Pdf file operation
The Pdf class in "leanpro.visual" provides the function of Pdf file content extraction.
The Pdf class has the following definition
JavaScript
interface PdfExtractOptions {
fontSize?: number,
password?: string
}
class Pdf {
static fromFile(inputFile: string): Pdf;
async extract(pageNum: number, options: PdfExtractOptions): Promise<string>;
}
in:
fromFile
A static method that generates a Pdf object instance from a Pdf file. This instance can be used to perform subsequent operations.
extract
Pass in the page number and other extraction parameters to extract the content of the page in the Pdf instance object. Page numbers start from 1.
Example:
JavaScript
let { Pdf } = require('leanpro.visual')
async function test() {
let inputFile = __dirname + '/sample.pdf';
let pageNum = 1;
let pdf = Pdf.fromFile(inputFile);
let content = await pdf.extract(pageNum);
console.log(content);
}
test();
The above example extracts the content of the first page in the sample.pdf file and outputs it.