Skip to content

Commit

Permalink
Merge pull request #566 from Fdawgs/build/deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs authored Feb 23, 2024
2 parents 7108895 + 07fc431 commit a211e58
Show file tree
Hide file tree
Showing 322 changed files with 74 additions and 117 deletions.
8 changes: 4 additions & 4 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ Lists or extracts embedded files (attachments) from a PDF file.
| file | <code>string</code> | Filepath of the PDF file to read. |
| [options] | <code>object</code> | Object containing options to pass to binary. |
| [options.listEmbedded] | <code>boolean</code> | List all of the embedded files in the PDF file. File names are converted to the text encoding specified by `options.outputEncoding`. |
| [options.ownerPassword] | <code>string</code> | Owner password (for encrypted files). |
| [options.outputEncoding] | <code>string</code> | Sets the encoding to use for text output. This defaults to `UTF-8`. |
| [options.ownerPassword] | <code>string</code> | Owner password (for encrypted files). |
| [options.outputPath] | <code>string</code> | Set the file name used when saving an embedded file with the save option enabled, or the directory if `options.saveall` is used. |
| [options.printVersionInfo] | <code>boolean</code> | Print copyright and version info. |
| [options.saveAllFiles] | <code>boolean</code> | Save all of the embedded files. This uses the file names associated with the embedded files (as printed by `options.listEmbedded`). By default, the files are saved in the current directory; this can be changed with `options.outputPath`. |
Expand Down Expand Up @@ -105,10 +105,10 @@ Saves images from a PDF file as PPM, PBM, PNG, TIFF, JPEG, JPEG2000, or JBIG2 fi
| [options.ccittFile] | <code>boolean</code> | Generate CCITT images as CCITT files. |
| [options.firstPageToConvert] | <code>number</code> | Specifies the first page to convert. |
| [options.lastPageToConvert] | <code>number</code> | Specifies the last page to convert. |
| [options.list] | <code>boolean</code> | Instead of writing the images, list the images along with various information for each image. NOTE: Do not specify the outputPrefix with this option. |
| [options.jbig2File] | <code>boolean</code> | Generate JBIG2 images as JBIG2 files. |
| [options.jpeg2000File] | <code>boolean</code> | Generate JPEG2000 images at JP2 files. |
| [options.jpegFile] | <code>boolean</code> | Generate JPEG images as JPEG files. |
| [options.list] | <code>boolean</code> | Instead of writing the images, list the images along with various information for each image. NOTE: Do not specify the outputPrefix with this option. |
| [options.ownerPassword] | <code>string</code> | Owner password (for encrypted files). |
| [options.pngFile] | <code>boolean</code> | Change the default output format to PNG. |
| [options.printVersionInfo] | <code>boolean</code> | Print copyright and version info. |
Expand Down Expand Up @@ -354,12 +354,12 @@ Converts a PDF file to PostScript (PS).
| [options.level2Sep] | <code>boolean</code> | Generate Level 2 separable PostScript. All colors are converted to CMYK. The PostScript separation convention operators are used to handle custom (spot) colors. |
| [options.level3] | <code>boolean</code> | Generate Level 3 PostScript. This enables all Level 2 featuresplus CID font embedding. |
| [options.level3Sep] | <code>boolean</code> | Generate Level 3 separable PostScript. The separation handling is the same as for `options.level2Sep`. |
| [options.noCenter] | <code>boolean</code> | 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. |
| [options.noCrop] | <code>boolean</code> | By default, printing output is cropped to the CropBox specified in the PDF file. This option disables cropping. |
| [options.noEmbedCIDFonts] | <code>boolean</code> | 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. |
| [options.noEmbedCIDTrueTypeFonts] | <code>boolean</code> | 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. |
| [options.noEmbedTrueTypeFonts] | <code>boolean</code> | 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. |
| [options.noEmbedType1Fonts] | <code>boolean</code> | 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. |
| [options.noCenter] | <code>boolean</code> | 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. |
| [options.noCrop] | <code>boolean</code> | By default, printing output is cropped to the CropBox specified in the PDF file. This option disables cropping. |
| [options.noShrink] | <code>boolean</code> | Do not scale PDF pages which are larger than the paper. By default, pages larger than the paper are shrunk to fit. |
| [options.opi] | <code>boolean</code> | Generate OPI comments for all images and forms which have OPI information. |
| [options.optimizecolorspace] | <code>boolean</code> | 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. |
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@
"testTimeout": 60000
},
"devDependencies": {
"@commitlint/cli": "^18.5.0",
"@commitlint/config-conventional": "^18.5.0",
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@eslint-community/eslint-plugin-eslint-comments": "^4.1.0",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"eslint": "^8.56.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jsdoc": "^48.0.2",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-regexp": "^2.2.0",
"eslint-plugin-security": "^2.1.0",
"eslint-plugin-security": "^2.1.1",
"glob": "^10.3.10",
"husky": "^9.0.6",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jsdoc-to-markdown": "^8.0.0",
"jsdoc-to-markdown": "^8.0.1",
"license-checker": "^25.0.1",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"spdx-copyleft": "^1.0.0",
"typescript": "^5.3.3"
},
"dependencies": {
"camelcase": "^6.3.0",
"semver": "^7.5.4",
"semver": "^7.6.0",
"upath": "^2.0.1"
}
}
115 changes: 36 additions & 79 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@ function parseOptions(acceptedOptions, options, version) {
Object.keys(options).forEach((key) => {
if (Object.hasOwn(acceptedOptions, key)) {
// eslint-disable-next-line valid-typeof -- `type` is a string
if (typeof options[key] === acceptedOptions[key].type) {
if (acceptedOptions[key].type === typeof options[key]) {
// Skip boolean options if false

if (acceptedOptions[key].type === "boolean" && !options[key]) {
return;
}
// Arg will be empty for some non-standard options

// Arg will be empty for some non-standard options
if (acceptedOptions[key].arg !== "") {
args.push(acceptedOptions[key].arg);
}
Expand Down Expand Up @@ -94,7 +93,7 @@ class Poppler {
__dirname,
"lib",
"win32",
"poppler-23.11.0",
"poppler-24.02.0",
"Library",
"bin"
);
Expand Down Expand Up @@ -124,9 +123,7 @@ class Poppler {

try {
const args = parseOptions(acceptedOptions, options);
args.push(file);
args.push(fileToAttach);
args.push(outputFile);
args.push(file, fileToAttach, outputFile);

const { stdout } = await execFileAsync(
joinSafe(this.popplerPath, "pdfattach"),
Expand All @@ -145,9 +142,9 @@ class Poppler {
* @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 `options.outputEncoding`.
* @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.ownerPassword] - Owner password (for encrypted files).
* @param {string} [options.outputPath] - Set the file name used when saving an embedded file with
* the save option enabled, or the directory if `options.saveall` is used.
* @param {boolean} [options.printVersionInfo] - Print copyright and version info.
Expand All @@ -167,16 +164,16 @@ class Poppler {
async pdfDetach(file, options = {}) {
const acceptedOptions = {
listEmbedded: { arg: "-list", type: "boolean" },
ownerPassword: { arg: "-opw", type: "string" },
outputEncoding: { arg: "-enc", type: "string" },
outputPath: { arg: "-o", type: "string" },
ownerPassword: { arg: "-opw", type: "string" },
printVersionInfo: { arg: "-v", type: "boolean" },
saveAllFiles: { arg: "-saveall", type: "boolean" },
saveFile: {
arg: "-savefile",
type: "string",
minVersion: "0.86.0",
},
saveAllFiles: { arg: "-saveall", type: "boolean" },
saveSpecificFile: { arg: "-save", type: "number" },
userPassword: { arg: "-upw", type: "string" },
};
Expand Down Expand Up @@ -231,11 +228,7 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}
args.push(Buffer.isBuffer(file) ? "-" : file);

const child = spawn(
joinSafe(this.popplerPath, "pdffonts"),
Expand Down Expand Up @@ -294,12 +287,12 @@ class Poppler {
* @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 {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 {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.
Expand All @@ -313,10 +306,10 @@ class Poppler {
ccittFile: { arg: "-ccitt", type: "boolean" },
firstPageToConvert: { arg: "-f", type: "number" },
lastPageToConvert: { arg: "-l", type: "number" },
list: { arg: "-list", type: "boolean" },
jbig2File: { arg: "-jbig2", type: "boolean" },
jpeg2000File: { arg: "-jp2", type: "boolean" },
jpegFile: { arg: "-j", type: "boolean" },
list: { arg: "-list", type: "boolean" },
ownerPassword: { arg: "-opw", type: "string" },
pngFile: { arg: "-png", type: "boolean" },
printVersionInfo: { arg: "-v", type: "boolean" },
Expand All @@ -336,11 +329,7 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}
args.push(Buffer.isBuffer(file) ? "-" : file);

if (outputPrefix) {
args.push(outputPrefix);
Expand Down Expand Up @@ -576,8 +565,7 @@ class Poppler {
const versionInfo = popplerVersionRegex.exec(stderr)[1];

const args = parseOptions(acceptedOptions, options, versionInfo);
args.push(file);
args.push(outputPattern);
args.push(file, outputPattern);

const { stdout } = await execFileAsync(
joinSafe(this.popplerPath, "pdfseparate"),
Expand Down Expand Up @@ -763,17 +751,10 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}

if (outputFile) {
args.push(outputFile);
} else {
args.push("-");
}
args.push(
Buffer.isBuffer(file) ? "-" : file,
outputFile || "-"
);

const child = spawn(
joinSafe(this.popplerPath, "pdftocairo"),
Expand Down Expand Up @@ -911,11 +892,7 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}
args.push(Buffer.isBuffer(file) ? "-" : file);

if (outputFile) {
args.push(outputFile);
Expand Down Expand Up @@ -1116,13 +1093,7 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}

args.push(outputPath);
args.push(Buffer.isBuffer(file) ? "-" : file, outputPath);

const child = spawn(
joinSafe(this.popplerPath, "pdftoppm"),
Expand Down Expand Up @@ -1211,6 +1182,11 @@ class Poppler {
* 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 `options.level2Sep`.
* @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.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.
Expand All @@ -1224,11 +1200,6 @@ class Poppler {
* @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.
Expand Down Expand Up @@ -1303,15 +1274,15 @@ class Poppler {
level2Sep: { arg: "-level2sep", type: "boolean" },
level3: { arg: "-level3", type: "boolean" },
level3Sep: { arg: "-level3sep", type: "boolean" },
noCenter: { arg: "-nocenter", type: "boolean" },
noCrop: { arg: "-nocrop", type: "boolean" },
noEmbedCIDFonts: { arg: "-noembcidps", type: "boolean" },
noEmbedCIDTrueTypeFonts: {
arg: "-noembcidtt",
type: "boolean",
},
noEmbedTrueTypeFonts: { arg: "-noembtt", type: "boolean" },
noEmbedType1Fonts: { arg: "-noembt1", type: "boolean" },
noCenter: { arg: "-nocenter", type: "boolean" },
noCrop: { arg: "-nocrop", type: "boolean" },
noShrink: { arg: "-noshrink", type: "boolean" },
opi: { arg: "-opi", type: "boolean" },
optimizecolorspace: {
Expand All @@ -1327,11 +1298,11 @@ class Poppler {
passfonts: { arg: "-passfonts", type: "boolean" },
preload: { arg: "-preload", type: "boolean" },
printVersionInfo: { arg: "-v", type: "boolean" },
processColorFormat: { arg: "-processcolorformat", type: "string" },
processColorProfile: {
arg: "-processcolorprofile",
type: "string",
},
processColorFormat: { arg: "-processcolorformat", type: "string" },
quiet: { arg: "-q", type: "boolean" },
rasterize: {
arg: "-rasterize",
Expand All @@ -1354,17 +1325,10 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}

if (outputFile) {
args.push(outputFile);
} else {
args.push("-");
}
args.push(
Buffer.isBuffer(file) ? "-" : file,
outputFile || "-"
);

const child = spawn(
joinSafe(this.popplerPath, "pdftops"),
Expand Down Expand Up @@ -1511,17 +1475,10 @@ class Poppler {
const args = parseOptions(acceptedOptions, options, versionInfo);

return new Promise((resolve, reject) => {
if (Buffer.isBuffer(file)) {
args.push("-");
} else {
args.push(file);
}

if (outputFile) {
args.push(outputFile);
} else {
args.push("-");
}
args.push(
Buffer.isBuffer(file) ? "-" : file,
outputFile || "-"
);

const child = spawn(
joinSafe(this.popplerPath, "pdftotext"),
Expand Down
18 changes: 9 additions & 9 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const windowsPath = joinSafe(
__dirname,
"lib",
"win32",
"poppler-23.11.0",
"poppler-24.02.0",
"Library",
"bin"
);
Expand Down Expand Up @@ -343,18 +343,18 @@ describe("Node-Poppler module", () => {

describe("pdfInfo function", () => {
const pdfInfoObject = {
tagged: "yes",
userProperties: "no",
suspects: "no",
form: "AcroForm",
javaScript: "no",
pages: "16",
encrypted: "no",
pageSize: "595.276 x 841.89 pts (A4)",
pageRot: "0",
fileSize: "583094 bytes",
form: "AcroForm",
javaScript: "no",
optimized: "no",
pageRot: "0",
pageSize: "595.276 x 841.89 pts (A4)",
pages: "16",
pdfVersion: "1.3",
suspects: "no",
tagged: "yes",
userProperties: "no",
};

it("Lists info of PDF file", async () => {
Expand Down
Binary file not shown.
Binary file removed src/lib/win32/poppler-23.11.0/Library/bin/lcms2.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit a211e58

Please sign in to comment.