Plugin - PDF (Attach an automatically generated PDF to an email)

Either based on the PHP dompdf library or the mPDF library, the RSForm!Pro PDF plugin is designed to generate PDF files that include submission information. The PDF files can then be attached to the built-in User and Admin emails or accessed via special placeholders.

 

Minimum requirements (same as dompdf requirements)

  • PHP 7.1+
  • MBString extension
  • DOM extension

Please check with your hosting provider first if you meet the minimum requirements.


The plugin can be installed via the usual Joomla! installer. You can read more on this process here.

RSForm!Pro PDF plugin video tutorial:

 

Once the plugin has been installed and published, the following configuration parameters are available within the Components > RSForm!Pro > Configuration > PDF area:


  • PDF Library: by default this is set to dompdf and there's usually no need to change it. If however you need RTL orientation in your PDF file, or proper display for certain languages like Arabic, then switch it to mPDF instead (this will be initially greyed out as you'll need to firstly include the mPDF library).
  • Font (only provided for the dompdf library): the font type that will be used to generate the PDF files
  • Orientation: sheet orientation - portrait / landscape
  • Paper Size: the paper format, e.g. A4
  • Allow Remote Resources (only provided for the dompdf library): if enabled, the PDF library will allow specifying remote resources (such as images, stylesheets) in your HTML code. For example, specifying src='http://www.somesite.com/someimage.jpg' in your img tag means the image will be downloaded on your server (please use this with caution). Note that you don't necessarily need to have this enabled to have images in your PDF body, as a specialized placeholder is provided instead when specifying your image path.
 
Note (only applied to dompdf):

Some special chars are not supported by all PDF font types. For example if your submissions or PDF text will be in Chinese, you will need to use the special, Firefly font, which is available for download within the My downloads > RSForm!Pro > View all plugins and modules > RSForm!Pro files > 3rd Party area.

To install additional fonts, simply upload them (using a FTP client) within the administrator/components/com_rsform/helpers/pdf/dompdf20/vendor/dompdf/dompdf/lib/fonts folder. Once the files have been added to the proper location, you will be able to select the desired font within the RSForm!Pro > Configuration > PDF area. Please note that this is only available for the fonts downloaded from our website, to install fonts obtained from any other source, please consult the dompdf documentation.

Important!

PDF Libraries, such as mPDF, can be downloaded from "My downloads" section > RSForm!Pro - Modules & Plugins > 3rd Party > and installed on your website
using the Joomla! installer.

If your hosting does not allow uploading large files (for example, the mPDF archive has aproximately 45MB), you can include the PDF libraries manually as explained below.

Including the mPDF library

Download the library

mPDF is an alternative to the default dompdf library that can be used to generate the PDF document. One of the key features that determined the inclusion of this library is the fact that it supports the RTL orientation in the generated document.


The mPDF library has about 45MB, thus it is not included by default in the plugin's installation package; this is provided as a separate download. Before starting off, you should check its minimum requirements and limitations.


Steps to take:

  • download the mPDF archive from "My downloads" section > RSForm!Pro - Modules & Plugins > 3rd Party > "Library - mPDF" Download.

  • unzip the archive.

  • using your FTP account, place its contents under the following path (basically the following "pdf" folder should have a "mpdf" folder containing the mPDF library files):

  • administrator/components/com_rsform/helpers/pdf/

  • You should end up with a folder named mpdf inside administrator/components/com_rsform/helpers/pdf/
  • the mPDF library can be then selected from the PDF Library option.

PDF layout and content configuration

Accessing the User / Admin email configuration areas will reveal the PDF configuration area. Simple configuration options are available:

  • Attach to email: if enabled, the generated PDF file will be attached to the User / Admin email.
  • File name: the name of the generated file.
  • PDF Layout: allows you to specify the actual content and layout of the generated PDF file. You can use use standard HTML along with the usual RSform!Pro placeholders (listed by clicking on the Toggle Quick Add button)
  • User Password (optional): Set a password that you can pass on to your users. The options selected in the Allowed Options field (explained below) will be applied for users who view the file using this password.
  • Owner Password (optional): Set a password that you can keep for yourself or other administrators. When logging in with this password, you will have complete freedom in editing the PDF file.
  • Allowed Options: Print the document / Modify the document / Extract contents (copy) / Comment in the document - Use CTRL + Click to select the permissions that you wish to associate the generated PDF file with. These will be applied for users who view the file using the User Password and even if no passwords are set for the file.
Note:

Limited CSS control is also provided. You can read more on the dompdf CSS compatibility here.

In order to display images in the PDF you will need to use the exact site path. To simplify this process we have added the {sitepath} placeholder.

Instead of:

<img src="http://www.mydomain.com/path/to/images/my-image.jpg" alt="My image" />

use:

<img src="{sitepath}/path/to/images/my-image.jpg" alt="My image" />

The {your_field_name:localpath} placeholder will return the local path of the image found on the server (eg. /home/public_html/path/to/uploaded/image.jpg).

Example:

<head>
<style type="text/css">
h1 {
 margin:3px auto;
 font-size:18px;
 color:blue;
}
p {
 background:#fefeda;
 text-indent:20px;
 text-align:left;
}
</style>
</head>
<body>
 <h1>Sample content here</h1>
 <p>Dear, {Name:value}, thank you for taking time to submit the form.</p>
 <img src="{sitepath}/images/sample.jpg" width="130" height="80" alt="Sample"/>
</body>

The generated PDF files don't necessarily need to be attached to generated emails. These can also be accessed via the {user_pdf} and {admin_pdf} placeholders. You can use them inside the RSform!Pro generated emails, Thank you message, Submissions View menu item (details view) and the Submissions directory area (details view and emails). The above placeholders will return the exact path to the PDF document, you could use them in a general link tag in order to create a link to the PDF file, for example:

This is a link to the <a href="{user_pdf}">User PDF</a> document.

RSForm!Pro takes things further and allows dynamic control over the generated PDFs. Basically, you can use PHP code spinets to control the content of generated PDF. This can be done via the specialized PHP PDF Pre-Processing Scripts area (Components > RSform!Pro > Manage forms > edit a form > Properties, Scripts section), which contains two sections: one for the User email PDF and one for the Admin one.

The following PHP variables can be used for manipulation:

  • $args: array that contains the submitted information.
  • $info: a variable that stores the HTML layout (which will be transformed into a PDF).
  • $pdf: dompdf or mPDF functions can be accessed through the $pdf variable, for example: $pdf->functionName();

Available global placeholders:

  • {global:username} - displays the username
  • {global:userid} - displays the user ID
  • {global:useremail} - displays the email of the user
  • {global:fullname} - will display the Full Name registered for the current user
  • {global:userip} - displays the ip of the user that submitted the data
  • {global:date_added} - displays the date when the form was submitted
  • {global:sitename} - returns the name of your site
  • {global:siteurl} - returns the URL of your site
  • {global:confirmation} - displays the URL used for the submission confirmation
  • {global:confirmed} - displays the status of the submission
  • {global:submission} / {global:submission_id} - returns the ID of the submission

Tip: Adding a page-break

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

<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>

Accessing the PDF library directly through the PHP PDF Pre-Processing Scripts

$pdf->instance->pdf

This contains the actual instance of either Dompdf\Dompdf or Mpdf\Mpdf based on what your config is actually using.

Overriding the instance can be done by running:

$options = new \Dompdf\Options();
$options->set('defaultFont', 'serif');
$options->set('defaultPaperSize', 'a4');
$options->set('defaultPaperOrientation', 'portrait');
$options->set('isRemoteEnabled', true);

$pdf->instance->pdf = new \Dompdf\Dompdf($options);
$pdf->instance->pdf = new \Mpdf\Mpdf([
  'default_font' => 'frutiger',
  'orientation' => 'P',
  'format' => 'a4'
]);

Accessing a function from the PDF library directly

$pdf->instance->pdf->functionName();
$pdf->functionName();

Set mPDF to use a template that you can write your own content over:

$pdf->SetDocTemplate(JPATH_SITE . '/path/to/file.pdf', true);

More information on what these libraries offer can be found on their official pages: dompdf mPDF

04 Mar 2024
Version 3.0.6
  • Added - Joomla! 5 native compatibility - no longer needs the 'Behaviour - Backward Compatibility' plugin.
06 Nov 2023
Version 3.0.5
  • Added - 'Download User PDF' and 'Download Admin PDF' buttons in the backend when editing the submission.
  • Updated - dompdf 0.8 and 1.0 are no longer supported and have been removed.
17 Aug 2023
Version 3.0.4
  • Fixed - When resending multiple submissions the PDF filename would show up incorrectly.
07 Jun 2023
Version 3.0.3
  • Updated - Attached PDF files are now deleted more reliably using the new onRsformAfterUserEmail and onRsformAfterAdminEmail triggers.
  • Updated - dompdf v2.0.x is now the default library
  • Updated - Minimum requirements bumped to use PHP 7.1, Joomla! 3.10.0 and RSForm! Pro 3.1.10
10 Sep 2022
Version 3.0.2
  • Added - Support for dompdf v2.0.x
08 Oct 2021
Version 3.0.1
  • Updated - Code improvements.
  • Updated - Some column sizes changed to mediumtext to store more information.
  • Updated - Some instructions are now shown when using specific PHP versions.
  • Fixed - PDF was being generated even if 'Attach to User Email' was set to 'No'.
  • Fixed - 'PDF Layout' was not showing the CodeMirror editor when 'Syntax Highlighting' was set to 'Yes'.
09 Jun 2021
Version 3.0.0
  • Updated - Joomla! 4.0 and RSForm! Pro 3.0 compatibility.
06 Jan 2021
Version 2.1.3
  • Updated - Support for the dompdf v1.0.1 library.
20 Jul 2020
Version 2.1.2
  • Updated - dompdf library updated to v0.8.3
15 May 2020
Version 2.1.1
  • Updated - PDF functions can be accessed through the $pdf variable in the PHP PDF Scripts areas.
07 May 2020
Version 2.1.0
  • Added - mPDF library support. Choose between dompdf and mPDF to generate your files.
  • Updated - Minimum requirements bumped to use RSForm! Pro 2.2.0
  • Updated - Code improvements.
18 Oct 2019
Version 2.0.4
  • Fixed - A Fatal Error was encountered when using both RSEvents! Pro and RSForm! Pro to generate PDF files.
03 Jun 2019
Version 2.0.3
  • Fixed - Prevent browsers from auto-filling the password field.
02 Aug 2018
Version 2.0.2
  • Fixed - Syntax Highlighting was not working.
21 Jun 2018
Version 2.0.1
  • Updated - Bumped minimum requirements to use RSForm! Pro 2.0.13 and Joomla! 3.7.0
29 Jan 2018
Version 2.0.0
  • Updated - dompdf updated to v0.8.2
17 Oct 2017
Version 1.51.5
  • Fixed - JFolder class was throwing an error in some cases.
13 Oct 2017
Version 1.51.4
  • Fixed - Several workarounds added for servers with ownership / permission issues.
06 Feb 2017
Version 1.51.3
  • Updated - {if} scripting can now be used in the PDF layouts.
19 Feb 2016
Version 1.51.2
  • Added - Configuration option to grab resources (eg. images) from remote locations.
03 Feb 2016
Version 1.51.1
  • Fixed - Firefly font was not working in PDF files.
09 Oct 2015
Version 1.51.0
  • Added - Joomla! automatic updates support.
  • Updated - Bumped minimum requirements to use RSForm! Pro 1.51.0 and Joomla! 2.5.28
13 Jul 2015
Version 1.50.5
  • Fixed - 'Firefly' font didn't work.
21 Apr 2015
Version 1.50.4
  • Fixed - Filename set was not being taken into account when downloading the PDF.
06 Apr 2015
Version 1.50.3
  • Fixed - Added a legacy function so that Export to PDF from Manage Directories still works with this plugin.
01 Apr 2015
Version 1.50.2
  • Updated - Tweaked the PDF generation process so that you can modify the $pdf variable in the 'PHP PDF Pre-Processing Scripts' area.
31 Mar 2015
Version 1.50.1
  • Added - Ability to encrypt the PDF through User Password & Owner Password.
  • Added - Can prevent printing, modifying, copying or commenting in the resulting PDF.
  • Updated - dompdf 0.6.1
31 Mar 2015
Version 1.50.0
  • Updated - Deleting a form now correctly removes form's PDF settings from the database.
  • Updated - PDF settings can be backed up and restored.
22 Nov 2013
Initial Release

89 persons found this article helpful.


Was this article helpful?

Yes No
Sorry about that

You Should Also Read

Plugin - SMS Notification (Send a SMS to a mobile phone number) HOT

Plugin - RSEvents!Pro (Create custom event registration forms) HOT

Plugin - External Mailer (Use different email settings and add DKIM support) HOT

Ticket PDF plugin HOT

Plugin - Zoom (Create user registration forms) HOT