用光栅图像替换PDF中的矢量图像 [英] Replacing vector images in a PDF with raster images
问题描述
是否有任何简单(可编写脚本)的方法将带有矢量图像的PDF转换为带有光栅图像的PDF?换句话说,我想生成一个具有完全相同(未栅格化)文本但每个矢量图像都替换为栅格化版本的PDF.
Is there any easy (scriptable) way to convert a PDF with vector images into a PDF with raster images? In other words, I want to generate a PDF with the exact same (un-rasterized) text but with each vector image replaced with a rasterized version.
我偶尔在Kindle上阅读技术文章的PDF,发现直接阅读PDF令人沮丧.值得庆幸的是,Amazon将PDF的自动转换格式可以很好地重排我尝试过的大多数PDF的文本部分.但是,尽管光栅图像似乎可以很好地完成转换过程,但矢量图像却受到了严重破坏.如果我可以轻松地转换PDF以便将其所有矢量图像都光栅化,那将是很好的选择.
I occasionally read PDFs of technical articles on my Kindle, and have found that reading a PDF directly is frustrating. Thankfully, Amazon's automatic conversion of PDFs to the Kindle format does a good job of reflowing the text portions of most of PDFs I have tried. However, while raster images seem to make it through the conversion process fine, vector images get horribly mangled. It would be great if I could easily convert a PDF so that all of its vector images were rasterized.
我对任何可能的解决方案都感兴趣,但最好是基于Linux或Windows的解决方案.
I am interested in any possible solutions, but a Linux- or Windows-based one would be preferable.
推荐答案
After some days searching for some solution, based on "Remove all text from PDF file" and "How to add a picture onto an existing pdf file?" I found a (ugly) scriptable solution:
gs -o /tmp/onlytxt.pdf -sDEVICE=pdfwrite -dFILTERVECTOR -dFILTERIMAGE $INPUT_FILE && \
gs -o /tmp/graphics.pdf -sDEVICE=pdfwrite -dFILTERTEXT $INPUT_FILE && \
convert -density $DPI -quality 100 /tmp/graphics.pdf /tmp/graphics.png && \
convert -density $DPI -quality 100 /tmp/graphics.png /tmp/graphics.pdf && \
pdftk /tmp/graphics.pdf stamp /tmp/onlytxt.pdf output $OUTPUT_FILE && \
rm /tmp/onlytxt.pdf /tmp/graphics.pdf /tmp/graphics.png
我们有三个变量INPUT_FILE,OUTPUT_FILE和DPI.我们通过Ghostscript分割文本和图形内容,将图形图像转换为光栅图像(PNG),然后使用pdftk将两者合并.
were we have three variables INPUT_FILE, OUTPUT_FILE, and DPI. We split the textual and graphical contents via Ghostscript, convert the graphical image to a raster image (PNG) and join the two using pdftk.
我一直在成功地使用它来转换巨大的矢量图像以用于科学论文.
I've been using this successfully to convert huge vector images for use in scientific papers.
这篇关于用光栅图像替换PDF中的矢量图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!