NickNaso / ghostscript4js

Ghostscript4JS binds the Ghostscript C API to the Node.JS world.
http://www.nacios.it
Apache License 2.0
66 stars 19 forks source link

Empty output file #57

Closed ViieeS closed 4 years ago

ViieeS commented 4 years ago
export async function compressPdf(data: Buffer): Promise<Buffer> {
    const fileHash = md5(data);
    const inFile = `${fileHash}.pdf`;
    const outFile = `${fileHash}_compressed.pdf`;
    const cmd = `-sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -o ${outFile} ${inFile}`;
    await fs.writeFile(inFile, data);
    await fs.open(outFile, 'w').then(fd => fd.close());
    await gs.execute(cmd);
    return fs.readFile(outFile);
}

This script gives me empty output file. If I don't create it using fs.open I receive an error: [Error: ENOENT: no such file or directory

ViieeS commented 4 years ago

Looks like I figured it out, I missed -q param:

const cmd = `-q -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -o ${outFile} ${inFile}`;