Skip to main content

Using PDF as a template

AOP empowers you to use existing PDF documents as templates, dynamically populating them with data from your application. This feature is ideal for generating standardized business documents such as invoices, reports, or certificates where a consistent layout must be maintained while the content varies.

Key Features

  • Text Insertion: Seamlessly inject dynamic text into predefined locations within your PDF template.
  • Image Insertion: Embed images (logos, signatures, QR codes) dynamically into designated areas.
  • Page Repeating: Automatically duplicate pages for iterating over datasets, perfect for multi-item invoices or batch processing.

Understanding PDF Tags

To make a PDF template interactive, you place special placeholders called "tags" in the document. AOP recognizes three primary tag types:

Tag TypeSyntaxPurposeExample
Text{tagname}Replaced with text values from your data{customer_name}
Image{%tagname}Replaced with images (URL or Base64){%company_logo}
Repeat{!tagname}Duplicates the page for each item in an array{!invoice_items}

Download a sample tagged template:

 sample_tagged_template.pdf  

Let's explore each tag type with practical examples.

Text Insertion

Text tags are the most common way to inject dynamic data into your PDF. Simply place {tagname} in your PDF template where you want the text to appear, and AOP will replace it with the corresponding value from your data source.

Example Scenario: Generate an invoice header with customer details.

Data Source

SELECT
'file1' AS "filename",
CURSOR (
SELECT
'John Doe' as "customer_name",
'INV-2025-001' as "invoice_number",
TO_CHAR(SYSDATE, 'YYYY-MM-DD') as "issue_date",
'$1,500.00' as "amount"
FROM
dual
) AS "data"
FROM
dual;

How to use in your PDF template:

Place these tags in your PDF document:

  • {customer_name} → Replaced with "John Doe"
  • {invoice_number} → Replaced with "INV-2025-001"
  • {issue_date} → Replaced with the current date
  • {amount} → Replaced with "$1,500.00"

Template

 sample_text_template.pdf  

Output

 text_output.pdf  

Image Insertion

Image tags enable you to dynamically place visuals in your PDF. Use the {%tagname} syntax to insert images from URLs or Base64-encoded strings.

Example Scenario: Add a company logo, digital signature, and QR code to an invoice.

SELECT
'file1' AS "filename",
CURSOR (
SELECT
'https://example.com/logo.png' as "company_logo",
l_base64_signature_image as "signature",
'https://example.com/qr/INV-2025-001.png' as "qr_code"
FROM
dual
) AS "data"
FROM
dual;

How to use in your PDF template:

Place these image tags in your PDF document:

  • {%company_logo} → Inserts the company logo
  • {%signature} → Inserts the signature image
  • {%qr_code} → Inserts the QR code

Template

 sample_image_template.pdf  

Output

 image_output.pdf  

Page Repeating

The Page Repeat tag, {!tagname}, is a powerful feature for batch processing and multi-item documents.

How it works:

  1. Place {!tagname} anywhere on a PDF page
  2. AOP looks for an array of objects in your data under tagname
  3. For each item in that array, AOP duplicates the entire page and populates it with that item's data

Example Scenario: Generate an employee profile card for every employee in your system.

Data Source

SELECT
'file1' AS "filename",
CURSOR (
SELECT
json_arrayagg(
json_object(
'name' value e.name,
'role' value e.role,
'department' value e.department,
'city' value e.city,
'country' value e.country,
'salary' value e.salary,
'active' value e.active,
'companyLogo' value e.logo_base64,
'companyLogo_width' value 150,
'companyLogo_height' value 80
)
) AS "items"
FROM employees e
) AS "data"
FROM
dual;

Template

 pdf_tags_repeat.pdf  

Output

 pdf_tags_repeat_output.pdf