Closed ViieeS closed 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
fs.open
[Error: ENOENT: no such file or directory
Looks like I figured it out, I missed -q param:
-q
const cmd = `-q -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -o ${outFile} ${inFile}`;
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