PDF plugin - tips and tricks

You'll find various tips and tricks listed below on using RSForm!Pro - PDF plugin. Start by clicking on the one that interests you.

If this is the first time you're using the RSForm!Pro - PDF plugin, this article should be read first as it provides in-depth information regarding PDF capabilities.


Navigation




Font, paper size and orientation


  • Global settings which apply on all generated PDF files.
    • Navigate to backend > Components > RSForm!Pro > Configuration > PDF.
    • This tab allows setting a 'Font', 'Orientation' and a 'Paper Size' (more details on these within the plugin documentation).

  • Overriding global settings in order to control individual PDF files.
    • Navigate to backend > Components > RSForm!Pro > Manage Forms > your form > Properties.
    • For paper size and orientation, select the "PHP PDF Pre-Processing Scripts" tab and add (examples):
    •         $pdf->dompdf->set_paper('a5','landscape');
      
      or, if you want the portrait version:
              $pdf->dompdf->set_paper('a4','portrait');
      
    • Changing the font can be done through CSS.
    • Edit the PDF layout and use a similar as the following snippet (note: this requires that you have the font installed - more details on this topic here):
    •           <style type="text/css">
                body { font-family: "DejaVu Sans" !important; }
                </style>
      


Adding pictures


  • Static pictures, found on your server, are added using the {sitepath} placeholder:
          <img src="{sitepath}/path/to/images/my-image.jpg" alt="image" />
    
  • Pictures uploaded through the form, more precisely, through the File Upload element can be added using (whereas 'FileUploadName' is the exact name you gave to the File Upload, case sensitive):
          <img src="{FileUploadName:localpath}" alt="image" />
    


Protect PDF with passwords


One PDF file can have 2 passwords, an Owner password and an Admin password. The "Admin password" is used to remove any restriction (Allowed Options) you might have set on your PDF file, while the "User password" will be used in order to allow the user to view the PDF contents.

You can also try a dynamic approach on this and generate different passwords for your PDF files on form submission. For example:

  • Add a "Support Ticket" form element (this is a hidden field that generates a random sequence based on its configuration).
  • You can then use the field's placeholder within the "Owner password" or "Admin password". If you've named your field RandSequence, it's exact placeholder would be (case sensitive): {RandSequence:value}
  • You can also add a "Textbox" instead and allow users to choose their own password.
  • Or even add a Hidden Field and generate your own custom string via Scripts called on form process area (backend > Components > RSForm!Pro > Manage Forms > your form > Properties > PHP Scripts).


Page breaks to split page information


If the size of the PDF exceeds one page, the PDF will automatically display the data on multiple pages. You can however have more control over the information displayed on a certain page by using the following inline style syntax to split pages:

    <div style="page-break-after:always">
    First page data here
    </div>

    <div style="page-break-after:always">
    Second page data here
    </div>

    <div style="page-break-after:always">
    Third page data here
    </div>


Save PDF file to folder


You can save the PDF files to your server with the help of custom scripting. In order to do so, a similar as the following script is needed within 'Script called after form has been processed' area (backend > Components > RSForm!Pro > Manage Forms > your form > Properties > PHP Scripts):

$pdfUser = str_replace($replace, $with, '{user_pdf}');
$pdfAdmin = str_replace($replace, $with, '{admin_pdf}');

//destination path for the User PDF file - you can replace {global:submissionid} with any other existing field placeholder from your form:
$pdfUserfile = JPATH_SITE.'/tmp/pdf-user-{global:submissionid}.pdf';

//destination path for the Admin PDF file:
$pdfAdminfile = JPATH_SITE.'/tmp/pdf-admin-{global:submissionid}.pdf';

$pdfUserfile = str_replace($replace, $with, $pdfUserfile);
$pdfAdminfile = str_replace($replace, $with, $pdfAdminfile);

$http = JHttpFactory::getHttp();

if ($response = $http->get($pdfUser))
{
   file_put_contents($pdfUserfile, $response->body);
}

if ($response = $http->get($pdfAdmin))
{
   file_put_contents($pdfAdminfile, $response->body);
}
Note:
  • $SubmissionId is added as the file name in order to prevent file overwriting and to provide a correlation with the actual submission.
  • More information on RSForm!Pro PHP Scripts can be found here.


Dynamically remove uncompleted form fields


RSForm!Pro incorporates a specialized syntax {if} statement that removes its contents in case a field doesn't have a value. To use this syntax within your PDF layout you'll have to use one of the following scripts (there are two cases for creating the PDF layout, both explained below).


  1. If you have configured the PDF file for the User Email:
  2. Head to backend > Components > RSForm!Pro > Manage Forms > edit your form > Properties > PHP PDF Pre-Processing Scripts > 'User Email Pre-processing PHP Script' area and add the following code:

    require_once(JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/scripting.php');
    RSFormProScripting::compile($info->useremail_layout, $args['placeholders'], $args['values']);
    
  3. If you have configured the PDF file for the Admin Email:
  4. Head to backend > Components > RSForm!Pro > Manage Forms > edit your form > Properties > PHP PDF Pre-Processing Scripts > 'Admin Email Pre-processing PHP Script' area and add the following code:

    require_once(JPATH_ADMINISTRATOR.'/components/com_rsform/helpers/scripting.php');
    RSFormProScripting::compile($info->adminemail_layout, $args['placeholders'], $args['values']);
    
Example:

Now you can simply use a syntax similar to the following (whereas 'fieldname' is the exact name of your form field):

{if {fieldName:value}} {fieldName:caption}:{fieldName:value} {/if}

Extras:

21 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

PHP PDF Pre-Processing Scripts HOT

Using the {if} statement with RSForm!Pro PDF plugin HOT

Improving the PDF export for submissions HOT

Save PDF file to folder