Having the ability to generate PDF documents from within Dynamic Forms and Dynamic Registration has always been a very powerful feature. In most cases you will have all that you need to create a great looking document right out of the box. However there are times where you need a bit more refinement before you get it just right for your SPEC. In this post I will outline some useful tips on how to get your Dynamic PDF exactly where you want it. In order to use any or all of these in your own completion event, simply append the event name with the terms in quotes below. For example: If your PDF Completion Event Name = “MyPDF” and you needed your document to auto size; you would change the name to “AutoSize_MyPDF”. That’s all there is to it!
If your Completion event name contains the term "LandScape", the pdf orientation will be changed to landscape. Default is Portrait.
This sets the specific pdf creator function below:
pdfConverter.PdfDocumentOptions.PdfPageOrientation = ExpertPdf.HtmlToPdf.PDFPageOrientation.Landscape
If your Completion event name contains the term "Stretch", the pdf inner document element will be stretched to fit the default pdf page size (8.5" x 11" Letter). The default value is False.
This sets the specific pdf creator function below:
pdfConverter.PdfDocumentOptions.StretchToFit = True
If your Completion event name contains the term "FitWidth", the pdf inner document element will be resized to fit the default pdf page width (8.5" for Letter or Legal) regardless of the height. The default value is False.
This sets the specific pdf creator function below:
pdfConverter.PdfDocumentOptions.FitWidth = True
If your Completion event name contains the term "AutoSize", the pdf page size will auto adjust based on the fixed sized declared for the inner html of your template. For instance if you set an outer div within your PDF template measuring 612px wide by 796px high you would get 8.5" x 11" for a page size. 612px wide by 1008px high would equal 8.5" x 14" Legal paper size @72 DPI. You can easily find the pixel equivalent for any page size by multiplying inches by DPI. For example:
- 8.5" x 11" @300 DPI would be
- 300*8.5=2550px
- 300*11=3300px
whereas the same dimension page
- 8.5" x 11" @72 DPI would be
- 72*8.5=612px
- 72*11=796px.
The default value is False.
This sets the specific pdf creator function below:
pdfConverter.PdfDocumentOptions.AutoSizePdfPage = True
If your Completion event name contains the term "ScriptsEnabled", the pdf will now include any JavaScript contained within the inner html. The default value is False
This sets the specific pdf creator function below:
pdfConverter.ScriptsEnabled = True
Closing notes are sourced from http://www.html-to-pdf.net/ and touch on setting dedicated page breaks and keeping images from being split between two pages.
The HTML to PDF converter supports custom page breaks with standard CSS styles like page-break-before:always and page-break-after:always applied to any HTML object. The page-break-inside:avoid style can be applied to a element to prevent splitting the content inside the element between pages.
To specify to the converter to not break (keep together on the same page) a HTML region between PDF pages you can apply inline the page-break-inside:avoid CSS style to the HTML element you want to keep appear in the rendered PDF document on same page. Of course the element height must be less than the page height, otherwise the style will be ignored by the converter. Please note that unlike the page-break-before and page-break-after , the page-break-inside:avoid style must be specified inline as in the example below:
<table>
<tr style="page-break-inside : avoid">
<td>
<img width="100" height="100" src="img1.jpg">
td>
<td>My text 1td>
tr>
<tr style="page-break-inside : avoid">
<td>
<img width="100" height="100" src="img2.jpg">
td>
<td>My text 2td>
tr>
table>
In this example the table can contain a large number of rows, each row containing an image in the left and a text in the right and we don't want such a row to span on two pages. This can be easily achieved by specifying the page-break-inside:avoid style inline for the table row. You can also set the page-break-inside:avoid CSS style inline on the IMG tag to achieve the same result.
I hope this helps some of you get that last bit of fine tuning needed to knock your project out of the park!
The Data Springs Module Suite uses ExpertPDF to handle the PDF creation features. Some of the information above was sourced directly from http://www.html-to-pdf.net/