Skip to main content

General

Introduction

In this section, we will cover the various actions that can be performed on PDF documents, along with the corresponding query for selecting the relevant data.

Conversion to PDF from different file formats

In AOP it is possible to convert different file formats to PDF. The possible file formats and their corresponding mime types are listed below.

File FormatMime Type
pdfapplication/pdf
docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
docmapplication/vnd.ms-word.document.macroEnabled.12
xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
pptmapplication/vnd.ms-powerpoint.presentation.macroEnabled.12
htmltext/html
mdtext/markdown
txttext/plain
gifimage/gif
jpegimage/jpeg
jpgimage/jpeg
pngimage/png
svgimage/svg+xml
webpimage/webp
bmpimage/bmp
msbmpimage/x-ms-bmp
docapplication/msword
pptapplication/vnd.ms-powerpoint
xlsapplication/vnd.ms-excel
odtapplication/vnd.oasis.opendocument.text
odsapplication/vnd.oasis.opendocument.spreadsheet
odpapplication/vnd.oasis.opendocument.presentation
emlmessage/rfc822
msgapplication/vnd.ms-outlook
csvtext/csv

Removing Last Page From a PDF

Have you ever been in a situation where you have a PDF with a blank last page? If so, you can use the remove_last_page option to remove the last page of a PDF.

For this, in your "output" object, you can add output_remove_last_page as a boolean value. In the INIT PL/SQL section you can provide g_output_remove_last_page as true.

aop_api_pkg.g_output_remove_last_page:= true

and with any template with PDF as output type, the last page will be removed from the output PDF.

 template.docx    output.pdf  

Protecting a PDF with a Password

For protecting a PDF with a password for access and/or modification, you can provide g_output_read_password and/or g_output_modify_password and/or goutput_pwd_protection_flag in the INIT PL/SQL section. It will protect the PDF from read access and/or modification. The g_output_pwd_protection_flag is optional. Click Here for more information on protection flags.

aop_api_pkg.g_output_read_password:= 'read_password';
aop_api_pkg.g_output_modify_password:= 'modify_password';
aop_api_pkg.g_output_pwd_protection_flag:= '4';

and with any template with PDF as output type, the output PDF will be password protected.

 template.docx    output.pdf  

tip

You can use the output_read_password and output_modify_password options together or separately.

Adding Barcodes to PDF

AOP supports overlay of barcodes on PDF. To add barcodes to PDF Templates "output_insert_barcode" should be true. In the INIT PL/SQL section you can provide g_output_insert_barcode as true. The template type should be PDF.

In the data section, data can be provided as normal data for the AOP. The properties that are available for the barcode are:

  • _type : The type of the barcode.
  • _height : The height of the barcode.
  • _width : The width of the barcode.

Example

Template

{|barcode}

Data Source

select 'file1' as "filename",
cursor (
select '1234567890' as "barcode",
'code128' as "barcode_type",
50 as "barcode_height",
50 as "barcode_width"
from dual
) as "data"
from dual;

In the INIT PL/SQL section you should provide g_output_insert_barcode as true.

aop_api_pkg.g_output_insert_barcode:= 1;  -- or true

with a template with PDF as output type, the output PDF will have the barcode.

 template.pdf    output.pdf  

Splitting the PDF into Multiple PDFs

For splitting a PDF into multiple PDFs, you can use the output_split option. For splitting the PDF into multiple PDFs, in INIT PL/SQL section you can provide g_output_split as true.

aop_api_pkg.g_output_split := 'true';

From AOP 24.3 onwards, we can now split pdf by specifying number of pages, or any string present in PDF. For that you should specify g_output_split_by_string in the INIT PL/SQL section.

aop_api_pkg.g_output_split := 'true';
aop_api_pkg.g_output_split_by_page := 3;
aop_api_pkg.g_output_split_by_string := 'Invoice No || Invoice Number' -- You should specify either of the parameter, if you specify both, split by page will be considered.

and a template with PDF as output type, the output PDF will be split into multiple PDFs. The output will be a zip file with each page of the input PDF as a separate PDF file.

 template.docx    output.zip  

Adding Watermark to PDF

Adding a watermark to a PDF can be done using the following options and parameters:

  • Use the output_watermark option in the output object to specify the watermark text as a plain string.
  • To set the color of the watermark text, use output_watermark_color with a plain string. The default color value is black.
  • To customize the font of the watermark text, use output_watermark_font with a plain string. The default font is Arial.
  • Adjust the opacity of the watermark text using output_watermark_opacity, which takes a number representing the opacity in percentage.
  • Specify the size of the watermark text using output_watermark_size with a number representing the size in pixels.

In the INIT PL/SQL section, you have the following options:

  • g_output_watermark: Set this to provide the watermark text.
  • g_output_watermark_color: Use this to define the color of the watermark text.
  • g_output_watermark_font: Set this to customize the font of the watermark text.
  • g_output_watermark_opacity: Use this to adjust the opacity of the watermark text (in percentage).
  • g_output_watermark_size: Set this to specify the size of the watermark text (in pixels).
aop_api_pkg.g_output_watermark:= 'watermark text';
aop_api_pkg.g_output_watermark_color:= 'red';
aop_api_pkg.g_output_watermark_font:= 'Arial';
aop_api_pkg.g_output_watermark_opacity:= 50;
aop_api_pkg.g_output_watermark_size:= 45;

and any template with PDF as output type, the output PDF will have the watermark text in the background. The result will look like this.

watermark_output

 template.docx    output.pdf  

Generating PDF/A Compliant PDF

For generating PDF/A format, we can use the output_convert_to_pdfa option. While converting using openoffice converter, specifying it will create PDF/A format, values can be either 1b or 2b which are the variants of PDF/A specification.

For example, if we want to convert a PDF to PDF/A-1b format, we can provide the value 1b in the output_convert_to_pdfa option. In INIT PL/SQL section you can provide g_output_convert_to_pdfa.

aop_api_pkg.g_output_convert_to_pdfa := '1b';
IMPORTANT NOTE

The PDF/A conversion is only supported by the openoffice converter. While converter handles the conversion, it is the responsibility of the template designer to ensure that the template is accessible.

and any template with PDF as output type, the output PDF will be in PDF/A-1b format.

 template.docx    output.pdf  

Generating PDF/UA standard PDF

For generating PDF/UA format, we can use the output_ua_compliant_pdf option. While converting using openoffice converter, specifying it will create PDF/UA format, values can be either true or false.

In INIT PL/SQL section you can provide g_output_ua_compliant_pdf.

aop_api_pkg.g_output_ua_compliant_pdf := 1;
IMPORTANT NOTE

The PDF/UA conversion is only supported by the openoffice converter. While converter handles the conversion, it is the responsibility of the template designer to ensure that the template is accessible.

 template.docx    output.pdf  

Flattening (Locking) PDF Form Fields

For flattening (locking) PDF form fields, we can use the lock_form option. In the output object we can provide the value true in the lock_form option. In the INIT PL/SQL section you can provide g_output_lock_form as true.

aop_api_pkg.g_output_lock_form := true;

Here's an example of a PDF form before and after it is flattened.

 template.pdf    output.pdf  

Ignoring Signature Fields while Flattening

If you want to ignore signature fields while flattening, you can use the g_lock_form_ignoring_sign option. In the output object we can provide the value true in the lock_form_except_signaturefield option.

aop_api_pkg.g_lock_form_ignoring_sign := true;

Creating Single Page PDF

Some printers can print a document which has unspecified height and tear the paper once the page is finished. These kinds of printers are used for ticketing systems. Since the height is dynamic, it is not possible to create the document in Word. AOP has a feature to create a single page PDF. This allows users to create a template in Word (or any other format) and get their output in a single page.

For that, you need to set Output Type to One Page PDF.

Single Page PDF

Duplicating the PDF into multiple copies

In AOP it is possible to duplicate the PDF into multiple copies. Lets take an example where we will be duplicating the PDF into 3 copies. For that, in the INIT PL/SQL Code section, following SQL needs to be placed.

aop_api_pkg.g_output_copies := 3;

Parameters for Specifying the Quality of the PDF (openoffice converter only)

If you are using openoffice converter, AOP provides options to provide the quality of the PDF. The options available are set the resolution of the image i.e. 300dpi, 600dpi, 900dpi or 1200dpi, and jpeg compression factor ranging from 0-100. The quality of the PDF can be set by using the following SQL in INIT PL/SQL Code section.

aop_api_pkg.g_output_image_resolution := "300dpi";
aop_api_pkg.g_output_image_compression := 100;

Changing the Locale used During Conversion (openoffice converter only)

AOP provides the option to change the locale used during conversion. You can use options like en , ne for the locale parameter. The locale can be changed by using the following SQL in INIT PL/SQL Code section.

aop_api_pkg.g_output_locale  := "ne";

Adding Annotations/Comments To PDF

Using AOP you can add annotations to the PDF. The process of adding annotations to PDF is similar to adding texts to PDF. You can define per page annotations that you want to place on the PDF along with some other properties. The properties include x and y coordinates where you want to place the annotation on the PDF, width and height of the annotation. The default height and width of annotations are 200 units and 50 units respectively. You can also set the color of the annotation and text to be displayed in the annotation.

SELECT
'file1' AS "filename",
CURSOR (
SELECT
CURSOR (
SELECT
CURSOR (
SELECT
'First text to be shown in first page' AS "text",
50 AS "x",
50 AS "y",
'#FFE1BD' AS "color",
200 AS "height",
50 AS "width"
FROM
dual
UNION ALL
SELECT
'Second text to be shown in first page' AS "text",
150 AS "x",
50 AS "y",
'#00FFFF' AS "color"
FROM
dual
) AS "P1",
CURSOR (
SELECT
'First text to be shown in second page' AS "text",
50 AS "x",
50 AS "y",
'#f9f9f9' AS "color"
FROM
dual
) AS "P2",
CURSOR (
SELECT
'Page Commenting here' AS "text",
0 AS "x",
0 AS "y",
'#000000' AS "color"
FROM
dual
) AS "all"
FROM
dual
) AS "aop_pdf_comments"
FROM
dual
) AS "data"
FROM
dual

With any Template whose output is PDF, we can add annotations to the PDF.

 template.pdf    output.pdf  

Validating a PDF document

Available from: v24.3

In AOP for a PDF template, you can validate if the document is a valid PDF document. For this, you need to set output_type parameter to validate_pdf. The response will be a JSON object with the following keys:

  • valid: A boolean value indicating if the document is a valid PDF document.
  • message: A message indicating the result of the validation.

There might be three possible values for the message key:

  • When a document is a valid PDF document (valid: true), the message will be PDF is valid.
  • When a document is not a valid PDF document (valid: false), the message will start with Error: followed by the exception obtained.
  • When the document is password protected (valid: true) the message will be PDF is password protected.

Example

Here is an example of how a PDF can be validated.

PLSQL Code

PL/SQL code used to call AOP, which returns a JSON response in a CLOB.

declare
l_output_filename varchar2(300);
l_blob blob;
l_clob clob;
begin
l_blob := aop_api_pkg.plsql_call_to_aop(
p_data_type => aop_api_pkg.c_source_type_none,
p_template_type => aop_api_pkg.c_source_type_apex,
p_template_source => 'aop_pdf_form_filled.pdf', -- Your template source
p_output_type => aop_api_pkg.c_validate_pdf, -- output type as "validate_pdf"
p_output_filename => l_output_filename,
p_aop_url => 'https://api.apexofficeprint.com/',
p_api_key => :AOP_API_KEY, --your api key
p_app_id => :APP_ID
);

l_clob := aop_api_pkg.blob2clob(l_blob);

l_clob := replace(l_clob,'],','],'||CHR(10));

return l_clob;
end;

Template

For the template, you can use any PDF file.

alt text

 template.pdf  

Output

When the given template is valid, as shown in the image above, AOP will provide the JSON response {"valid":true,"message":"PDF is valid"}. However, the response for others will be as listed below.

//for valid PDF
{
"valid": true,
"message": "PDF is valid"
}
//for password protected PDF
{
"valid": true,
"message": "PDF is password protected"
}
//for invalid PDF
{
"valid": false,
"message": "Error: Header doesn't contain versioninfo"
}

Converting PDF to Images

Available from: v24.3

AOP allows you to convert a PDF document into images. For this you just need to set the Output Type as image(jpeg), and a ZIP file containing all the images will be returned as the output.

Info

Currently, conversion from PDF to JPEG is the only supported format.

Example

Here is an example of how a PDF can be converted into images using AOP.

Data Source

The dynamic action settings for converting a PDF into images is shown below.
You need to select Image(jpeg) as the Output Type in the dynamic action.

alt text

Template

For the template, you can use any PDF file.

alt text

 multi_page_template.pdf  

Output

Upon processing the provided template and setting Output Type as Image(jpeg), the resulting output is as follows.

alt text

 output.zip