Login to follow
AdvancedHtmlToPDF

AdvancedHtmlToPDF (ODC)

Stable version 0.2.0 (Compatible with ODC)
Uploaded on 30 May by Xebia USA Inc.
AdvancedHtmlToPDF

AdvancedHtmlToPDF (ODC)

Documentation
0.2.0

HTML to PDF Using IText Extension for OutSystems

Overview

The HTML to PDF Extension for OutSystems provides a simple and effective way to convert HTML content into a PDF document using the iText library. This extension is useful for generating PDF reports, invoices, or any other documents that need to be created dynamically from HTML content within OutSystems applications.

This library is optimized for high-performance server-side use, supporting asynchronous operations. It can generate PDF documents with over 250 pages in just a few seconds. In our demo application, we implemented dynamic table rendering to streamline content generation and significantly enhance scalability and performance

Key Features

- Converts HTML with CSS content to PDF using the iText library.
- Allows users to generate PDF files from dynamic HTML data.
- Supports custom styling, embedded images, and standard HTML formatting.
- Easily integrated into OutSystems applications as a custom action.

Extension Components 1. ConvertHtmlToPdf Action

This action is the core functionality of the extension, which converts HTML content into a PDF file.

Inputs:

- HtmlContent (Text): The HTML content that needs to be converted into a PDF. This input should contain valid HTML code (such as Example:Invoice #12345

Customer: John Doe

- IsRotate (Boolean): If the condition is true, the page will rotate to landscape; otherwise, it will remain in portrait orientation.
- OutputPdfPath (Text): The file path where the generated PDF will be saved. This is a full file path, including the file name and extension (e.g., C:\PDFs\Invoice12345.pdf).
Example:
C:\GeneratedReports\Invoice12345.pdf


Outputs:

- None: The action does not return any value, but the output PDF is saved at the specified file path.


Usage Instructions 1. Import the Extension

Import the HTML to PDF Extension from the OutSystems Forge into your environment.

2. Calling the ConvertHtmlToPdf Action

To use the ConvertHtmlToPdf action within your application, follow these steps:
1. Add the Action: In your OutSystems application, go to the Logic tab and add the ConvertHtmlToPdf action from the extension to the logic flow where you need the PDF generation.
2. Prepare HTML Content: Prepare the HTML content you want to convert to PDF. This could be dynamically generated in your application (e.g., from a report, form, etc.).
3. Specify the Output Path: Specify the path where the generated PDF will be saved. Ensure that the OutSystems server has permission to write to this location.
4. Call the Action: Use the following code in the logic flow to call the ConvertHtmlToPdf action.

Example:
HtmlToPdfConverter converter = new HtmlToPdfConverter();
string htmlContent = "Invoice #12345

Customer: John Doe"; string pdfPath = "C:\GeneratedReports\Invoice12345.pdf"; converter.ConvertHtmlToPdf(htmlContent, pdfPath);


5. Save or Display PDF: After the action is executed, the PDF will be saved at the provided file path. You can either provide a download link to the user or email the PDF as needed.



Screenshots




PDF Output:


If the IsRotate input is set to False, it will be generated in portrait mode.
Picture

If the IsRotate input is set to True, the PDF will be generated in landscape orientation.

Picture

Troubleshooting

- Invalid HTML: Ensure that the HTML content is well-formed. Malformed HTML may cause the conversion to fail.
- File Path Issues: Ensure that the file path provided for saving the PDF is valid and accessible by the OutSystems server. Verify that the server has write permissions to the directory.
- Permissions: The OutSystems server needs permission to write files to the specified directory. If the path is inaccessible, the conversion will fail.