PDF output plugin Guide
Overview
In Servoy, manipulating and annotating existing PDFs is a common requirement for applications that involve generating reports, filling out forms, or adding security and branding elements to documents. Servoy provides powerful tools for interacting with PDFs programmatically, allowing for modifications like combining multiple PDF files, adding annotations (such as watermarks or page numbers), filling out forms, and securing PDFs with password protection.
Key Use Cases:
Manipulating Existing PDFs:
Annotating PDFs: Add text, images (like watermarks), and other annotations to enhance or modify existing PDF documents. This is useful for adding confidential marks like "TOP SECRET" or including a company logo on every page.
Filling and Flattening Forms: Programmatically fill out PDF forms (for example, invoices or contracts) and flatten the form, which prevents further edits after the data is filled in.
Combining Multiple PDFs: Merge several PDF files into one, which can be useful for generating comprehensive reports or combining document sections.
Annotations and Customization:
Text Annotations: Add labels, captions, or other text-based elements to a PDF. For example, marking documents with notes like "DRAFT" or "CONFIDENTIAL" for specific sections.
Watermarks: Insert image-based watermarks, such as logos or background images, to each page of a document. You can control the placement of these images and whether they appear in the foreground or background.
Page Numbers: Automatically add page numbers to an existing PDF, useful for multi-page documents like reports or contracts where pagination is necessary for navigation.
Security:
Encrypting PDFs: PDFs can be secured by applying password protection, restricting actions like copying, printing, or modifying the contents. This feature is essential for sensitive or confidential documents where specific user permissions are required.
Advanced PDF Generation and Reporting: For more sophisticated PDF generation, reporting, and business intelligence (BI) needs, Servoy integrates with tools like:
Jasper Reports: A powerful reporting engine that can generate complex PDF reports from data sources, offering features like advanced formatting, data grouping, and charts.
Smart Doc Editor: A flexible tool for creating and editing structured documents, including PDFs, often used in applications where structured reporting is a key feature.
In Servoy, manipulating and annotating existing PDFs requires the File Plugin methods. These methods provide the core functionality for working with PDF files, such as reading, writing, and saving modifications to the filesystem. To learn more, refer to the File Plugin documentation.
Combining multiple files into a single PDF
You can combine multiple files into a single PDF by reading the data from multiple PDFs and using the plugins.pdf_output.combinePDFDocuments method to merge them.
Code Example:
Programmatic fill in form and flatten
PDF forms often need to be filled programmatically with data and then flattened to prevent further editing. This is done using the plugins.pdf_output.convertPDFFormToPDFDocument method to lock the fields after filling.
Example:
Showing Thumbnail Previews in a Form
You can generate and display thumbnail previews of PDF pages within a Servoy form using the generateThumbnails method. This method creates image representations of each page in the PDF, which can be displayed as thumbnails.
Example:
Adding Annotations
Annotations, such as text, watermarks, or page numbers, can be added to PDFs using the following methods.
Text
To add a text annotation (e.g., a "TOP SECRET" label), use the plugins.pdf_output.overlayText method. You can specify the text and its position on the page.
Example:
Watermark
You can add an image watermark, such as a company logo, to every page of a PDF using the plugins.pdf_output.watermark method. The watermark can be placed in the background or foreground, and you can control its position on the page.
Example:
Page Numbers
To automatically add page numbers to a PDF, use the plugins.pdf_output.numberPages method. This is useful for documents where numbering is necessary for organization and readability.
Example:
Last updated