ftos.files.pdf.writeText
IMPORTANT!
Starting with v24.3.0, this is renamed from writeText to ftos.files.pdf.writeText.
Starting with v24.3.0, this is renamed from writeText to ftos.files.pdf.writeText.
Inserts text boxes in a PDF file and uploads the resulting document in the file upload location.
This is a business logic method for business service components.
Syntax
Copy
function ftos.files.pdf.writeText(sourceRealName: string, outputFileName: string, textList: any[], textOptions: any): string
| Parameter | Description |
|---|---|
sourceRealName
|
Unique internal ID of the source PDF file (real name). |
outputFileName
|
Name of the resulting PDF file where you wish to add the text boxes. The file name must include the .pdf file extension. |
textList
|
Array of JSON objects containing the text boxes coordinates, text contents, and page numbers in the source PDF where they must be inserted. |
textOptions
|
JSON object containing formatting parameters for the inserted text. |
The textList parameter has the following structure:
Copy
[
{rect:{left: <'box 1 left margin'>, right: <'box 1 right margin'>, bottom: '<box 1 bottom margin>', top: '<box 1 top margin>'}, text:'<dummy text>', page: <source PDF box 1 page no.>, newText:'<box 1 text contents>'});
{rect:{left: <'box 2 left margin'>, right: <'box 2 right margin'>, bottom: '<box 2 bottom margin>', top: '<box 2 top margin>'}, text:'<dummy text>', page: <source PDF box 2 page no.>, newText:'<box 2 text contents>'});
...
];
The textOptions object includes text formatting attributes, for example:
Copy
{fontColor: 'Black', fontSize: 10, fontName: 'Arial'}
Return Value
Returns a string containing the saved PDF's real name.
Type Aliases
Examples
In this example,:
- We generate a text box with the DRAFT contents at the following position {left: 20, bottom: 20, right: 220, top: 30}.
- We generate a text box with the Internal use only contents at the following position {left: 0, bottom: 30, right: 220, top: 40}.
- We display the two text boxes on each page of the document_df7022c8-4fb3-4353-9fa8-bb2514e3a6ea.pdf file. For details on how to get the total number of pages of a PDF document, see ftos.files.pdf.getPagesCount.
- We save the resulting document in a file called document_draft_wm.pdf.
- The watermark text will be displayed with red size 10 Arial fonts.
- We store the resulting file's real name in a variable called fileName which we display on screen. For details on how to display messages, see ftos.context.response.setMessage.
Copy
var rectangle1 = {left: 20, bottom: 20, right: 220, top: 30};
var rectangle2 = {left: 0, bottom: 30, right: 220, top: 40};
var textWithPositions = [];
var i = Number
for (i=1; i<=ftos.files.pdf.getPagesCount('document_df7022c8-4fb3-4353-9fa8-bb2514e3a6ea.pdf'); i++){
textWithPositions.push({rect:rectangle1, text:'nothing', page:i, newText:'DRAFT'});
textWithPositions.push({rect:rectangle2, text:'nothing', page:i, newText:'Internal use only'});
}
var options = {fontColor: 'red', fontSize: 10, fontName: 'Arial'};
fileName = ftos.files.pdf.writeText('document_df7022c8-4fb3-4353-9fa8-bb2514e3a6ea.pdf', 'document_draft_wm.pdf', textWithPositions, options);
ftos.context.response.setMessage('File ' + fileName + ' has been saved.')