sgapiImagePDF(%%pdf, %%image, %%pad, %%width, %%resize, %%just, %%border)

Important Update to Custom Scripting

The CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!


  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.

This function adds an image to the given PDF.

Parameters

  • %%pdf - The title of the PDF you are creating.
  • %%image - The image URL.
  • %%pad - Image padding by page unit (defaults to 5). Enter '0' for no padding.
  • %%width - The width of the image on the page (defaults to 0).
  • %%resize - Can be 'full','width','none'.
  • %%just - The horizontal position of the image.
  • %%border = array () - See PHP PDF Creation documentation for border options.

For more info on PHP PDF Creation visit: https://github.com/rospdf/pdf-php/blob/master/readme.pdf

Example

The below script creates and builds a PDF object, outputs it and adds it as an attachment to a send email action. In the highlighted portion of the script we specify the URL of the image to be added to the PDF.

Check it out in an example survey

OR

Download a survey with these scripting functions to your account

%%pdf = "Example PDF";
%%text = "Text to include in PDF";
%%size = 14;
%%options = array('spacing' => 1.5);
%%table = array( array(1,2,3,4), array(5,6,7,8), array (9,10,11,12) );
%%columns = array('Column A','Column B','Column C','Column D');

sgapiNewPDF(%%pdf,'letter','portrait');
sgapiSetFontPDF(%%pdf,'courier');
sgapiSetColorPDF(%%pdf,0,0,0);
sgapiImagePDF(%%pdf,"https://surveygizmolibrary.s3.amazonaws.com/library/160589/surveysoftwareapi.png"); 
sgapiTextPDF(%%pdf,%%text,%%size,%%options);
sgapiTablePDF(%%pdf,%%table,%%columns,'Table Title');

%%formattedpdf = sgapiPDFOutput(%%pdf);

%%attachment['example.pdf'] = %%formattedpdf;

//Attach to existing send email action (ID 3)
sgapiSetQuestionProperty(3,"email_attachments",%%attachment);