0

I looking for lib NOdeJS or VueJS to reduce the size of PDF upload by users.

What lib choose ?

Otherwise I saw pdftron but it is very little used and not free

i try install ghostscript4js and use this solution

How to compress a pdf with node?

i have error on install of ghostscript4js

(i'm and developpe in win10 but the serve is on unix)

npm install ghostscript4js

> ghostscript4js@3.2.1 install C:\Users\server\node_modules\ghostscript4js
> node-gyp rebuild


C:\Users\server\node_modules\ghostscript4js>if not defined npm_config_node_gyp (node "C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer
gyp ERR! find VS looking for Visual Studio 2015
gyp ERR! find VS - not found
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack     at VisualStudioFinder.fail (C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
gyp ERR! stack     at C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
gyp ERR! stack     at C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
gyp ERR! stack     at C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
gyp ERR! stack     at C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
gyp ERR! stack     at C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:310:5)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
gyp ERR! System Windows_NT 10.0.19041
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\server\node_modules\ghostscript4js
gyp ERR! node -v v12.18.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN homeinlove-website@3.5.0 No repository field.
npm WARN homeinlove-website@3.5.0 No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ghostscript4js@3.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ghostscript4js@3.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\AppData\Roaming\npm-cache\_logs\2020-09-15T10_24_32_794Z-debug.log

i have install ghostscript and add GS4JS_HOME var enviroment (gs not recognized as command)

with this command line do the same

npm install ghostscript4js --GS4JS_DLL="C:/Program\ Files/gs/gs9.53.1/bin/gsdll64.dll"

hhézre
  • 29
  • 2
  • 7
  • Does this answer your question? [How to compress a pdf with node?](https://stackoverflow.com/questions/43728147/how-to-compress-a-pdf-with-node) – Boaz Sep 15 '20 at 09:17

1 Answers1

1

You can install ghoststricpt4js for server Node.js. const gs = require('ghostscript4js');

Then you use this script for compress pdf file:

 gs.executeSync(
`-q -dNOPAUSE -dBATCH -dSAFER -dPDFA=2 -dPDFACompatibilityPolicy=1 -dSimulateOverprint=true -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dPDFSETTINGS=/screen -dEmbedAllFonts=true -dSubsetFonts=true -dAutoRotatePages=/None -dColorImageDownsampleType=/Bicubic -dColorImageResolution=300 -dGrayImageDownsampleType=/Bicubic -dGrayImageResolution=150 -dMonoImageDownsampleType=/Bicubic -dMonoImageResolution=300 -sOutputFile=${file.destination}/%d_${file.filename}.pdf ${file.path}`
);

Reference: https://gist.github.com/firstdoit/6390547 OR https://gist.github.com/ahmed-musallam/27de7d7c5ac68ecbd1ed65b6b48416f9

miko866
  • 182
  • 2
  • 9
  • i try but i'm not success to install ghoststricpt4js – hhézre Sep 15 '20 at 12:19
  • I see that you have to install node-gyp package too. https://github.com/nodejs/node-gyp And node-gyp needs some other dependencies. But I use only Mac or Linux. – miko866 Sep 15 '20 at 19:55