Skip to main content
Roberty Studio
RPADocuments

PDF

PDF

The PDF module is responsible for performing handling actions on PDF files. Its methods can be accessed as in the example below:

js
const pdf = await Documents.PDF.toPdf["v1_0_0"]({
documentPath: "C:/Users/Roberty/Documents/teste.docx",
pdfPath: "C:/Users/Roberty/Documents/teste.pdf"
})

Methods​

readByRegions​

Method responsible for getting information as text from regions of a PDF selected by the user.

js
const infoRegions = await Documents.PDF.readByRegions["v1_0_0"]({
pdfPath: "C:/Users/Roberty/Documents/teste.pdf",
regions: [{
x: 20,
y: 20,
height: 20,
width: 20,
name: `endereco`,
page: 1
}]
})

Required parameters​

  • pdfPath: String - expects the path where the PDF file is stored. The path must contain the file name and the .pdf extension.
  • regions: Array of Objects - expects an array of objects that must contain the following properties:
    • x: number - expects a number that will be the initial horizontal position of the desired region, as a percentage of the page width (from 0 to 100);
    • y: number - expects a number that will be the initial vertical position of the desired region, as a percentage of the page height (from 0 to 100);
    • height: number - expects a number that will be the height of the region that must be selected, as a percentage of the page height;
    • width: number - expects a number that will be the width of the region that must be selected, as a percentage of the page width;
    • name: string - expects a name that will identify the area selected. It must start with a letter or _ and contain only letters, numbers and _ (e.g. address), and it cannot be repeated among the regions;
    • page: number - expects a number representing the page where the desired region is (1 = first page).

Optional parameters​

This method has no optional parameters.

Return​

The constant or variable created, such as the infoRegions of the example shown earlier, receives an object containing every name of the regions passed by the user. These properties return the information obtained in the region as text, as the example below shows:

js
const endereço = infoRegions.endereco
console.log(endereço) //mostrará o conteúdo obtido na região de endereço do PDF

If the file does not exist or the reading fails, the returned object has only the error property (e.g. pdfNotFound).

toPdf​

Method responsible for converting a file to the PDF format.

js
const convertError = await Documents.PDF.toPdf["v1_0_0"]({
documentPath: "C:/Users/Roberty/Documents/teste.docx",
pdfPath: "C:/Users/Roberty/Documents/teste.pdf"
})

Required parameters​

  • documentPath: String - expects the path of the file that will be converted. The path must contain the file name and the extension.
  • pdfPath: String - expects the path where the PDF file will be saved. The path must contain the file name and the .pdf extension.

Optional parameters​

This method has no optional parameters.

Return​

The constant or variable created, such as the convertError of the example shown earlier, receives a value of the Object type that gives access to the following properties:

  • convertError.error: string - returns an error message if the conversion is not performed successfully.

readLines​

Method responsible for reading the content of a PDF and returning it line by line.

js
const result = await Documents.PDF.readLines["v4_0_0"]({
pdfPath: "C:/Users/Roberty/Documents/teste.pdf",
})

Required parameters​

  • pdfPath: String - expects the path where the PDF file is stored. The path must contain the file name and the .pdf extension.

Optional parameters​

  • yThreshold: Number - expects a number defining the vertical tolerance (in pixels) to group elements in the same line. Useful for PDFs with irregular spacing between lines.

Return​

The constant or variable created, such as the result of the example shown earlier, receives an object with the following properties:

  • result.lines: String[][] - array of arrays of strings, where each position represents a line of the PDF and its text segments.
  • result.content: String - the whole content of the PDF in text format, with line breaks.

mergePDF​

Method responsible for merging multiple PDF files into a single file.

js
const mergePDF = await Documents.PDF.mergePDF.v1_0_0({
filesPath: [ '', '' ],
outputPath: ''
})

Required parameters​

  • filesPath: String[] - expects an array of strings with the paths of the PDFs you want to be merged into a single one. The path must contain the file name and the .pdf extension.
  • outputPath: String - expects the path where the PDF file will be saved. The path must contain the file name and the .pdf extension.

Optional parameters​

This method has no optional parameters.

Return​

This action has no return.