Pdf merge and compress

pdftk : https://www.pdflabs.com/tools/pdftk-server/

gswin64 : https://ghostscript.com/releases/gsdnld.html

filenames = os.listdir()
result = ” “.join(filenames)
result

pdftk 1.pdf 2.pdf 3.pdf cat output merged.pdf

gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 –dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=merged_compress.pdf merged.pdf

  • -dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
  • -dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
  • -dPDFSETTINGS=/prepress output similar to Acrobat Distiller “Prepress Optimized” setting (300 dpi)
  • -dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller “Print Optimized” setting (300 dpi)
  • -dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file

Reference:  https://ghostscript.readthedocs.io/en/latest/VectorDevices.html#controls-and-features-specific-to-postscript-and-pdf-input

pdf to png command

gswin64 -sDEVICE=pngalpha -sOutputFile=math.png -r144 math.pdf