Skip to main content

PDF Attachments

Introduction

Available From: v23.1

AOP Allows users to provide attachments to PDF. PDF attachments are files that are attached to the PDF document. These files can be of any type. Here is an example of a PDF document with an attached file.

 sample_attachment_template.pdf  

PDF attachments can be added to the PDF document similar to how you add prepend and append files. In init PL/SQL, you can provide the attachment files using the g_attachments_sql variable. The SQL query must return the following columns:

  • filename - The name of the file to be attached to the PDF document.
  • mime_type - The mime type of the file.
  • file_blob - The file content as a BLOB.

Example for Attaching a File to PDF Template

Providing the Attachment file using Init PL/SQL.

aop_api_pkg.g_attachments_sql := q'[select file_name as filename, mime_type, file_content as file_blob
from apex_application_static_files
where application_id = :APP_ID
and file_name in ('sample_attachment_file.pdf', 'sample_attachment_file2.webp')
order by filename]';

Template

The template file must be a PDF. Attachment files will be attached to the PDF document.

 sample_attachment_template.pdf    sample_pdf_file.pdf    sample_attachment_file2.webp  

Output

Upon processing the template and attachments, the following output is obtained.

 Output.pdf  

Retrieving Attachments from PDF

Attachments can be retrieved from the PDF document by specifying output_type as get_attachments. In the plsql, you can use get_attachments in p_output_type parameter to retrieve the attachments from the PDF document. The attachments will be returned as a zip file. If you want a specific attachment, you should provide the attachment name in g_output_attachment_name parameter.

p_output_type => 'get_attachments',

Output

Upon processing the template PDF containing attachments, the output is a zip file with the attachments.

 attachments.zip  

Output While Retriving Attachments from PDF

If number of attachment in the PDF is 1 or g_output_attachment_name is provided, then the output will be a single file instead of a zip file.

Retriving Specific Attachment from PDF

If you want a specific attachment, you should provide the attachment name in g_output_attachment_name parameter in INIT PL/SQL.

aop_api_pkg.g_output_attachment_name:= "sample_attachment_file.pdf"

Retriving XML Attachment from PDF as a JSON

If you need data of the XML attachment as a JSON. For that, additionally you need to provide g_output_convert_attachment_to_json as true in init PL/SQL. Please note that output type should be get_attachments and this only works for XML attachments.

To retrive a specific XML attachment as JSON, you should provide both the attachment name in g_output_attachment_name parameter and g_output_convert_attachment_to_json as true in INIT PL/SQL.

aop_api_pkg.output_convert_attachment_to_json:= 1