Git Product home page Git Product logo

gsx-pdf-optimize's Introduction

gsx-pdf-optimize

Optimize PDFs with Ghostscript gsx command, for example the test/raw_pdf.pdf (generated by Figma) goes from 3.7 MB to 642 KB.

Install

First, make sure you've installed Ghostscript in your command. In Mac it looks like this:

brew install ghostscript

Then, install this tool globally:

npm install gsx-pdf-optimize --global

Usage

gsx-pdf-optimize input.pdf [output.pdf] [opts]

Options:
  --preset, -P   one of: screen (default), printer, prepress, ebook
  --dpi, -D      image resampling resolution in DPI, default 300
  --quiet        enable or disable logging (default quiet=true)
  --command      the Ghostscript command to use, default gsx

You can also override the command with the GSX_OPTIMIZE_COMMAND env var, e.g. if you want to set that in your bash profile.

Examples:

gsx-pdf-optimize input.pdf
gsx-pdf-optimize input.pdf output.pdf
gsx-pdf-optimize input.pdf --preset=ebook --dpi=96
GSX_OPTIMIZE_COMMAND=gs gsx-pdf-optimize input.pdf output.pdf

Raw Command

Below is the raw command if you'd like to optimize it further yourself. Credit goes to @lkraider and this gist.

gsx -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/screen \
  -dNOPAUSE -dQUIET -dBATCH \
  -dCompatibilityLevel=1.5 \
  `# font settings` \
  -dSubsetFonts=true \
  -dCompressFonts=true \
  -dEmbedAllFonts=true \
  `# color format` \
  -sProcessColorModel=DeviceRGB \
  -sColorConversionStrategy=RGB \
  -sColorConversionStrategyForImages=RGB \
  -dConvertCMYKImagesToRGB=true \
  `# image resample` \
  -dDetectDuplicateImages=true \
  -dColorImageDownsampleType=/Bicubic \
  -dColorImageResolution=300 \
  -dGrayImageDownsampleType=/Bicubic \
  -dGrayImageResolution=300 \
  -dMonoImageDownsampleType=/Bicubic \
  -dMonoImageResolution=300 \
  -dDownsampleColorImages=true \
  `# preset overrides` \
  -dDoThumbnails=false \
  -dCreateJobTicket=false \
  -dPreserveEPSInfo=false \
  -dPreserveOPIComments=false \
  -dPreserveOverprintSettings=false \
  -dUCRandBGInfo=/Remove \
  -sOutputFile=output.pdf \
  input.pdf

License

MIT, see LICENSE.md for details.

gsx-pdf-optimize's People

Contributors

mattdesl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.