You can use the AODocs PDF Generator to:
- copy and convert to PDF format all the attachments in a document
- merge the converted attachments into a single PDF file
- apply a watermark, a header and/or a footer to all pages in the generated PDF
- either attach the new PDF file to the current document or download it
This article explains how to create a Viewer action custom script that performs all these actions. Parameters are available to define whether to:
- attach the PDF to the document or download it
- apply the watermark and/or headers and footers
Automatically generated table of contents
Create a document class and a watermark template
If you want to apply a watermark, you must first create a document to serve as the template in which you define the watermark, header and footer to apply to the generated PDF.
If you don't want to apply a watermark, skip this step.
Note: We recommend creating a new document class for the watermark template.
1. In the library administration, create a new document class.
2. Add the following String properties to the document class you intend to use for the template document:
- pdfHeader
- pdfFooter
- pdfWatermark
Important: Make sure you respect upper and lower case.
3. Create your template document in the new document class.
4. Fill in the properties with the text you want to appear in the watermark, header and/or footer.
Create a custom script
1. Create a new custom script. You can name it as you like. Define it as type Viewer Action.
Learn more: Custom scripts.
2. Click the name of your custom script to configure it.
3. Leave the default options:
- Run with current user's privileges.
- checkbox Async execution unselected
4. Copy the code from the sample custom script into your custom script.
5. If you are working in a library that uses Google Cloud Storage or Azure Blob storage, you must remove the two forward slashes at the beginning of the line outlined in red.
6. Create an optional parameter called behavior
and give it the default value Download
.
Important: Make sure you respect upper and lower case for parameters and their values. The names of the parameters and their values don't appear in the end user interface.
7. If you want to apply a watermark, create two more optional parameters:
- parameter
applyWatermark
with the default valueTrue
- parameter
documentId
with as default value the ID of the watermark template you created in the previous step.
Note: Learn about how to retrieve document IDs.
8. Click Save.
Create custom actions
Create one or more custom actions according to your business requirements. You can choose to:
- attach the new PDF file to the current document or download it
- apply the watermark, header and/or footer you defined in your watermark template, or not
To do this, when you create a custom action, you must give values to the parameters.
Note: Change the default values if necessary.
Parameter | Possible values |
|
By default: the ID of your watermark template. |
|
|
|
|
1. In the library administration, open the document class in which you want to use the script (in our example, "Document") and select the Custom tab.
2. Click the Add a new viewer custom action button.
3. Enter the text that will appear in the user interface to run the custom script, in our example, "Download PDF with watermark".
4. Select the required custom script, in our example, "AODocs PDF Generator".
5. Click Create
Note: In this example we kept the default parameter values.
7. To change the default value of a parameter, click the pencil button and define a new value. Then click Apply.
In the example below we created a new custom action "Attach PDF without watermark" and we changed the values of:
- the
behavior
parameter toAttach to document
- the
applyWatermark
parameter toFalse
8. Save your changes.
Run your custom script: end user experience
A jigsaw puzzle button appears in the tool bar. Its drop-down menu contains the custom actions you defined. Select the required option to run the script.
Important: The document must have at least one attachment.
All the attachments are copied, converted to PDF format and merged into a single PDF file. If you used the applyWatermark
parameter, the watermark, header and/or footer are applied to all the pages in the PDF.
The PDF takes the name of your AODocs document with a time stamp.
If you selected the option to download the PDF, it opens in a new tab. Click download.
If you selected the option to attach the PDF to the current document, the PDF is listed in the Attachments section.
Notes:
– If you run the script in a document with no attachments, an error message appears.
– If you re-run the script, a PDF of all the files are copied, converted and merged again, including the first PDF you generated (if you chose to attach it to the document). If you need to re-run the script, we recommend removing the generated PDF first.
Customize the display of the text in the watermark, header and footer
You can edit the custom script to customize the display of the text used in the watermark, header and footer.
Open your custom script. In the bottom field find the three blocks of code corresponding to the watermark, header and footer settings.
The following settings are available:
Font family | Font size | Font style | Font color | Rotation | Repeat text | Alignment | |
Header and footer | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Watermark | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Change the font family and font style
The table below shows the font families and font styles available for each type of renderer.
Renderer | Font family | Font style | Notes |
LEGACY |
|
|
You can't use UNDERLINE and LINETHROUGH at the same time for footers and headers, but you can for the watermark. |
STANDARD |
|
|
You can't use UNDERLINE or LINETHROUGH for the watermark, but you can for headers and footers (though not at the same time) |
ADVANCED |
|
|
You can't use font styles for headers or footers, but you can for the watermark.
* You can't use font styles with these font families ** You can't use these font families for the watermark, but you can for headers and footers |
You may want to change the renderer to be able to use a particular font family or font style. To do this, enter LEGACY
, STANDARD
, or ADVANCED
on the line that defines the renderer for the behavior
parameter value you defined.
In the example below, the STANDARD
renderer is defined for both "Attach to document" and "Download".
When you have selected the required renderer, in the blocks of code corresponding to the watermark, header and footer settings, edit the:
-
.setFontFamily(PdfWatermarkConfig.FontFamily.XXX)
line to change the font family -
.setFontStyle(PdfWatermarkConfig.FontStyle.XXX)
line to change the font style
Note: There can be more than one font style defined, separated by commas.
In the example below:
- the font family for the watermark, header and footer is
HELVETICA
- the font style for the watermark is commented, so no particular style is applied
- the font style for the header is italic and underlined
- the font style for the footer is bold
Change the font size
To change the font size, edit the .setFontSize(XX)
line in the blocks of code corresponding to the watermark, header and footer.
Change the degree of rotation of the watermark
To change the degree of rotation of the watermark, edit the .setRotation(XX);
line in the block of code corresponding to the watermark.
Note: You can't rotate text in headers or footers.
Change the repeat frequency of the watermark
To change the number of times the watermark is repeated, edit the .setRepeatCount(X)
line in the block of code corresponding to the watermark.
Notes:
–The default value is 1.
– You can't repeat text in headers or footers.
Change the alignment of the headers and footers
To change the alignment of the headers and footers, enter LEFT
, RIGHT
or CENTER
in the .setTextAlign(PDFHeaderFooterConfig.TextAlign.XXX);
line in the blocks of code corresponding to the header and/or footer.
Note: You can't align the watermark.