The PDF module is responsible for performing handling actions on PDF files. Its methods can be accessed as in the example below:
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.
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 in pixels of where the desired region is;
- y: number - expects a number that will be the initial vertical position in pixels of where the desired region is;
- height: number - expects a number that will be the height in pixels of the region that must be selected;
- width: number - expects a number that will be the width in pixels of the region that must be selected;
- name: string - expects a name that will identify the area selected;
- page: number - expects a number representing the page where the desired region is.
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:
const endereço = infoRegions.endereco
console.log(endereço) //mostrará o conteúdo obtido na região de endereço do PDF
toPdf
Method responsible for converting a file to the PDF format.
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.
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.pdfextension.
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.
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.