PDF Certificate creation through javascript in Captivate for Captivate Prime LMS

430 views Asked by At

I am creating a custom Certificate through a Captivate course to be ran in Captivate Prime. We have code written around obtaining the APIs from Captivate Prime and they seem to be populating in Chrome, Firefox, and Edge, but not in IE 7-10. As a separate problem, the production of the Certificate as a PDF is done through code and that code is activated by a button. When a learner goes back into the course in Captivate Prime, the button will not work again.

Setup: Learner takes a 10 question test. If they pass, the Certificate 'course' is opened and when it shows, it pulls the info from APIs and fills in general information; Name, Address, course name, competed, etc. There is a button on the page that the learner can click that will create the PDF and download it with all the information from the APIs that have already been pulled. In Internet Explorer, the page in Captivate Prime will not fill in the API information, but it does work in Chrome, Firefox, and Edge. If you go back into the course and to that content (certificate creation), the information loads again on the visual, but the button will not work to produce the PDF.

I am attaching code, but if I have not described this in enough detail or you have any questions, please feel free to ask.

This is the PDF Creation.

// This is the function that will generate a PDF from an image and text fields.
function createCert() {
  var imgBackground = new Image();
  imgBackground.src = "DHA-Test-Cert.png";
  imgBackground.onload = function () {
    var doc = new jsPDF({
      orientation: "landscape",
      unit: "in",
      format: [11, 8.5],
    });
    doc.addImage(imgBackground, 0, 0, 11, 8.5);
    var userName = window.cpAPIInterface.getVariableValue("v_UserName");
    var fileName = "DHACertPDF.pdf";
    var courseTitle = window.cpAPIInterface.getVariableValue("v_CourseTitle");
    var dateCompleted =
      window.cpAPIInterface.getVariableValue("v_CompletionDate");
    var userAddress1 = window.cpAPIInterface.getVariableValue("v_Address1");
    var userAddress2 = window.cpAPIInterface.getVariableValue("v_Address2");
    var userCityStateZip =
      window.cpAPIInterface.getVariableValue("v_CityStateZip");

    doc.setFontSize(12);
    doc.setTextColor(0, 0, 0);
    doc.setFont("helvetica");
    doc.setFontType("bold");
    doc.text(4.6, 6.6, userName, null, null, "left");
    doc.text(4.6, 7.2, courseTitle, null, null, "left");
    doc.setFontType("normal");
    doc.text(0.41, 2.8, dateCompleted, null, null, "left");
    doc.text(0.41, 3.0, courseTitle, null, null, "left");
    doc.text(0.41, 5.6, userName, null, null, "left");
    doc.text(0.41, 5.8, userAddress1, null, null, "left");
    doc.text(0.41, 6.0, userAddress2, null, null, "left");
    doc.text(0.41, 6.2, userCityStateZip, null, null, "left");
    doc.save(fileName);
  };
}
0

There are 0 answers