1.2.0 • Published 1 year ago

node-pdftocairo v1.2.0

Weekly downloads
59
License
MIT
Repository
github
Last release
1 year ago

node-pdftocairo

Build Status Codecov npm MIT

Node.js wrapper for pdftocairo - PDF to PNG/JPEG/TIFF/PDF/PS/EPS/SVG using cairo
Inspired by jjwilly16/node-pdftk

Requirements

Since pdftocairo is included in Poppler, you should install Poppler before using this library.

Installation

yarn add node-pdftocairo
import { input } from 'node-pdftocairo';

API

Simple Usage

The first argument of input can be a file path or buffer.
If you pass a output file path to output, it will generate files and returns Promise<null>; otherwise return buffers without generating files.

Generate file buffer(s) from a PDF file

const inputPath = path.join(__dirname, '../test/files/sample.pdf');
const options = { format: 'png' };
const outputBuffer = await input(inputPath, options).output();

Generate file buffer(s) from the buffer

const inputPath = path.join(__dirname, '../test/files/sample.pdf');
const buffer = fs.readFileSync(inputPath);
const options = { format: 'png' };
const outputBuffer = await input(buffer, options).output();

Generate file(s) on the specified output path

const inputPath = path.join(__dirname, '../test/files/sample.pdf');
const outputPath = path.join(__dirname, '../test/files/sample-img');
const options = { format: 'png' };
await input(inputPath, options).output(outputPath);

Options

Reference: Ubuntu Manpage: pdftocairo

PropertyDescriptionTypeDefault
binspecify the path of pdftocairostring-
formatoutput file format, should be one of png jpeg tiff ps eps pdf svgstring-
antialiasSet the cairo antialias option used for text and drawing in image files (or rasterized regions in vector output), should be one of default none gray subpixel fast good beststring-
rangeSpecifies the first/last page to convert.{ f?: number, l?: number }-
filterGenerates only the odd or even numbered pages.string-
singlefileWrites only the first page and does not add digits.booleanfalse
resolutionSpecifies the X and Y resolution, in pixels per inch of image files (or rasterized regions in vector output). The default is 150 PPI.number | { x: number, y: number }-
scaleScales 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).number | { x: number, y: number }-
cropSpecifies the x-coordinate/y-coordinate of the crop area top left corner in pixels (image output) or points (vector output) and Specifies the width/height/size of crop area in pixels (image output) or points (vector output) (default is 0){ x?: number, y?: number, W?: number, H?: number, sz?: number }-
cropboxUses the crop box rather than media box when generating the files (PNG/JPEG/TIFF only)booleanfalse
monoGenerate a monochrome file (PNG and TIFF only).booleanfalse
grayGenerate a grayscale file (PNG, JPEG, and TIFF only).booleanfalse
transparentUse a transparent page color instead of white (PNG and TIFF only).booleanfalse
level2Generate Level 2 PostScript (PS only).booleanfalse
level3Generate Level 3 PostScript (PS only). This enables all Level 2 features plus shading patterns and masked images. This is the default setting.booleanfalse
originPageSizesThis option is the same as "-paper match".booleanfalse
iccUse the specified ICC file as the output profile (PNG only). The profile will be embedded in the PNG file.string-
jpegoptWhen used with -jpeg, takes a list of options to control the jpeg compression. See JPEG OPTIONS for the available options.string-
paperSet 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 the -paper, -paperw, or -paperh options are specified the default is to match the paper size.string | { w: number, h: number }-
nocropBy default, printing output is cropped to the CropBox specified in the PDF file. This option disables cropping (PS,PDF,SVG only).booleanfalse
expandExpand PDF pages smaller than the paper to fill the paper (PS,PDF,SVG only). By default, these pages are not scaled.booleanfalse
noshrinkDon't scale PDF pages which are larger than the paper (PS,PDF,SVG only). By default, pages larger than the paper are shrunk to fit.booleanfalse
nocenterBy 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).booleanfalse
duplexAdds the %%IncludeFeature: *Duplex DuplexNoTumble DSC comment to the PostScript file (PS only). This tells the print manager to enable duplexing.booleanfalse
ownerPasswordSpecify the owner password for the PDF file. Providing this will bypass all security restrictions.string-
userPasswordSpecify the user password for the PDF file.string-