Custom script for a PDF with multiple pages

0

Can anyone offer an example of how to use %%sgapiNewPagePDF(%%pdf); to create more than one page in a PDF?

This is what I have but I don’t know how to create 2 pages to hold the content.

%%firstName = sgapiGetValue(3);
%%lastName = sgapiGetValue(4);
%%theDate = sgapiGetValue(278);
%%jobTitle = sgapiGetValue(98);
%%GI_1 = sgapiGetValue(15);
%%GI_2 = sgapiGetValue(49);
%%GI_3 = sgapiGetValue(54);
%%GI_4 = sgapiGetValue(56);
%%GI_5 = sgapiGetValue(135);
%%GI_Tally = sgapiGetValue(282);
%%GI_Evi = sgapiGetValue(57);

%%pdftemplate = ‘<head><meta http-equiv=”Content-Type” content=”text/html;charset=utf-8″ /></head>
<body style=”margin:20; padding:20;”>
<table border=”0″ style=”width:100%;”>
<tbody>
<tr>
<td colspan=”2″>
<p><strong>YOUR INITIAL RATING FOR THE MARKETING COMPETENCY ASSESSMENT</strong></span></p>
<p>NAME: <strong>’.%%firstName.'</strong><br />
JOB TITLE: <strong>’.%%lastName.'</strong><br />
DATE COMPLETED: <strong>’.%%theDate.'</strong><br />
LINE MANAGER: <strong>’.%%jobTitle.'</strong><br />
</p>
</td>
</tr>
<tr>
<td colspan=”2″> </td>
</tr><tr>
<td style=”width:80%;vertical-align:top; background-color:#CCD8E7;”><span style=”color:#003C88;font-size:18px;”><strong>GENERATING INSIGHTS</strong></span></td>
<td style=”text-align:center;width:20%;vertical-align:top; background-color:#CCD8E7;”><span style=”color:#003C88;font-size:18px;”><strong>MY INITIAL RATING</strong></span></td>
</tr>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</td>
<td style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_1.'</td>
</tr>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</td>
<td style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_2.'</td>
</tr>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</td>
<td style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_3.'</td>
</tr>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</td>
<td style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_4.'</td>
</tr>
<tr>
<td>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
</td>
<td style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_5.'</td>
</tr>
<tr>
<td><span style=”font-size:16px;”><strong style=”line-height:22.4px;”>INDICATIVE TOTAL RATING FOR THIS COMPETENCY AREA</strong></span></td>
<td style=”text-align:center;background-color:rgb(247,247,247);”><strong>’.%%GI_Tally.'</strong></td>
</tr>
<tr>
// NEED TO START A NEW PAGE HERE

<td colspan=”2″><strong>MY EVIDENCE</strong></td>
</tr>
<tr>
<td colspan=”2″><span style=”text-align:center;background-color:rgb(247,247,247);”>’.%%GI_Evi.'</span></td>
</tr>
</tbody>
</table>
</body>’;

%%pdf = sgapiHTMLTOPDF(%%pdftemplate,true,false);

%%attachment[’Assessment Summary.pdf’] = %%pdf;

//Attach to existing send email action (ID 108)

sgapiSetQuestionProperty(108,”email_attachments”,%%attachment);

 

Kate Williams82611 asked
    0

    Hey Kate!

    The Custom Scripting PDF functions are a bit tricky to work with – they do leave a bit to the imagination! One very important detail is that the `sgapiHTMLTOPDF` function operates completely separately from the other PDF functions listed in the documentation.

    Two ways to create a PDF

    The `sgapiNewPDF` and other functions listed below are built upon the Cpdf and Cezpdf open source PHP classes:

    • sgapiNewPDF
    • sgapiTextPDF
    • sgapiSetFontPDF
    • sgapiSetColorPDF
    • sgapiImagePDF
    • sgapiTablePDF
    • sgapiNewPagePDF
    • sgapiPDFOutput

    When using this method, you’ll first create a “blank” PDF object with the `sgapiNewPDF` function, and then add to/edit that PDF using the other functions. All of these require a `%%pdf` argument, which will be the same title you passed to the `sgapiNewPDF` function.

    In regards to the `sgapiNewPagePDF` function, this “inserts” a page break whenever it is called. In practice, you might create a PDF, add some text, then insert a page break, then add some more text. Once complete, you’ll use the `sgapiPDFOutput` function to take your work-in-progress and save it’s output as a PDF file, to be attached to an email message for example.

    Inserting a page break when using sgapiHTMLTOPDF

    `sgapiHTMLTOPDF` is a self-contained, full-service PDF generation function. Instead of building up your PDF incrementally, you pass in some HTML, and get a PDF file returned. This function is built upon the wkhtmltopdf open source command line tool.

    Inserting page breaks in a PDF created with this function is done with CSS. The `page-break-before` property in specific is a very handy one, although `page-break-after` and `page-break-inside` are also available. Check out this page from the Mozilla Developer Network for more details on how to use this CSS property:

    https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-before

    I hope this information helps!

    Nathan - Survey Astronaut answered
      ×

      Login

      Question stats

      • Active
      • Views2318 times
      • Answers1 answer
      • Followers0 followers