简体   繁体   English

缩小PDF

[英]shrinking a PDF

I'm not sure if this is the right place to post this question. 我不确定这是否是发布此问题的正确位置。

I'm trying to reduce the size of multiple 7MB PDF files so I tried this ghostscript commands I found online: 我试图减少多个7MB PDF文件的大小,所以我尝试了在网上找到的ghostscript命令:

simple ghostscript with printer quality setting
    gswin32c.exe -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

tried this
    gswin32c.exe -o output.pdf -sDEVICE=pdfwrite -dColorConversionStrategy=/LeaveColorUnchanged -dDownsampleMonoImages=false -dDownsampleGrayImages=false -dDownsampleColorImages=false -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -dColorImageFilter=/FlateEncode -dGrayImageFilter=/FlateEncode input.pdf

and this
    gswin32c.exe -o output.pdf -sDEVICE=pdfwrite -dColorConversionStrategy=/LeaveColorUnchanged -dEncodeColorImages=false -dEncodeGrayImages=false -dEncodeMonoImages=false input.pdf

but in all cases the PDF files obtained were 'bigger' that the original. 但是在所有情况下,所获得的PDF文件都比原始文件“大”了。 All these pdf files are basically a collection of scanned images so maybe I need a specific option to 'tell' ghostscript to compress them ? 所有这些pdf文件基本上都是扫描图像的集合,所以也许我需要一个特定的选项来“告知” ghostscript来压缩它们?

The strange thing I found is that using the trial version of phantom pdf I was able to reduce the size to 2-5MB without visible loss of quality. 我发现的奇怪之处在于,使用phantom pdf的试用版,我能够将大小减小到2-5MB,而不会出现质量损失。

How do I do the same with ghostscript ? 我如何对ghostscript进行操作?

Firstly, Ghostscript (or more accurately, Ghostscript's pdfwrite device) doesn't 'shrink' PDF files, it makes new ones which may, or may not, be smaller. 首先,Ghostscript(或更准确地说,是Ghostscript的pdfwrite设备)不会“缩小” PDF文件,而是使新文件可能会缩小,也可能不会缩小。

Secondly, its practically impossible to say what might be happening with a PDF file without an example to look at. 其次,如果没有示例,几乎不可能说出PDF文件可能发生的情况。

If your files really are scanned images, then (assuming sensible initial compression) there's probably no way to reduce the file size without reducing quality. 如果您的文件确实是扫描的图像,那么(假设合理的初始压缩)可能无法在不降低质量的情况下减小文件大小。 You might not notice the reduction in quality, especilaly if you're just viewing on screen, but it will be there. 可能不会注意到质量下降,特别是如果您只是在屏幕上观看,那么质量就会下降。

Random poking with command lines which you run across online is probably not going to result in useful output either; 使用在线运行的命令行随机戳可能也不会产生有用的输出。 you really need to understand where the size is being used in your original files, and then select options which are likely to reduce that. 您确实需要了解原始文件中使用的大小,然后选择可能会减小大小的选项。

For example, you say the pages are scanned images; 例如,您说页面是扫描的图像。 there are only two realistic ways to reduce the size of an image, downsample it to a lower resolution, or select a different (more efficient, possibly lossy, compression). 只有两种现实的方法可以减小图像的大小,将图像下采样到较低的分辨率或选择其他图像(更有效,可能有损压缩)。 Ghostscript already compresses image data (unless you tell it not to). Ghostscript已经压缩了图像数据(除非您告诉它不这样做)。

The latter two of your command lines explicitly disable image downsampling, so they are not likely to reduce the size of scanned images. 您的命令行的后两个显式禁用图像下采样,因此它们不太可能减小扫描图像的大小。 (by default the pdfwrite device doesn't downsample images, we try to preserve quality) (默认情况下,pdfwrite设备不会对图像进行下采样,我们会尝试保持质量)

The middle option disables auto compression, and selects Flate compression. 中间选项禁用自动压缩,并选择Flate压缩。 If your images were previously JPEG compressed, or are not contone images, then this is probably reasonable. 如果您的图像以前是JPEG压缩的,或者不是连续图像,那么这可能是合理的。

You also say that the PDF files got larger, most likely this is due to using compressed object streams and xref, which is a PDF 1.5 feature that the pdfwrite device doesn't support. 您还说过PDF文件变大了,很可能是由于使用了压缩的对象流和外部参照,这是pdfwrite设备不支持的PDF 1.5功能。 However its not likely to save you much space. 但是,它不太可能为您节省很多空间。

I'd say the most likely difference is that 'phantom PDF' is using more aggressive downsampling, which you could reproduce with pdfwrite. 我想说的最可能的区别是,“ phantom PDF”正在使用更具侵略性的下采样,您可以使用pdfwrite进行复制。

I'm assuming, of course, that you are using a recent version of Ghostscript. 我当然假设您使用的是最新版本的Ghostscript。 Older versions unsurprisingly perform less well than recent ones. 毫不奇怪,较旧的版本比最近的版本表现差。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM