Eric Furspan
Eric Furspan

Reputation: 761

File compression via Powershell

I have been playing around with the Compress-Archive cmdlet, but am getting fairly weak results in terms of compression ratio, especially when compared to services such as smallpdf.com. Are there alternatives to Compress-Archive which may be called via Powershell, which are known to produce higher compression levels for PDFs?

Compress-Archive results: orig: 1300kb, compressed: 690kb

SmallPDF.com results: orig: 1300kb, compressed: 306kb

Thanks!

Upvotes: 0

Views: 4864

Answers (2)

kana.malzer
kana.malzer

Reputation: 3

Can confirm NeeviaPDF. Even has documentation for CMD-Paramteres including examples. Works like a charm in combination with Invoke-Expression in Powershell. CMD Line Parameters are 1:1 what you see in the GUI so testing is REALLY easy.

While ghostscript often would simply refuse to compress some PDFs no matter the config (and then leave way too much on there) this compressed my 8MB-6page-takenOnS22Ultra-PDF down to 590kb and it's still really readable. Don't know what they did but it just works so well. See my cmdLine arguments down below.

GUI is under folder "apps", CMDline is in Folder "cmdLine"

$neeviaPath = "C:\Program Files (x86)\neeviaPDF.com\PDFcompress\cmdLine\CLcompr.exe"

$inputFilePath = "C:\Path\to\file.pdf"
$outputFilePath = "C:\Path\to\file_cmprsd.pdf"

Invoke-Expression "& `"$neeviaPath`" `"$inputFilePath`" `"$outputFilePath`" -cos -ci jpx -cq 5 -gi jpx -gq 5 -mi jbig2 -mq 0
-crt 175 -crr 100 -grt 175 -grr 100 -mrt 175 -mrr 100"

Upvotes: 0

Mike Garuccio
Mike Garuccio

Reputation: 2718

There are a few different options available, how well they will work for you largely depends on what the content of your PDF file is but it shouldn't be too hard to put together tests cases for them and compare.

From what I can tell the docotic.pdf library will probably be the easiest to integrate with your existing code, it ships as a .NET library and looks to be actively maintained, however there is a fairly significant cost associated with that library, anywhere from $600 to $3000 depending on your use case, they do offer a trial so that you can test for free however - http://bitmiracle.com/pdf-library/

The neeviapdf appears similar and cheaper but I am not sure if its still being actively developed, the site appears quite old and the last update was in 2013. - http://www.neeviapdf.com/PDFcompress/?w=feat

And finally There is GhostScript, which is Open-Source and freely available, it supports many different PDF operations, including compression. Check out http://www.ghostscript.com/ for more information and https://gist.github.com/firstdoit/6390547 for an example of using it for compression.

EDIT

Should probably also include smallpdf's recommendation for a a PDF library which is PDF-tools, you can view their compression product here - http://www.pdf-tools.com/pdf/products-pdf-pdfa.aspx#optimization

Upvotes: 1

Related Questions