Replacing vector images in a PDF with raster images

后端 未结 8 1117
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 22:46

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

8条回答
  •  借酒劲吻你
    2021-01-30 23:17

    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
    

    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.

提交回复
热议问题