Advertisement
nrzmalik

How to Print PDF Completion Certificate in Storyline

Mar 10th, 2024 (edited)
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.41 KB | Source Code | 0 0
  1. var confettiScript = document.createElement('script');
  2. confettiScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js';
  3. confettiScript.async = true;
  4. confettiScript.onload = function() {
  5.     generateCertificate();
  6. };
  7. document.head.appendChild(confettiScript);
  8.  
  9. function generateCertificate() {
  10.     var date = new Date();
  11.     var dd = String(date.getDate()).padStart(2, '0');
  12.     var mm = String(date.getMonth() + 1).padStart(2, '0');
  13.     var yyyy = date.getFullYear();
  14.     date = mm + '/' + dd + '/' + yyyy;
  15.  
  16.     var name = prompt("Please enter your name:", "");
  17.     if (!name) {
  18.          name = prompt("Please enter your name:", "");
  19.     }
  20.     var doc = new jsPDF({
  21.         orientation: 'landscape'
  22.     });
  23.  
  24.     var pageWidth = doc.internal.pageSize.getWidth();
  25.     var pageHeight = doc.internal.pageSize.getHeight();
  26.  
  27.     doc.setLineWidth(2);
  28.     doc.setDrawColor(182, 0, 0);
  29.     doc.rect(10, 10, pageWidth - 20, pageHeight - 20);
  30.  
  31.     var gradient = doc.setFillColor(182, 0, 0);
  32.     doc.rect(10, 10, pageWidth - 20, 40, 'F');
  33.  
  34.     doc.setDrawColor(255, 255, 255);
  35.     doc.setLineWidth(1);
  36.     doc.line(10, 40, pageWidth - 10, 40);
  37.     doc.line(30, 10, 30, 40);
  38.     doc.line(pageWidth - 30, 10, pageWidth - 30, 40);
  39.  
  40.     doc.setTextColor(255, 255, 255);
  41.     doc.setFontSize(30);
  42.     doc.setFont('Helvetica', 'bold');
  43.     var title0 = "Certificate of Completion";
  44.  
  45.     var pageWidth = doc.internal.pageSize.getWidth();
  46.     var nameWidth = doc.getStringUnitWidth(title0) * doc.internal.getFontSize() / doc.internal.scaleFactor;
  47.     var xPos = (pageWidth - nameWidth) / 2;
  48.     doc.text(title0, xPos, 30, null, null, 'left');
  49.  
  50.     doc.setTextColor(0, 0, 0);
  51.  
  52.     doc.setFontSize(28);
  53.     doc.setFont('Helvetica','normal');
  54.     var title2 = "THIS IS TO CERTIFY THAT";
  55.     var pageWidth = doc.internal.pageSize.getWidth();
  56.     var nameWidth = doc.getStringUnitWidth(title2) * doc.internal.getFontSize() / doc.internal.scaleFactor;
  57.     var xPos = (pageWidth - nameWidth) / 2;
  58.     doc.text(title2, xPos, 70, null, null, 'left');
  59.  
  60.     doc.setFontSize(50);
  61.     doc.setFont('Helvetica','bold');
  62.     var pageWidth = doc.internal.pageSize.getWidth();
  63.     var nameWidth = doc.getStringUnitWidth(name) * doc.internal.getFontSize() / doc.internal.scaleFactor;
  64.     var xPos = (pageWidth - nameWidth) / 2;
  65.     doc.text(name, xPos, 100, null, null, 'left');
  66.  
  67.     doc.setFont('Helvetica','normal');
  68.     doc.setFontSize(28);
  69.     var title3 = "You have successfully completed:";
  70.     var pageWidth = doc.internal.pageSize.getWidth();
  71.     var nameWidth = doc.getStringUnitWidth(title3) * doc.internal.getFontSize() / doc.internal.scaleFactor;
  72.     var xPos = (pageWidth - nameWidth) / 2;
  73.     doc.text(title3, xPos, 140, null, null, 'left');
  74.  
  75.     var pageTitle = document.title;
  76.     doc.setFontSize(24);
  77.     doc.setFont('Helvetica','bold');
  78.     var pageWidth = doc.internal.pageSize.getWidth();
  79.     var nameWidth = doc.getStringUnitWidth(pageTitle) * doc.internal.getFontSize() / doc.internal.scaleFactor;
  80.     var xPos = (pageWidth - nameWidth) / 2;
  81.     doc.text(pageTitle, xPos, 160, null, null, 'left');
  82.  
  83.     doc.setDrawColor(0, 0, 0);
  84.     doc.setLineWidth(0.5);
  85.     doc.line(18, 190, 43, 190);
  86.  
  87.     doc.setFontSize(14);
  88.     doc.setTextColor(0, 0, 0);
  89.     doc.text(date, 18, 188, null, null, 'left');
  90.     doc.text("Date", 25, 195, null, null, 'left');
  91.  
  92.     doc.save(name + " Certificate.pdf");
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement