Skip to main content

Adding text and images to PDF

AOP provides several options to add texts and images in the PDF. Here are the examples on how you can perform the operations.

Adding Texts to PDF

AOP supports overlaying text on PDFs. To add text to PDFs, you can define per-page text or text on every page by placing text inside the attribute all, with flexible options for styling and positioning.
To utilize this feature, insert your text and desired styling properties into the aop_pdf_texts.
The supported styling properties include:

  • Position, defined by X and Y coordinates
  • Rotation, measured in degrees
  • Font style, such as typeface, bold, and italic
  • Font color
  • Font size
Providing x and y coordinates as percentage

From AOP 24.2.2 onwards, it is possible to specify x and y coordinates as a percentage of the page width and height. For that, you can provide the x and y coordinates as a string with a percentage sign at the end. e.g.

select
'First text to be shown in first page' as "text",
'50%' as "x",
'50%' as "y",
60 as "rotation",
'false' as "bold",
'false' as "italic",
'Arial' as "font",
'#FF00FF' as "font_color"
from dual

Example

The following example demonstrates how to insert per-page text with text styling and positioning.

Data Source

This SQL query generates a structured dataset for overlaying styled text on specific pages of a PDF. It defines the text content, position, rotation, font style, font color, and formatting for each page (P1 and P2).
AOP uses this data to overlay the text onto the PDF.

SELECT 'file1' AS "filename",
CURSOR (
SELECT CURSOR (
SELECT CURSOR (
SELECT 'First text to be shown in first page' AS "text",
50 AS "x",
600 AS "y",
0 AS "rotation",
'false' AS "bold",
'false' AS "italic",
'Arial' AS "font",
'#FF00FF' AS "font_color"
FROM dual
UNION ALL
SELECT
'Second text to be shown in first page' AS "text",
150 AS "x",
50 AS "y",
60 AS "rotation",
'false' AS "bold",
'false' AS "italic",
'Times new roman' AS "font",
'#00FFFF' AS "font_color",
20 AS "font_size"
FROM
dual
) AS "P1",
CURSOR (
SELECT 'First text to be shown in second page' AS "text",
50 AS "x",
600 AS "y",
0 AS "rotation",
'false' AS "bold",
'false' AS "italic",
'Arial' AS "font",
'#FF00FF' AS "font_color"
FROM dual
) AS "P2",
CURSOR (
SELECT 'Page {currentpage}/{totalpage}' AS "text",
10 AS "x",
10 AS "y",
0 AS "rotation",
'false' AS "bold",
'false' AS "italic",
'Arial' AS "font",
'#000000' AS "font_color",
'15' AS "font_size"
FROM dual
) AS "all"
FROM dual
) AS "aop_pdf_texts"
FROM dual
) AS "data"
FROM dual;
Page-Specific and Global Text Attributes

The P1 and P2 attributes in the code define the text for pages 1 and 2, respectively.
The all attribute adds text that appears on all pages of the PDF.
For example, the text Page {currentpage}/{totalpage} is added to all pages as it is specified within the all attribute.

Template

This example uses a general DOCX template.

 template.docx  

Output

When you provide a template and define your formatting and positioning specifications in the data source, AOP generates a PDF based on those settings.
For example, as shown in the image, the first page includes two text blocks, and the second page displays one, all styled according to the defined specifications on data source.

 output.pdf  

Adding Images to PDF

AOP supports overlaying images on a PDF. To implement this feature, place the image and its parameters inside the aop_pdf_images.
You can specify an image for each individual page or for all pages by including the image and its parameters within the all attribute.
The styling options available for images include:

  • Position, specified by X and Y coordinates,
  • Rotation, measured in degrees,
  • Width of the image.
Note

You can also use semi transparent PNG for wartermarking purposes.

Example

This example demonstrates how to overlay images onto a PDF.

Data Source

The data source includes the Apex Office Print logo along with its positioning specifications and width to overlay it onto the PDF.

SELECT
'file1' AS "filename",
CURSOR (
SELECT
CURSOR (
SELECT
CURSOR (
SELECT
'https://united-codes.com/uc_logos/aop/Branded/logo-apex-office@2x.png' AS "image",
50 AS "x",
400 AS "y",
500 AS "image_width",
- 75 AS "rotation"
FROM
dual
) AS "all"
FROM
dual
) AS "aop_pdf_images"
FROM
dual
) AS "data"
FROM
dual;

Template

This example uses the W-8BEN form, a Certificate of Foreign Status for Beneficial Owners, as a template. You can use any template that generates a PDF output, and images can be added to the PDF as needed.

 template.pdf  

Output

When you provide the image orientation details in the data source and a template, the output will be as follows.

 output.pdf