APEX plugin to generate a PDF from the page content

Ashritha Malli
Oracle Developers
Published in
3 min readMay 20, 2022

Overview

Many APEX applications require the user to be able to download page content in PDF format.

Oracle Application Express (APEX) can create a PDF file for your forms and reports with just a few clicks, but there is no easy way to generate a PDF from the page content. This plugin generates a PDF from HTML content and gives you the option to send it as an email attachment simply by calling an APEX process.

About the plugin

Plug-Ins allow for the Application Express framework to be readily extended with custom item types, region types, processes and Dynamic Actions. Once defined, plug-in based components are created and maintained much like standard Application Express components. Plug-ins enable developers to create highly customized components to enhance the functionality, appearance and user friendliness of their applications.

Generate PDF plugin is a dynamic action plugin which generates a PDF from the HTML content.

The plugin uses HtmlToPdfConverter toolkit to generate PDFs from HTML. It takes APEX region’s static ID as a parameter and converts the content inside this region to PDF. It also gives you an option to send it as an email attachment, with the ability to set the below parameters. The plugin calls an APEX process to send the generated PDF as an attachment.

To email address

From email address

From name

Email Subject

Email Body

PDF attachment name

Plugin Attributes

How to install

  1. Download the dynamic_action_plugin_generate_pdf.sql plugin file from GitHub repo (link below).
  2. Import the plugin file , go to Application -> Shared Components -> Plugins -> Import and import the file dynamic_action_plugin_generate_pdf.sql
  3. Upload the html2pdf JS (html2pdf.bundle.js) file to Shared Components -> images -> js folder

Plugin settings

The plugin has the following custom attributes

Custom Attributes
Plugin Settings

How to use

  1. In your APEX page, create a region with contents which you want to convert to PDF. Update the static ID.
  2. Create a button, add a dynamic action on click on this button and select action Generate PDF Plugin.
  3. Fill in the parameters as mentioned above.

APEX Email process

Generate PDF plugin uses an APEX process to send the generated PDF as an email attachment. The plugin converts the HTML from the page to a base64 string which is passed to the APEX process. The APEX process then converts the string to blob and sends it as an attachment.

To create this APEX process, go to your Application -> Shared Components -> Application Processes -> Create new and fill in the below details

Name: SEND_RECORD_EMAIL

Sequence: 1

Point: Ajax Callback

Update the source with the code in apex-process-send-email.sql from the GitHub repo.

GitHub

https://github.com/Ora-CustomApps/APEX-GeneratePDF-Plugin (private repo, contact me for access)

--

--