diff --git a/API.md b/API.md index 61a205a8..e1a23da5 100644 --- a/API.md +++ b/API.md @@ -199,7 +199,7 @@ Converts a PDF file to PNG/JPEG/TIFF/PDF/PS/EPS/SVG. | Param | Type | Description | | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | file | string | Filepath of the PDF file to read. | -| [outputFile] | string | Filepath of the file to output the results to. Can be set to `'-'` to write output to stdout. Using stdout is not valid with image formats unless `options.singleFile` is set to `true`. If not set then the output filename will be derived from the PDF file name. | +| [outputFile] | string | Filepath of the file to output the results to. If `undefined` then will write output to stdout. Using stdout is not valid with image formats unless `options.singleFile` is set to `true`. If not set then the output filename will be derived from the PDF file name. | | [options] | object | Object containing options to pass to binary. | | [options.antialias] | 'default' \| 'none' \| 'gray' \| 'subpixel' \| 'fast' \| 'good' \| 'best' | Set the cairo antialias option used for text and drawing in image files (or rasterized regions in vector output). | | [options.cropBox] | boolean | Uses the crop box rather than media box when generating the files (PNG/JPEG/TIFF only). | @@ -349,7 +349,7 @@ Converts a PDF file to PostScript (PS). | Param | Type | Description | | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | file | string | Filepath of the PDF file to read. | -| [outputFile] | string | Filepath of the file to output the results to. Can be set to `'-'` to write output to stdout. | +| [outputFile] | string | Filepath of the file to output the results to. If `undefined` then will write output to stdout. | | [options] | object | Object containing options to pass to binary. | | [options.antialias] | 'yes' \| 'no' | Enable anti-aliasing on rasterization, accepts `yes` or `no`. | | [options.binary] | boolean | Write binary data in Level 1 PostScript. By default, pdftops writes hex-encoded data in Level 1 PostScript. Binary data is non-standard in Level 1 PostScript but reduces the file size and can be useful when Level 1 PostScript is required only for its restricted use of PostScript operators. | @@ -401,7 +401,7 @@ Converts a PDF file to TXT. | Param | Type | Description | | -------------------------------- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | file | string | Filepath of the PDF file to read. | -| [outputFile] | string | Filepath of the file to output the results to. Can be set to `'-'` to write output to stdout. | +| [outputFile] | string | Filepath of the file to output the results to. If `undefined` then will write output to stdout. | | [options] | object | Object containing options to pass to binary. | | [options.boundingBoxXhtml] | boolean | Generate an XHTML file containing bounding box information for each word in the file. | | [options.boundingBoxXhtmlLayout] | boolean | Generate an XHTML file containing bounding box information for each block, line, and word in the file. | diff --git a/CHANGELOG.md b/CHANGELOG.md index e5037217..96e54442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +## 2.0.0 (2020-11-03) + +- docs: enable TypeScript definition generation for all methods ([cceecc8](https://github.com/Fdawgs/node-poppler/commit/cceecc8)) , thanks to @arthurdenner +- docs(index): correct stdout usage ([be0bb49](https://github.com/Fdawgs/node-poppler/commit/be0bb49)) +- docs(readme): add note about macos binaries ([41c7e1e](https://github.com/Fdawgs/node-poppler/commit/41c7e1e)) +- test(index): correct param orders for function calls ([e075a7b](https://github.com/Fdawgs/node-poppler/commit/e075a7b)) +- build(deps-dev): bump dev dependencies ([c450c04](https://github.com/Fdawgs/node-poppler/commit/c450c04)) +- build(travis): update osx image ([0c043db](https://github.com/Fdawgs/node-poppler/commit/0c043db)) +- feat(index): add typescript definition file ([d82df8b](https://github.com/Fdawgs/node-poppler/commit/d82df8b)) +- feat(lib): update poppler win32 binaries from 20.10.0 to 20.11.0 ([bc5478e](https://github.com/Fdawgs/node-poppler/commit/bc5478e)) +- refactor(index): reorder parameters for all functions ([ead466e](https://github.com/Fdawgs/node-poppler/commit/ead466e)) +- chore: add TypeScript config to generate definition ([c5b4858](https://github.com/Fdawgs/node-poppler/commit/c5b4858)), thanks to @arthurdenner +- chore(scripts): do not lint ts and tsx files ([b1e8426](https://github.com/Fdawgs/node-poppler/commit/b1e8426)) + +### BREAKING CHANGE + +- optional `options` object parameter for all functions has been moved to the end. i.e. `Poppler.pdfToText(options, file, outputFile)` is now `Poppler.pdfToText(file, outputFile, options)`. + +This allows for easier use of the functions as users no longer have to place an undefined parameter if no options are provided. `Poppler.pdfToText(undefined, file, outputFile)` can now be called instead like `Poppler.pdfToText(file, outputFile)`. + ## 1.8.5 (2020-10-14) - build: create codeql-analysis.yml workflow file ([7346f8f](https://github.com/Fdawgs/node-poppler/commit/7346f8f)) diff --git a/README.md b/README.md index 34cca400..6885f662 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ npm install node-poppler node-poppler's test scripts use yarn commands. ### Linux and macOS/Darwin support + Windows and macOS/Darwin binaries are provided with this repository. For Linux users, you will need to download the `poppler-data` and `poppler-utils` binaries separately. diff --git a/package.json b/package.json index 833c8930..cb1cb96c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-poppler", - "version": "1.8.5", + "version": "2.0.0", "description": "Asynchronous node.js wrapper for the Poppler PDF rendering library", "keywords": [ "async", diff --git a/src/index.d.ts b/src/index.d.ts index 37551835..d3b1f054 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,493 +1,538 @@ -export class Poppler { - /** - * @param {string=} binPath - Path of poppler-utils binaries. - * Useful for Linux users who have poppler-utils binaries already installed. - */ - constructor(binPath?: string | undefined); - popplerPath: string; - /** - * @author Frazer Smith - * @description Embeds files (attachments) into a PDF file. - * @param {string} file - Filepath of the PDF file to read. - * @param {string} fileToAttach - Filepath of the attachment to be embedded into the PDF file. - * @param {string} outputFile - Filepath of the file to output the results to. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {boolean=} options.replace - Replace embedded file with same name (if it exists). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfAttach(file: string, fileToAttach: string, outputFile: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Lists or extracts embedded files (attachments) from a PDF file. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.listEmbedded - List all of the embedded files in the PDF file. - * File names are converted to the text encoding specified by the `outputEncoding` option. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {string=} options.outputEncoding - Sets the encoding to use for text output. - * This defaults to `UTF-8`. - * @param {string=} options.outputPath - Set the file name used when saving an embedded file with - * the save option enabled, or the directory if the `saveall` option is used. - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {boolean=} options.saveAllFiles - Save all of the embedded files. This uses the file - * names associated with the embedded files (as printed by the `listEmbedded` option). - * By default, the files are saved in the current directory; this can be changed - * with the `outputPath` option. - * @param {string=} options.saveFile - Save the specified embedded file. - * By default, this uses the file name associated with the embedded file (as printed by the - * `listEmbedded` option); the file name can be changed with the `outputPath` option. - * @param {number=} options.saveSpecificFile - Save the specified embedded file. - * By default, this uses the file name associated with the embedded file (as printed by the - * `listEmbedded` option); the file name can be changed with the `outputPath` option. - * @param {string=} options.userPassword - User password (for encrypted files). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfDetach(file: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Lists the fonts used in a PDF file along with various information for each font. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {object=} options - Object containing options to pass to binary. - * @param {number=} options.firstPageToExamine - Specifies the first page to examine. - * @param {number=} options.lastPageToExamine - Specifies the last page to examine. - * @param {boolean=} options.listSubstitutes - List the substitute fonts that poppler - * will use for non-embedded fonts. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {string=} options.userPassword - User password (for encrypted files). * - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfFonts(file: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string} outputPrefix - Filename prefix of output files. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.allFiles - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format. - * CMYK files are written as TIFF files. All other images are written as PNG files. - * @param {boolean=} options.ccittFile - Generate CCITT images as CCITT files. - * @param {number=} options.firstPageToConvert - Specifies the first page to convert. - * @param {number=} options.lastPageToConvert - Specifies the last page to convert. - * @param {boolean=} options.list - Instead of writing the images, list the - * images along with various information for each image. - * NOTE: Do not specify the outputPrefix with this option. - * @param {boolean=} options.jbig2File - Generate JBIG2 images as JBIG2 files. - * @param {boolean=} options.jpeg2000File - Generate JPEG2000 images at JP2 files. - * @param {boolean=} options.jpegFile - Generate JPEG images as JPEG files. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {boolean=} options.pngFile - Change the default output format to PNG. - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {boolean=} options.tiffFile - Change the default output format to TIFF. - * @param {string=} options.userPassword - Specify the user password for the PDF file. - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfImages(file: string, outputPrefix: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Prints the contents of the `Info` dictionary from a PDF file. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {object=} options - Object containing options to pass to binary. - * @param {number=} options.firstPageToConvert - First page to print. - * @param {number=} options.lastPageToConvert - Last page to print. - * @param {boolean=} options.listEncodingOptions - List the available encodings. - * @param {string=} options.outputEncoding - Sets the encoding to use for text output. - * This defaults to `UTF-8`. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {boolean=} options.printBoundingBoxes - Prints the page box bounding boxes: - * MediaBox, CropBox, BleedBox, TrimBox, and ArtBox. - * @param {boolean=} options.printDocStruct - Prints the logical document structure - * of a Tagged-PDF file. - * @param {boolean=} options.printDocStructText - Print the textual content along with the - * document structure of a Tagged-PDF file. Note that extracting text this way might be slow - * - * for big PDF files. - * @param {boolean=} options.printIsoDates - Prints dates in ISO-8601 format (including the time zone). - * @param {boolean=} options.printJS - Prints all JavaScript in the PDF file. - * @param {boolean=} options.printMetadata - Prints document-level metadata. (This is the `Metadata` - * stream from the PDF file's Catalog object). - * @param {boolean=} options.printNamedDests - Print a list of all named destinations. If a page range - * is specified using the `firstPageToConvert` and `lastPageToConvert` options, only destinations - * in the page range are listed. - * @param {boolean=} options.printRawDates - Prints the raw (undecoded) date strings, directly from the PDF file. - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {string=} options.userPassword - User password (for encrypted files). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfInfo(file: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Extract single pages from a PDF file, - * and writes one PDF file for each page to outputPattern. - * This will not work if the file is encrypted. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string} outputPattern - Should contain %d (or any variant respecting printf format), - * since %d is replaced by the page number. - * As an example, `sample-%d.pdf` will produce `sample-1.pdf` for a single page document. - * @param {object=} options - Object containing options to pass to binary. - * @param {number=} options.firstPageToExtract - Specifies the first page to extract. - * This defaults to page 1. - * @param {number=} options.lastPageToExtract - Specifies the last page to extract. - * This defaults to the last page of the PDF file. - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfSeparate(file: string, outputPattern: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Converts a PDF file to PNG/JPEG/TIFF/PDF/PS/EPS/SVG. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string=} outputFile - Filepath of the file to output the results to. - * - * Can be set to `'-'` to write output to stdout. Using stdout is not valid with image formats - * unless `options.singleFile` is set to `true`. - * - * If not set then the output filename will be derived from the PDF file name. - * @param {object=} options - Object containing options to pass to binary. - * @param {('default'|'none'|'gray'|'subpixel'|'fast'|'good'|'best')=} options.antialias Set the cairo - * antialias option used for text and drawing in image files (or rasterized regions in vector output). - * @param {boolean=} options.cropBox - Uses the crop box rather than media box when - * generating the files (PNG/JPEG/TIFF only). - * @param {number=} options.cropHeight - Specifies the height of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropSize - Specifies the size of crop square in pixels - * (image output) or points (vector output). - * @param {number=} options.cropWidth - Specifies the width of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {boolean=} options.duplex - Adds the %%IncludeFeature: *Duplex DuplexNoTumble DSC - * comment to the PostScript file (PS only). This tells the print manager to enable duplexing. - * @param {boolean=} options.epsFile - Generate an EPS file. An EPS file contains a single image, - * so if you use this option with a multi-page PDF file, you must use `firstPageToConvert` and - * `lastPageToConvert` to specify a single page. - * The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used - * with this option. - * @param {boolean=} options.evenPagesOnly - Generates only the even numbered pages. - * @param {boolean=} options.fillPage - Expand PDF pages smaller than the paper to fill the - * paper (PS,PDF,SVG only). By default, these pages are not scaled. - * @param {number=} options.firstPageToConvert - Specifies the first page to convert. - * @param {boolean=} options.grayscaleFile - Generate grayscale file (PNG, JPEG, and TIFF only). - * @param {boolean=} options.iccFile - Use the specified ICC file as the output profile - * (PNG only). The profile will be embedded in the PNG file. - * @param {boolean=} options.jpegFile - Generate JPEG file(s). - * @param {number=} options.lastPageToConvert - Specifies the last page to convert. - * @param {boolean=} options.monochromeFile - Generate monochrome file (PNG and TIFF only). - * @param {boolean=} options.noCenter - By default, PDF pages smaller than the paper - * (after any scaling) are centered on the paper. This option causes them to be aligned to - * the lower-left corner of the paper instead (PS,PDF,SVG only). - * @param {boolean=} options.noCrop - By default, printing output is cropped to the CropBox - * specified in the PDF file. This option disables cropping (PS, PDF, SVG only). - * @param {boolean=} options.noShrink - Do not scale PDF pages which are larger than the paper - * (PS,PDF,SVG only). By default, pages larger than the paper are shrunk to fit. - * @param {boolean=} options.oddPagesOnly - Generates only the odd numbered pages. - * @param {boolean=} options.originalPageSizes - Set the paper size of each page to match - * the size specified in the PDF file. - * @param {string=} options.ownerPassword - Specify the owner password for the PDF file. - * Providing this will bypass all security restrictions. - * @param {number=} options.paperHeight - Set the paper height, in points (PS, PDF, SVG only). - * @param {('letter'|'legal'|'A4'|'A3'|'match')=} options.paperSize - Set the paper size to one of `letter`, `legal`, `A4`, - * or `A3` (PS,PDF,SVG only). This can also be set to `match`, which will set the paper size - * of each page to match the size specified in the PDF file. If none of the paperSize, - * paperWidth, or paperHeight options are specified the default is to match the paper size. - * @param {number=} options.paperWidth - Set the paper width, in points (PS,PDF,SVG only). - * @param {boolean=} options.pdfFile - Generate PDF file. - * @param {boolean=} options.pngFile - Generate PNG file(s). - * @param {boolean=} options.printVersionInfo - Print copyright and version information. - * @param {boolean=} options.psFile - Generate PS file. - * @param {boolean=} options.psLevel2 - Generate Level 2 PostScript (PS only). - * @param {boolean=} options.psLevel3 - Generate Level 3 PostScript (PS only). This enables all - * Level 2 features plus shading patterns and masked images. This is the default setting. - * @param {boolean=} options.quiet - Do not print any messages or errors. - * @param {number=} options.resolutionXAxis - Specifies the X resolution, in pixels per inch of - * image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per - * inch of image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.resolutionYAxis - Specifies the Y resolution, in pixels per inch of - * image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.scalePageTo - Scales the long side of each page (width for landscape - * pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will - * be determined by the aspect ratio of the page (PNG/JPEG/TIFF only). - * @param {number=} options.scalePageToXAxis - Scales each page horizontally to fit in scale-to-x - * pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of - * the page (PNG/JPEG/TIFF only). - * @param {number=} options.scalePageToYAxis - Scales each page vertically to fit in scale-to-y - * pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of - * the page (PNG/JPEG/TIFF only). - * @param {boolean=} options.singleFile - Writes only the first page and does not add digits. - * @param {boolean=} options.svgFile - Generate SVG (Scalable Vector Graphics) file. - * @param {('none'|'packbits'|'jpeg'|'lzw'|'deflate')=} options.tiffCompression - Set TIFF compression. - * @param {boolean=} options.tiffFile - Generate TIFF file(s). - * @param {boolean=} options.transparentPageColor - Use a transparent page color - * instead of white (PNG and TIFF only). - * @param {string=} options.userPassword - Specify the user password for the PDF file. - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfToCairo(file: string, outputFile?: string | undefined, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Converts a PDF file to HTML. - * Poppler will use the directory and name of the original file - * and append `-html` to the end of the filename. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.complexOutput - Generate complex output. - * @param {boolean=} options.exchangePdfLinks - Exchange .pdf links with .html. - * @param {boolean=} options.extractHidden - Force hidden text extraction. - * @param {number=} options.firstPageToConvert - First page to print. - * @param {boolean=} options.fontFullName - Outputs the font name without any substitutions. - * @param {boolean=} options.ignoreImages - Ignore images. - * @param {('PNG'|'JPG')=} options.imageFormat - Image file format for Splash output (PNG or JPG). - * If complexOutput is selected, but imageFormat is not specified, PNG will be assumed. - * @param {number=} options.lastPageToConvert - Last page to print. - * @param {boolean=} options.noDrm - Override document DRM settings. - * @param {boolean=} options.noFrames - Generate no frames. Not supported in complex output mode. - * @param {boolean=} options.noMergeParagraph - Do not merge paragraphs. - * @param {boolean=} options.noRoundedCoordinates - Do not round coordinates - * (with XML output only). - * @param {string=} options.outputEncoding - Sets the encoding to use for text output. - * This defaults to `UTF-8`. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {boolean=} options.quiet - Do not print any messages or errors. - * @param {boolean=} options.singlePage - generate single HTML that includes all pages. - * @param {boolean=} options.stdout - Use standard output. - * @param {string=} options.userPassword - User password (for encrypted files). - * @param {number=} options.wordBreakThreshold - Adjust the word break threshold percent. - * Default is 10. Word break occurs when distance between two adjacent characters is greater - * than this percent of character height. - * @param {boolean=} options.xmlOutput - Output for XML post-processing. - * @param {number=} options.zoom - Zoom the PDF document (default 1.5). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfToHtml(file: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format, - * grayscale image files in Portable Graymap (PGM) format, or monochrome image files - * in Portable Bitmap (PBM) format. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string} outputPath - Filepath to output the results to. - * @param {object=} options - Object containing options to pass to binary. - * @param {('yes'|'no')=} options.antialiasFonts - Enable or disable font anti-aliasing. - * This defaults to `yes`. - * @param {('yes'|'no')=} options.antialiasVectors - Enable or disable vector anti-aliasing. - * This defaults to `yes`. - * @param {boolean=} options.cropBox - Uses the crop box rather than media box when - * generating the files (PNG/JPEG/TIFF only). - * @param {number=} options.cropHeight - Specifies the height of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropSize - Specifies the size of crop square in pixels - * (image output) or points (vector output). - * @param {number=} options.cropWidth - Specifies the width of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {string=} options.displayProfile - If Poppler is compiled with colour management support, this option - * sets the display profile to the ICC profile stored in the display profile file passed. - * @param {boolean=} options.evenPagesOnly - Generates only the even numbered pages. - * @param {number=} options.firstPageToConvert - Specifies the first page to convert. - * @param {('yes'|'no')=} options.freetype - Enable or disable FreeType (a TrueType / Type 1 font rasterizer). - * This defaults to `yes`. - * @param {boolean=} options.grayscaleFile - Generate grayscale PGM file (instead of a color PPM file). - * @param {boolean=} options.jpegFile - Generate JPEG file instead a PPM file. - * @param {number=} options.lastPageToConvert - Specifies the last page to convert. - * @param {boolean=} options.monochromeFile - Generate monochrome PBM file (instead of a color PPM file). - * @param {boolean=} options.oddPagesOnly - Generates only the odd numbered pages. - * @param {string=} options.ownerPassword - Specify the owner password for the PDF file. - * Providing this will bypass all security restrictions. - * @param {boolean=} options.pngFile - Generate PNG file instead a PPM file. - * @param {boolean=} options.printVersionInfo - Print copyright and version information. - * @param {boolean=} options.quiet - Do not print any messages or errors. - * @param {number=} options.resolutionXAxis - Specifies the X resolution, in pixels per inch of - * image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per - * inch of image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.resolutionYAxis - Specifies the Y resolution, in pixels per inch of - * image files (or rasterized regions in vector output). The default is 150 PPI. - * @param {number=} options.scalePageTo - Scales the long side of each page (width for landscape - * pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will - * be determined by the aspect ratio of the page. - * @param {number=} options.scalePageToXAxis - Scales each page horizontally to fit in scale-to-x - * pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of - * the page. - * @param {number=} options.scalePageToYAxis - Scales each page vertically to fit in scale-to-y - * pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of - * the page. - * @param {boolean=} options.singleFile - Writes only the first page and does not add digits. - * @param {('none'|'solid'|'shape')=} options.thinLineMode - Specifies the thin line mode. This defaults to `none`. - * @param {('none'|'packbits'|'jpeg'|'lzw'|'deflate')=} options.tiffCompression - Set TIFF compression. - * @param {boolean=} options.tiffFile - Generate TIFF file instead a PPM file. - * @param {string=} options.userPassword - Specify the user password for the PDF file. - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfToPpm(file: string, outputPath: string, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Converts a PDF file to PostScript (PS). - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string=} outputFile - Filepath of the file to output the results to. - * Can be set to `'-'` to write output to stdout. - * @param {object=} options - Object containing options to pass to binary. - * @param {('yes'|'no')=} options.antialias - Enable anti-aliasing on rasterization, accepts `yes` or `no`. - * @param {boolean=} options.binary - Write binary data in Level 1 PostScript. By default, - * pdftops writes hex-encoded data in Level 1 PostScript. Binary data is non-standard in Level 1 - * PostScript but reduces the file size and can be useful when Level 1 PostScript is required - * only for its restricted use of PostScript operators. - * @param {boolean=} options.duplex - Set the Duplex pagedevice entry in the PostScript file. - * This tells duplex-capable printers to enable duplexing. - * @param {boolean=} options.epsFile - Generate an EPS file. An EPS file contains a single image, - * so if you use this option with a multi-page PDF file, you must use `firstPageToConvert` and - * `lastPageToConvert` to specify a single page. - * The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used - * with this option. - * @param {boolean=} options.fillPage - Expand PDF pages smaller than the paper to fill the - * paper. By default, these pages are not scaled. - * @param {number=} options.firstPageToConvert - Specifies the first page to convert. - * @param {number=} options.form - Generate PostScript form which can be imported by software - * that understands forms. - * A form contains a single page, so if you use this option with a multi-page PDF file, - * you must use `firstPageToConvert` and `lastPageToConvert` to specify a single page. - * The `level1` option cannot be used with `form`. - * No more than one of the mode options (`epsFile`, `form`) may be given. - * @param {number=} options.lastPageToConvert - Specifies the last page to convert. - * @param {boolean=} options.level1 - Generate Level 1 PostScript. The resulting PostScript - * files will be significantly larger (if they contain images), but will print on Level 1 printers. - * This also converts all images to black and white. - * @param {boolean=} options.level1Sep - Generate Level 1 separable PostScript. - * All colors are converted to CMYK. Images are written with separate stream data for the four components. - * @param {boolean=} options.level2 - Generate Level 2 PostScript. - * Level 2 supports color images and image compression. This is the default setting. - * @param {boolean=} options.level2Sep - Generate Level 2 separable PostScript. All colors are - * converted to CMYK. The PostScript separation convention operators are used to handle custom (spot) colors. - * @param {boolean=} options.level3 - Generate Level 3 PostScript. - * This enables all Level 2 featuresplus CID font embedding. - * @param {boolean=} options.level3Sep - Generate Level 3 separable PostScript. - * The separation handling is the same as for `level2Sep`. - * @param {boolean=} options.noEmbedCIDFonts - By default, any CID PostScript fonts which are - * embedded in the PDF file are copied into the PostScript file. This option disables that embedding. - * No attempt is made to substitute for non-embedded CID PostScript fonts. - * @param {boolean=} options.noEmbedCIDTrueTypeFonts - By default, any CID TrueType fonts which are - * embedded in the PDF file are copied into the PostScript file. This option disables that embedding. - * No attempt is made to substitute for non-embedded CID TrueType fonts. - * @param {boolean=} options.noEmbedTrueTypeFonts - By default, any TrueType fonts which are embedded - * in the PDF file are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead. - * Embedded fonts make PostScript files larger, but may be necessary for readable output. - * Also, some PostScript interpreters do not have TrueType rasterizers. - * @param {boolean=} options.noEmbedType1Fonts - By default, any Type 1 fonts which are embedded in the PDF file - * are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead. - * Embedded fonts make PostScript files larger, but may be necessary for readable output. - * @param {boolean=} options.noCenter - By default, PDF pages smaller than the paper - * (after any scaling) are centered on the paper. This option causes them to be aligned to - * the lower-left corner of the paper instead. - * @param {boolean=} options.noCrop - By default, printing output is cropped to the CropBox - * specified in the PDF file. This option disables cropping. - * @param {boolean=} options.noShrink - Do not scale PDF pages which are larger than the paper. - * By default, pages larger than the paper are shrunk to fit. - * @param {boolean=} options.opi - Generate OPI comments for all images and forms which have OPI information. - * @param {boolean=} options.optimizecolorspace - By default, bitmap images in the PDF pass through to the - * output PostScript in their original color space, which produces predictable results. - * This option converts RGB and CMYK images into Gray images if every pixel of the image has equal components. - * This can fix problems when doing color separations of PDFs that contain embedded black and - * white images encoded as RGB. - * @param {boolean=} options.originalPageSizes - Set the paper size of each page to match - * the size specified in the PDF file. - * @param {boolean=} options.overprint - Enable overprinting. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {number=} options.paperHeight - Set the paper height, in points. - * @param {('letter'|'legal'|'A4'|'A3'|'match')=} options.paperSize - Set the paper size to one of `letter`, `legal`, `A4`, - * or `A3`. This can also be set to `match`, which will set the paper size - * of each page to match the size specified in the PDF file. If none of the paperSize, - * paperWidth, or paperHeight options are specified the default is to match the paper size. - * @param {number=} options.paperWidth - Set the paper width, in points. - * @param {boolean=} options.passfonts - By default, references to non-embedded 8-bit fonts - * in the PDF file are substituted with the closest `Helvetica`, `Times-Roman`, or `Courier` font. - * This option passes references to non-embedded fonts through to the PostScript file. - * @param {boolean=} options.preload - Preload images and forms. - * @param {boolean=} options.printVersionInfo - Print copyright and version information. - * @param {boolean=} options.quiet - Do not print any messages or errors. - * @param {('always'|'never'|'whenneeded')=} options.rasterize - By default, pdfToPs rasterizes pages as needed, - * for example, if they contain transparencies. To force rasterization, set `rasterize` to `always`. - * Use this to eliminate fonts. - * To prevent rasterization, set `rasterize` to `never`. - * This may produce files that display incorrectly. - * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per - * inch of image files (or rasterized regions in vector output). The default is 300 PPI. - * @param {string=} options.userPassword - User password (for encrypted files). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfToPs(file: string, outputFile?: string | undefined, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Converts a PDF file to TXT. - * - * @param {string} file - Filepath of the PDF file to read. - * @param {string=} outputFile - Filepath of the file to output the results to. - * Can be set to `'-'` to write output to stdout. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.boundingBoxXhtml - Generate an XHTML file containing bounding - * box information for each word in the file. - * @param {boolean=} options.boundingBoxXhtmlLayout - Generate an XHTML file containing - * bounding box information for each block, line, and word in the file. - * @param {number=} options.cropHeight - Specifies the height of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropWidth - Specifies the width of crop area in pixels - * (image output) or points (vector output). - * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left - * corner in pixels (image output) or points (vector output). - * @param {('unix'|'dos'|'mac')=} options.eolConvention - Sets the end-of-line convention to use for - * text output: unix; dos; mac. - * @param {number=} options.firstPageToConvert - Specifies the first page to convert. - * @param {number=} options.fixedWidthLayout - Assume fixed-pitch (or tabular) text, with the - * specified character width (in points). This forces physical layout mode. - * @param {boolean=} options.generateHtmlMetaFile Generate simple HTML file, including the - * meta information. This simply wraps the text in `
` and `
` and prepends the meta headers. - * @param {number=} options.lastPageToConvert - Specifies the last page to convert. - * @param {boolean=} options.listEncodingOptions - List the available encodings. - * @param {boolean=} options.maintainLayout - Maintain (as best as possible) the original physical - * layout of the text. The default is to undo physical layout (columns, hyphenation, etc.) and - * output the text in reading order. - * @param {boolean=} options.noDiagonalText - Discard diagonal text. - * @param {boolean=} options.noPageBreaks - Do not insert page breaks (form feed characters) - * between pages. - * @param {string=} options.outputEncoding - Sets the encoding to use for text output. - * This defaults to `UTF-8`. - * @param {string=} options.ownerPassword - Owner password (for encrypted files). - * @param {boolean=} options.printVersionInfo - Print copyright and version information. - * @param {boolean=} options.quiet - Do not print any messages or errors. - * @param {boolean=} options.rawLayout - Keep the text in content stream order. This is a - * hack which often undoes column formatting, etc. Use of raw mode is no longer recommended. - * @param {string=} options.userPassword - User password (for encrypted files). - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfToText(file: string, outputFile?: string | undefined, options?: object | undefined): Promise; - /** - * @author Frazer Smith - * @description Merges several PDF files in order of their occurrence in the files array to - * one PDF result file. - * - * @param {Array} files - Filepaths of the PDF files to merge. - * An entire directory of PDF files can be merged like so: `path/to/directory/*.pdf`. - * @param {string} outputFile - Filepath of the file to output the resulting merged PDF to. - * @param {object=} options - Object containing options to pass to binary. - * @param {boolean=} options.printVersionInfo - Print copyright and version information. - * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. - */ - pdfUnite(files: any[], outputFile: string, options?: object | undefined): Promise; -} +export class Poppler { + /** + * @param {string=} binPath - Path of poppler-utils binaries. + * Useful for Linux users who have poppler-utils binaries already installed. + */ + constructor(binPath?: string | undefined); + popplerPath: string; + /** + * @author Frazer Smith + * @description Embeds files (attachments) into a PDF file. + * @param {string} file - Filepath of the PDF file to read. + * @param {string} fileToAttach - Filepath of the attachment to be embedded into the PDF file. + * @param {string} outputFile - Filepath of the file to output the results to. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {boolean=} options.replace - Replace embedded file with same name (if it exists). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfAttach( + file: string, + fileToAttach: string, + outputFile: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Lists or extracts embedded files (attachments) from a PDF file. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.listEmbedded - List all of the embedded files in the PDF file. + * File names are converted to the text encoding specified by the `outputEncoding` option. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {string=} options.outputEncoding - Sets the encoding to use for text output. + * This defaults to `UTF-8`. + * @param {string=} options.outputPath - Set the file name used when saving an embedded file with + * the save option enabled, or the directory if the `saveall` option is used. + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {boolean=} options.saveAllFiles - Save all of the embedded files. This uses the file + * names associated with the embedded files (as printed by the `listEmbedded` option). + * By default, the files are saved in the current directory; this can be changed + * with the `outputPath` option. + * @param {string=} options.saveFile - Save the specified embedded file. + * By default, this uses the file name associated with the embedded file (as printed by the + * `listEmbedded` option); the file name can be changed with the `outputPath` option. + * @param {number=} options.saveSpecificFile - Save the specified embedded file. + * By default, this uses the file name associated with the embedded file (as printed by the + * `listEmbedded` option); the file name can be changed with the `outputPath` option. + * @param {string=} options.userPassword - User password (for encrypted files). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfDetach( + file: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Lists the fonts used in a PDF file along with various information for each font. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {object=} options - Object containing options to pass to binary. + * @param {number=} options.firstPageToExamine - Specifies the first page to examine. + * @param {number=} options.lastPageToExamine - Specifies the last page to examine. + * @param {boolean=} options.listSubstitutes - List the substitute fonts that poppler + * will use for non-embedded fonts. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {string=} options.userPassword - User password (for encrypted files). * + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfFonts( + file: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 files. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string} outputPrefix - Filename prefix of output files. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.allFiles - Write JPEG, JPEG2000, JBIG2, and CCITT images in their native format. + * CMYK files are written as TIFF files. All other images are written as PNG files. + * @param {boolean=} options.ccittFile - Generate CCITT images as CCITT files. + * @param {number=} options.firstPageToConvert - Specifies the first page to convert. + * @param {number=} options.lastPageToConvert - Specifies the last page to convert. + * @param {boolean=} options.list - Instead of writing the images, list the + * images along with various information for each image. + * NOTE: Do not specify the outputPrefix with this option. + * @param {boolean=} options.jbig2File - Generate JBIG2 images as JBIG2 files. + * @param {boolean=} options.jpeg2000File - Generate JPEG2000 images at JP2 files. + * @param {boolean=} options.jpegFile - Generate JPEG images as JPEG files. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {boolean=} options.pngFile - Change the default output format to PNG. + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {boolean=} options.tiffFile - Change the default output format to TIFF. + * @param {string=} options.userPassword - Specify the user password for the PDF file. + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfImages( + file: string, + outputPrefix: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Prints the contents of the `Info` dictionary from a PDF file. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {object=} options - Object containing options to pass to binary. + * @param {number=} options.firstPageToConvert - First page to print. + * @param {number=} options.lastPageToConvert - Last page to print. + * @param {boolean=} options.listEncodingOptions - List the available encodings. + * @param {string=} options.outputEncoding - Sets the encoding to use for text output. + * This defaults to `UTF-8`. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {boolean=} options.printBoundingBoxes - Prints the page box bounding boxes: + * MediaBox, CropBox, BleedBox, TrimBox, and ArtBox. + * @param {boolean=} options.printDocStruct - Prints the logical document structure + * of a Tagged-PDF file. + * @param {boolean=} options.printDocStructText - Print the textual content along with the + * document structure of a Tagged-PDF file. Note that extracting text this way might be slow + * + * for big PDF files. + * @param {boolean=} options.printIsoDates - Prints dates in ISO-8601 format (including the time zone). + * @param {boolean=} options.printJS - Prints all JavaScript in the PDF file. + * @param {boolean=} options.printMetadata - Prints document-level metadata. (This is the `Metadata` + * stream from the PDF file's Catalog object). + * @param {boolean=} options.printNamedDests - Print a list of all named destinations. If a page range + * is specified using the `firstPageToConvert` and `lastPageToConvert` options, only destinations + * in the page range are listed. + * @param {boolean=} options.printRawDates - Prints the raw (undecoded) date strings, directly from the PDF file. + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {string=} options.userPassword - User password (for encrypted files). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfInfo( + file: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Extract single pages from a PDF file, + * and writes one PDF file for each page to outputPattern. + * This will not work if the file is encrypted. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string} outputPattern - Should contain %d (or any variant respecting printf format), + * since %d is replaced by the page number. + * As an example, `sample-%d.pdf` will produce `sample-1.pdf` for a single page document. + * @param {object=} options - Object containing options to pass to binary. + * @param {number=} options.firstPageToExtract - Specifies the first page to extract. + * This defaults to page 1. + * @param {number=} options.lastPageToExtract - Specifies the last page to extract. + * This defaults to the last page of the PDF file. + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfSeparate( + file: string, + outputPattern: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Converts a PDF file to PNG/JPEG/TIFF/PDF/PS/EPS/SVG. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string=} outputFile - Filepath of the file to output the results to. + * + * If `undefined` then will write output to stdout. Using stdout is not valid with image formats + * unless `options.singleFile` is set to `true`. + * + * If not set then the output filename will be derived from the PDF file name. + * @param {object=} options - Object containing options to pass to binary. + * @param {('default'|'none'|'gray'|'subpixel'|'fast'|'good'|'best')=} options.antialias Set the cairo + * antialias option used for text and drawing in image files (or rasterized regions in vector output). + * @param {boolean=} options.cropBox - Uses the crop box rather than media box when + * generating the files (PNG/JPEG/TIFF only). + * @param {number=} options.cropHeight - Specifies the height of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropSize - Specifies the size of crop square in pixels + * (image output) or points (vector output). + * @param {number=} options.cropWidth - Specifies the width of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {boolean=} options.duplex - Adds the %%IncludeFeature: *Duplex DuplexNoTumble DSC + * comment to the PostScript file (PS only). This tells the print manager to enable duplexing. + * @param {boolean=} options.epsFile - Generate an EPS file. An EPS file contains a single image, + * so if you use this option with a multi-page PDF file, you must use `firstPageToConvert` and + * `lastPageToConvert` to specify a single page. + * The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used + * with this option. + * @param {boolean=} options.evenPagesOnly - Generates only the even numbered pages. + * @param {boolean=} options.fillPage - Expand PDF pages smaller than the paper to fill the + * paper (PS,PDF,SVG only). By default, these pages are not scaled. + * @param {number=} options.firstPageToConvert - Specifies the first page to convert. + * @param {boolean=} options.grayscaleFile - Generate grayscale file (PNG, JPEG, and TIFF only). + * @param {boolean=} options.iccFile - Use the specified ICC file as the output profile + * (PNG only). The profile will be embedded in the PNG file. + * @param {boolean=} options.jpegFile - Generate JPEG file(s). + * @param {number=} options.lastPageToConvert - Specifies the last page to convert. + * @param {boolean=} options.monochromeFile - Generate monochrome file (PNG and TIFF only). + * @param {boolean=} options.noCenter - By default, PDF pages smaller than the paper + * (after any scaling) are centered on the paper. This option causes them to be aligned to + * the lower-left corner of the paper instead (PS,PDF,SVG only). + * @param {boolean=} options.noCrop - By default, printing output is cropped to the CropBox + * specified in the PDF file. This option disables cropping (PS, PDF, SVG only). + * @param {boolean=} options.noShrink - Do not scale PDF pages which are larger than the paper + * (PS,PDF,SVG only). By default, pages larger than the paper are shrunk to fit. + * @param {boolean=} options.oddPagesOnly - Generates only the odd numbered pages. + * @param {boolean=} options.originalPageSizes - Set the paper size of each page to match + * the size specified in the PDF file. + * @param {string=} options.ownerPassword - Specify the owner password for the PDF file. + * Providing this will bypass all security restrictions. + * @param {number=} options.paperHeight - Set the paper height, in points (PS, PDF, SVG only). + * @param {('letter'|'legal'|'A4'|'A3'|'match')=} options.paperSize - Set the paper size to one of `letter`, `legal`, `A4`, + * or `A3` (PS,PDF,SVG only). This can also be set to `match`, which will set the paper size + * of each page to match the size specified in the PDF file. If none of the paperSize, + * paperWidth, or paperHeight options are specified the default is to match the paper size. + * @param {number=} options.paperWidth - Set the paper width, in points (PS,PDF,SVG only). + * @param {boolean=} options.pdfFile - Generate PDF file. + * @param {boolean=} options.pngFile - Generate PNG file(s). + * @param {boolean=} options.printVersionInfo - Print copyright and version information. + * @param {boolean=} options.psFile - Generate PS file. + * @param {boolean=} options.psLevel2 - Generate Level 2 PostScript (PS only). + * @param {boolean=} options.psLevel3 - Generate Level 3 PostScript (PS only). This enables all + * Level 2 features plus shading patterns and masked images. This is the default setting. + * @param {boolean=} options.quiet - Do not print any messages or errors. + * @param {number=} options.resolutionXAxis - Specifies the X resolution, in pixels per inch of + * image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per + * inch of image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.resolutionYAxis - Specifies the Y resolution, in pixels per inch of + * image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.scalePageTo - Scales the long side of each page (width for landscape + * pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will + * be determined by the aspect ratio of the page (PNG/JPEG/TIFF only). + * @param {number=} options.scalePageToXAxis - Scales each page horizontally to fit in scale-to-x + * pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of + * the page (PNG/JPEG/TIFF only). + * @param {number=} options.scalePageToYAxis - Scales each page vertically to fit in scale-to-y + * pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of + * the page (PNG/JPEG/TIFF only). + * @param {boolean=} options.singleFile - Writes only the first page and does not add digits. + * @param {boolean=} options.svgFile - Generate SVG (Scalable Vector Graphics) file. + * @param {('none'|'packbits'|'jpeg'|'lzw'|'deflate')=} options.tiffCompression - Set TIFF compression. + * @param {boolean=} options.tiffFile - Generate TIFF file(s). + * @param {boolean=} options.transparentPageColor - Use a transparent page color + * instead of white (PNG and TIFF only). + * @param {string=} options.userPassword - Specify the user password for the PDF file. + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfToCairo( + file: string, + outputFile?: string | undefined, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Converts a PDF file to HTML. + * Poppler will use the directory and name of the original file + * and append `-html` to the end of the filename. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.complexOutput - Generate complex output. + * @param {boolean=} options.exchangePdfLinks - Exchange .pdf links with .html. + * @param {boolean=} options.extractHidden - Force hidden text extraction. + * @param {number=} options.firstPageToConvert - First page to print. + * @param {boolean=} options.fontFullName - Outputs the font name without any substitutions. + * @param {boolean=} options.ignoreImages - Ignore images. + * @param {('PNG'|'JPG')=} options.imageFormat - Image file format for Splash output (PNG or JPG). + * If complexOutput is selected, but imageFormat is not specified, PNG will be assumed. + * @param {number=} options.lastPageToConvert - Last page to print. + * @param {boolean=} options.noDrm - Override document DRM settings. + * @param {boolean=} options.noFrames - Generate no frames. Not supported in complex output mode. + * @param {boolean=} options.noMergeParagraph - Do not merge paragraphs. + * @param {boolean=} options.noRoundedCoordinates - Do not round coordinates + * (with XML output only). + * @param {string=} options.outputEncoding - Sets the encoding to use for text output. + * This defaults to `UTF-8`. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {boolean=} options.printVersionInfo - Print copyright and version info. + * @param {boolean=} options.quiet - Do not print any messages or errors. + * @param {boolean=} options.singlePage - generate single HTML that includes all pages. + * @param {boolean=} options.stdout - Use standard output. + * @param {string=} options.userPassword - User password (for encrypted files). + * @param {number=} options.wordBreakThreshold - Adjust the word break threshold percent. + * Default is 10. Word break occurs when distance between two adjacent characters is greater + * than this percent of character height. + * @param {boolean=} options.xmlOutput - Output for XML post-processing. + * @param {number=} options.zoom - Zoom the PDF document (default 1.5). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfToHtml( + file: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Converts a PDF file to colour image files in Portable Pixmap (PPM) format, + * grayscale image files in Portable Graymap (PGM) format, or monochrome image files + * in Portable Bitmap (PBM) format. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string} outputPath - Filepath to output the results to. + * @param {object=} options - Object containing options to pass to binary. + * @param {('yes'|'no')=} options.antialiasFonts - Enable or disable font anti-aliasing. + * This defaults to `yes`. + * @param {('yes'|'no')=} options.antialiasVectors - Enable or disable vector anti-aliasing. + * This defaults to `yes`. + * @param {boolean=} options.cropBox - Uses the crop box rather than media box when + * generating the files (PNG/JPEG/TIFF only). + * @param {number=} options.cropHeight - Specifies the height of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropSize - Specifies the size of crop square in pixels + * (image output) or points (vector output). + * @param {number=} options.cropWidth - Specifies the width of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {string=} options.displayProfile - If Poppler is compiled with colour management support, this option + * sets the display profile to the ICC profile stored in the display profile file passed. + * @param {boolean=} options.evenPagesOnly - Generates only the even numbered pages. + * @param {number=} options.firstPageToConvert - Specifies the first page to convert. + * @param {('yes'|'no')=} options.freetype - Enable or disable FreeType (a TrueType / Type 1 font rasterizer). + * This defaults to `yes`. + * @param {boolean=} options.grayscaleFile - Generate grayscale PGM file (instead of a color PPM file). + * @param {boolean=} options.jpegFile - Generate JPEG file instead a PPM file. + * @param {number=} options.lastPageToConvert - Specifies the last page to convert. + * @param {boolean=} options.monochromeFile - Generate monochrome PBM file (instead of a color PPM file). + * @param {boolean=} options.oddPagesOnly - Generates only the odd numbered pages. + * @param {string=} options.ownerPassword - Specify the owner password for the PDF file. + * Providing this will bypass all security restrictions. + * @param {boolean=} options.pngFile - Generate PNG file instead a PPM file. + * @param {boolean=} options.printVersionInfo - Print copyright and version information. + * @param {boolean=} options.quiet - Do not print any messages or errors. + * @param {number=} options.resolutionXAxis - Specifies the X resolution, in pixels per inch of + * image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per + * inch of image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.resolutionYAxis - Specifies the Y resolution, in pixels per inch of + * image files (or rasterized regions in vector output). The default is 150 PPI. + * @param {number=} options.scalePageTo - Scales the long side of each page (width for landscape + * pages, height for portrait pages) to fit in scale-to pixels. The size of the short side will + * be determined by the aspect ratio of the page. + * @param {number=} options.scalePageToXAxis - Scales each page horizontally to fit in scale-to-x + * pixels. If scale-to-y is set to -1, the vertical size will determined by the aspect ratio of + * the page. + * @param {number=} options.scalePageToYAxis - Scales each page vertically to fit in scale-to-y + * pixels. If scale-to-x is set to -1, the horizontal size will determined by the aspect ratio of + * the page. + * @param {boolean=} options.singleFile - Writes only the first page and does not add digits. + * @param {('none'|'solid'|'shape')=} options.thinLineMode - Specifies the thin line mode. This defaults to `none`. + * @param {('none'|'packbits'|'jpeg'|'lzw'|'deflate')=} options.tiffCompression - Set TIFF compression. + * @param {boolean=} options.tiffFile - Generate TIFF file instead a PPM file. + * @param {string=} options.userPassword - Specify the user password for the PDF file. + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfToPpm( + file: string, + outputPath: string, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Converts a PDF file to PostScript (PS). + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string=} outputFile - Filepath of the file to output the results to. + * If `undefined` then will write output to stdout. + * @param {object=} options - Object containing options to pass to binary. + * @param {('yes'|'no')=} options.antialias - Enable anti-aliasing on rasterization, accepts `yes` or `no`. + * @param {boolean=} options.binary - Write binary data in Level 1 PostScript. By default, + * pdftops writes hex-encoded data in Level 1 PostScript. Binary data is non-standard in Level 1 + * PostScript but reduces the file size and can be useful when Level 1 PostScript is required + * only for its restricted use of PostScript operators. + * @param {boolean=} options.duplex - Set the Duplex pagedevice entry in the PostScript file. + * This tells duplex-capable printers to enable duplexing. + * @param {boolean=} options.epsFile - Generate an EPS file. An EPS file contains a single image, + * so if you use this option with a multi-page PDF file, you must use `firstPageToConvert` and + * `lastPageToConvert` to specify a single page. + * The page size options (originalPageSizes, paperSize, paperWidth, paperHeight) can not be used + * with this option. + * @param {boolean=} options.fillPage - Expand PDF pages smaller than the paper to fill the + * paper. By default, these pages are not scaled. + * @param {number=} options.firstPageToConvert - Specifies the first page to convert. + * @param {number=} options.form - Generate PostScript form which can be imported by software + * that understands forms. + * A form contains a single page, so if you use this option with a multi-page PDF file, + * you must use `firstPageToConvert` and `lastPageToConvert` to specify a single page. + * The `level1` option cannot be used with `form`. + * No more than one of the mode options (`epsFile`, `form`) may be given. + * @param {number=} options.lastPageToConvert - Specifies the last page to convert. + * @param {boolean=} options.level1 - Generate Level 1 PostScript. The resulting PostScript + * files will be significantly larger (if they contain images), but will print on Level 1 printers. + * This also converts all images to black and white. + * @param {boolean=} options.level1Sep - Generate Level 1 separable PostScript. + * All colors are converted to CMYK. Images are written with separate stream data for the four components. + * @param {boolean=} options.level2 - Generate Level 2 PostScript. + * Level 2 supports color images and image compression. This is the default setting. + * @param {boolean=} options.level2Sep - Generate Level 2 separable PostScript. All colors are + * converted to CMYK. The PostScript separation convention operators are used to handle custom (spot) colors. + * @param {boolean=} options.level3 - Generate Level 3 PostScript. + * This enables all Level 2 featuresplus CID font embedding. + * @param {boolean=} options.level3Sep - Generate Level 3 separable PostScript. + * The separation handling is the same as for `level2Sep`. + * @param {boolean=} options.noEmbedCIDFonts - By default, any CID PostScript fonts which are + * embedded in the PDF file are copied into the PostScript file. This option disables that embedding. + * No attempt is made to substitute for non-embedded CID PostScript fonts. + * @param {boolean=} options.noEmbedCIDTrueTypeFonts - By default, any CID TrueType fonts which are + * embedded in the PDF file are copied into the PostScript file. This option disables that embedding. + * No attempt is made to substitute for non-embedded CID TrueType fonts. + * @param {boolean=} options.noEmbedTrueTypeFonts - By default, any TrueType fonts which are embedded + * in the PDF file are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead. + * Embedded fonts make PostScript files larger, but may be necessary for readable output. + * Also, some PostScript interpreters do not have TrueType rasterizers. + * @param {boolean=} options.noEmbedType1Fonts - By default, any Type 1 fonts which are embedded in the PDF file + * are copied into the PostScript file. This option causes pdfToPs to substitute base fonts instead. + * Embedded fonts make PostScript files larger, but may be necessary for readable output. + * @param {boolean=} options.noCenter - By default, PDF pages smaller than the paper + * (after any scaling) are centered on the paper. This option causes them to be aligned to + * the lower-left corner of the paper instead. + * @param {boolean=} options.noCrop - By default, printing output is cropped to the CropBox + * specified in the PDF file. This option disables cropping. + * @param {boolean=} options.noShrink - Do not scale PDF pages which are larger than the paper. + * By default, pages larger than the paper are shrunk to fit. + * @param {boolean=} options.opi - Generate OPI comments for all images and forms which have OPI information. + * @param {boolean=} options.optimizecolorspace - By default, bitmap images in the PDF pass through to the + * output PostScript in their original color space, which produces predictable results. + * This option converts RGB and CMYK images into Gray images if every pixel of the image has equal components. + * This can fix problems when doing color separations of PDFs that contain embedded black and + * white images encoded as RGB. + * @param {boolean=} options.originalPageSizes - Set the paper size of each page to match + * the size specified in the PDF file. + * @param {boolean=} options.overprint - Enable overprinting. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {number=} options.paperHeight - Set the paper height, in points. + * @param {('letter'|'legal'|'A4'|'A3'|'match')=} options.paperSize - Set the paper size to one of `letter`, `legal`, `A4`, + * or `A3`. This can also be set to `match`, which will set the paper size + * of each page to match the size specified in the PDF file. If none of the paperSize, + * paperWidth, or paperHeight options are specified the default is to match the paper size. + * @param {number=} options.paperWidth - Set the paper width, in points. + * @param {boolean=} options.passfonts - By default, references to non-embedded 8-bit fonts + * in the PDF file are substituted with the closest `Helvetica`, `Times-Roman`, or `Courier` font. + * This option passes references to non-embedded fonts through to the PostScript file. + * @param {boolean=} options.preload - Preload images and forms. + * @param {boolean=} options.printVersionInfo - Print copyright and version information. + * @param {boolean=} options.quiet - Do not print any messages or errors. + * @param {('always'|'never'|'whenneeded')=} options.rasterize - By default, pdfToPs rasterizes pages as needed, + * for example, if they contain transparencies. To force rasterization, set `rasterize` to `always`. + * Use this to eliminate fonts. + * To prevent rasterization, set `rasterize` to `never`. + * This may produce files that display incorrectly. + * @param {number=} options.resolutionXYAxis - Specifies the X and Y resolution, in pixels per + * inch of image files (or rasterized regions in vector output). The default is 300 PPI. + * @param {string=} options.userPassword - User password (for encrypted files). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfToPs( + file: string, + outputFile?: string | undefined, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Converts a PDF file to TXT. + * + * @param {string} file - Filepath of the PDF file to read. + * @param {string=} outputFile - Filepath of the file to output the results to. + * If `undefined` then will write output to stdout. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.boundingBoxXhtml - Generate an XHTML file containing bounding + * box information for each word in the file. + * @param {boolean=} options.boundingBoxXhtmlLayout - Generate an XHTML file containing + * bounding box information for each block, line, and word in the file. + * @param {number=} options.cropHeight - Specifies the height of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropWidth - Specifies the width of crop area in pixels + * (image output) or points (vector output). + * @param {number=} options.cropXAxis - Specifies the x-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {number=} options.cropYAxis - Specifies the y-coordinate of the crop area top left + * corner in pixels (image output) or points (vector output). + * @param {('unix'|'dos'|'mac')=} options.eolConvention - Sets the end-of-line convention to use for + * text output: unix; dos; mac. + * @param {number=} options.firstPageToConvert - Specifies the first page to convert. + * @param {number=} options.fixedWidthLayout - Assume fixed-pitch (or tabular) text, with the + * specified character width (in points). This forces physical layout mode. + * @param {boolean=} options.generateHtmlMetaFile Generate simple HTML file, including the + * meta information. This simply wraps the text in `
` and `
` and prepends the meta headers. + * @param {number=} options.lastPageToConvert - Specifies the last page to convert. + * @param {boolean=} options.listEncodingOptions - List the available encodings. + * @param {boolean=} options.maintainLayout - Maintain (as best as possible) the original physical + * layout of the text. The default is to undo physical layout (columns, hyphenation, etc.) and + * output the text in reading order. + * @param {boolean=} options.noDiagonalText - Discard diagonal text. + * @param {boolean=} options.noPageBreaks - Do not insert page breaks (form feed characters) + * between pages. + * @param {string=} options.outputEncoding - Sets the encoding to use for text output. + * This defaults to `UTF-8`. + * @param {string=} options.ownerPassword - Owner password (for encrypted files). + * @param {boolean=} options.printVersionInfo - Print copyright and version information. + * @param {boolean=} options.quiet - Do not print any messages or errors. + * @param {boolean=} options.rawLayout - Keep the text in content stream order. This is a + * hack which often undoes column formatting, etc. Use of raw mode is no longer recommended. + * @param {string=} options.userPassword - User password (for encrypted files). + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfToText( + file: string, + outputFile?: string | undefined, + options?: object | undefined + ): Promise; + /** + * @author Frazer Smith + * @description Merges several PDF files in order of their occurrence in the files array to + * one PDF result file. + * + * @param {Array} files - Filepaths of the PDF files to merge. + * An entire directory of PDF files can be merged like so: `path/to/directory/*.pdf`. + * @param {string} outputFile - Filepath of the file to output the resulting merged PDF to. + * @param {object=} options - Object containing options to pass to binary. + * @param {boolean=} options.printVersionInfo - Print copyright and version information. + * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. + */ + pdfUnite( + files: any[], + outputFile: string, + options?: object | undefined + ): Promise; +} diff --git a/src/index.js b/src/index.js index cac1c1eb..41b15f71 100644 --- a/src/index.js +++ b/src/index.js @@ -183,7 +183,7 @@ class Poppler { * will use for non-embedded fonts. * @param {string=} options.ownerPassword - Owner password (for encrypted files). * @param {boolean=} options.printVersionInfo - Print copyright and version info. - * @param {string=} options.userPassword - User password (for encrypted files). * + * @param {string=} options.userPassword - User password (for encrypted files). * * @returns {Promise} Promise of stdout string on resolve, or Error object on rejection. */ async pdfFonts(file, options = {}) { diff --git a/src/index.test.js b/src/index.test.js index 799f9c12..24b5613b 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -113,11 +113,13 @@ describe('pdfAttach function', () => { replace: 'test' }; - await poppler.pdfAttach(file, undefined, undefined, options).catch((err) => { - expect(err.message).toEqual( - "Invalid value type provided for option 'replace', expected boolean but recieved string" - ); - }); + await poppler + .pdfAttach(file, undefined, undefined, options) + .catch((err) => { + expect(err.message).toEqual( + "Invalid value type provided for option 'replace', expected boolean but recieved string" + ); + }); }); test('Should return an Error object if invalid option is passed to function', async () => { @@ -126,9 +128,13 @@ describe('pdfAttach function', () => { wordFile: 'test' }; - await poppler.pdfAttach(file, undefined, undefined, options).catch((err) => { - expect(err.message).toEqual("Invalid option provided 'wordFile'"); - }); + await poppler + .pdfAttach(file, undefined, undefined, options) + .catch((err) => { + expect(err.message).toEqual( + "Invalid option provided 'wordFile'" + ); + }); }); });