Docxpresso internally uses an instance of Libre Office (recommended) or Open Office to carry out the required format conversions whenever the requested final document format is not Open Document Text (.odt) or Word (.doc).
Since version 3.5 onwards we offer our users direct access to the internal document format conversion engine so they can use it with whatever purpose they like.
Docxpresso is not certainly the only available solution for that specific task but we have considered that the queuing system embedded within Docxpresso (that avoid potential conflicts with concurrent calls under heavy loads) as well as its pure PHP wrapper could be of help to many of our users.
This conversion utility requires of a full installation of the Docxpresso package so beware that you need to carefully follow the installation instructions for the platform of your choice (LINUX/UNIX or WINDOWS).
Let us start by describing its public API in detail.
Signature
public Conversor ( $source, $target [, $options] )
Parameters
- $source (type: string). Path (relative or absolute) to the document we wish to convert
- $target (type: string). Path (relative or absolute) where the converted document should be stored
- $options (type: array). This optional array includes the available options for PDF rendering:
- 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.
Available document format combinations
Beware that not all possible document format combinations are possible or available. In the following we offer the available options:
Text documents
You may convert:
- Open Document Format (.odt),
- Word (.docx and .doc),
- Rich Text Format (.rtf),
- and Plain Text (.txt)
into:
- Portable Document Format (.pdf),
- Open Document Format (.odt),
- Word (.docx and .doc),
- Rich Text Format (.rtf),
- and Plain Text (.txt).
Spreadsheets
You may convert:
- Open Document Spreadsheets (.ods),
- Excel(.xlsx and .xls)
- and Comma Separated Values (.csv)
into:
- Portable Document Format (.pdf),
- Open Document Spreadsheets (.ods),
- Excel(.xlsx and .xls)
- and Comma Separated Values (.csv).
Presentations
You may convert:
- Open Document Prsentations (.odp) and
- PowerPoint(.pptx and .ppt)
into:
- Portable Document Format (.pdf),
- Open Document Prsentations (.odp) and
- PowerPoint(.pptx and .ppt)
Let us illustrate all of this with the help of a sample script:
<?php /** * This sample script generates a PDF out of a Word (.docx) file with some custom options */ require_once 'pathToDOCXRESSO/Conversor.inc'; new DocxpressoConversor('test_conversion.docx', 'test_conversion.pdf');
Let us illustrate the use of advanced options by creating a pdf with custom settings (password protected, zoom, etcetera):
<?php /** * This sample script generates a PDF out of a Word (.docx) file with some custom options */ require_once 'pathToDOCXRESSO/Conversor.inc'; //Let us include some advanced options $options = array(); $options['EncryptFile'] = true; $options['DocumentOpenPassword'] = 'html52pdf'; $options['Magnification'] = 4; $options['Zoom'] = 60; $options['InitialView'] = 2; new DocxpressoConversor('test_conversion.doc', 'test_conversion_pwd.pdf', $options);
If you download 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.