In the majority of examples we have restricted ourselves to the simplest pdf possible rendering; i.e. leaving all the options as default. Here we are going to go a little deeper into the functionality of the render method.
Let us start by describing its public API in detail.
Signature
public render ( $path [, $options] )
Parameters
- $path (type: string). Path of the resulting document
- $options (type: array). This array has the following available keys and values:
- PageRange (type: string), if left empty all pages are printed. If a range is given, e.g. 2-4, only those pages are exported to PDF.
- UseLosslessCompression (type: bool, default: false), if true all images are exported as PNG, otherwise the JPG format is used.
- UseLosslessCompression (type: bool, default: false), if true all images are exported as PNG, otherwise the JPG format is used.
- Quality (type: int, default: 90)), this option sets the quality of JPG export (it has to be a value between 1 and 100).
- ReduceImageResolution (type: bool, default: false), if true will use the resolution specified by the MaxImageResolution property.
- MaxImageResolution (type: int, default: 300) sets the dpi (dots per inch) resolution of the exported images.
- SelectPdfVersion (type: int, default: 0):
- PDF 1.4: set this option to 0 (default).
- PDF/A-1 (ISO 19005-1:2005): set this option to 1.
- UseTaggedPDF (type: bool, default: false), if set to true it creates a tagged (accesible) PDF.
- ExportFormFields (type: bool, default: true), if true all form elements are exported as such.
- FormsType (type: int, default: 2) specifies the submit format of the PDF forms:
- FDF: set this option to 0.
- PDF: set this option to 1.
- HTML: set this option to 2 (default value).
- XML: set this option to 3.
- ExportBookmarks (type: bool, default: true)), if true exports to PDF the document bookmarks.
- EmbedStandardFonts (type: bool, default: false), if true the 14 standard PDF fonts are included into the PDF file.
- Watermark (type: string), if not empty watermarks the PDF with the given text.
- InitialView (type: int, default: 0) specifies how the PDF should be displayed when opened:
- 0: default view mode, neither outlines or thumbnails.
- 1: outline pane opened.
- 2: thumbnail pane opened.
- Magnification (type: int, default: 0) specifies the magnification of the PDF when opened:
- 0: default magnification.
- 1: fit entire page within the viewer window.
- 2: fit entire page width within the viewer window.
- 3: fit entire page width (cutting the margins) within the viewer window.
- 4: opens with the zoom specified in the Zoom option.
- Zoom (type: int, default: 100) specifies the zoom level (only used if Magnification is set to 4). The available range is 50-1600.
- PageLayout (type: int, default: 0) specifies the PDF layout when opened:
- 0: default viewer configuration.
- 1: one page at a time.
- 2: display pages in one column.
- 3: display pages in two columns.
- FirstPageOnLeft (type: bool, default: false), if true the first page should be on the left (only used if PageLayout is set to 3).
- CenterWindow (type: bool, default: false), if true the PDF viewer window is centred in the screen.
- OpenInFullScreenMode (type: bool, default: false), if true the PDF is open in full screen mode.
- DisplayPDFDocumentTitle (type: bool, default: true), if true the title of the PDF (if previously set) is shown in the viewer window title bar.
- HideViewerMenubar (type: bool, default: false), if true hides the viewer menubar.
- HideViewerToolbar (type: bool, default: false,) if true hides the viewer toolbar.
- HideViewerWindowControls (type: bool, default: false), if true hides the viewer controls.
Let us illustrate all of this with the help of a sample script:
<?php /** * This sample script generates a PDF with some custom options and password protected */ require_once 'pathToDOCXRESSO/CreateDocument.inc'; $doc = new DocxpressoCreateDocument(); $format = '.pdf';//.pdf, .doc, .docx, .odt, .rtf $doc->paragraph(array('text' => 'Let us add a simple TOC to the document with just the default options:')); //insert the TOC $doc->toc(); //insert some headings and content so we can populate the TOC for ($j=1; $j < 5; $j++){ $doc->heading(array('level' => 1, 'text' => 'The Title number:' . $j, 'style' => 'page-break-before: always')); $doc->heading(array('level' => 2, 'text' => 'A subtitle of the title number: ' . $j)); $doc->paragraph(array('text' => 'Some random text.')); } //Let us include some advanced options $options = array(); $options['EncryptFile'] = true; $options['DocumentOpenPassword'] = 'html52pdf'; $options['Magnification'] = 4; $options['Zoom'] = 60; $options['InitialView'] = 2; //include in the render method the path where you want your document to be saved $doc->render('pdf_rendering_options' . $format, $options);
If you save the resulting pdf and open it, for example, with Adobe Reader you will be able to check that you are prompted to introduce a password (html52pdf in this case) and when opened the viewer will show the document with a zoom of 60% and with the thumbnail pane open.