Convert PDF to image with high resolution

前端 未结 18 1901
故里飘歌
故里飘歌 2020-11-28 00:13

I\'m trying to use the command line program convert to take a PDF into an image (JPEG or PNG). Here is one of the PDFs that I\'m trying to convert.

I want the progr

相关标签:
18条回答
  • 2020-11-28 00:48

    One more suggestion is that you can use GIMP.

    Just load the PDF file in GIMP->save as .xcf and then you can do whatever you want to the image.

    0 讨论(0)
  • 2020-11-28 00:48

    I have used pdf2image. A simple python library that works like charm.

    First install poppler on non linux machine. You can just download the zip. Unzip in Program Files and add bin to Machine Path.

    After that you can use pdf2image in python class like this:

    from pdf2image import convert_from_path, convert_from_bytes
    images_from_path = convert_from_path(
       inputfile,
       output_folder=outputpath,
       grayscale=True, fmt='jpeg')
    

    I am not good with python but was able to make exe of it. Later you may use the exe with file input and output parameter. I have used it in C# and things are working fine.

    Image quality is good. OCR works fine.

    0 讨论(0)
  • 2020-11-28 00:49

    normally I extract the embedded image with 'pdfimages' at the native resolution, then use ImageMagick's convert to the needed format:

    $ pdfimages -list fileName.pdf
    $ pdfimages fileName.pdf fileName   # save in .ppm format
    $ convert fileName-000.ppm fileName-000.png
    

    this generate the best and smallest result file.

    Note: For lossy JPG embedded images, you had to use -j:

    $ pdfimages -j fileName.pdf fileName   # save in .jpg format
    

    With recent poppler you can use -all that save lossy as jpg and lossless as png

    On little provided Win platform you had to download a recent (0.37 2015) 'poppler-util' binary from: http://blog.alivate.com.au/poppler-windows/

    0 讨论(0)
  • 2020-11-28 00:50

    I really haven't had good success with convert [update May 2020: actually: it pretty much never works for me], but I've had EXCELLENT success with pdftoppm. Here's a couple examples of producing high-quality images from a PDF:

    1. [Produces ~25 MB-sized files per pg] Output uncompressed .tif file format at 300 DPI into a folder called "images", with files being named pg-1.tif, pg-2.tif, pg-3.tif, etc:

      mkdir -p images && pdftoppm -tiff -r 300 mypdf.pdf images/pg
      
    2. [Produces ~1MB-sized files per pg] Output in .jpg format at 300 DPI:

      mkdir -p images && pdftoppm -jpeg -r 300 mypdf.pdf images/pg
      
    3. [Produces ~2MB-sized files per pg] Output in .jpg format at highest quality (least compression) and still at 300 DPI:

      mkdir -p images && pdftoppm -jpeg -jpegopt quality=100 -r 300 mypdf.pdf images/pg
      

    For more explanations, options, and examples, see my full answer here:

    https://askubuntu.com/questions/150100/extracting-embedded-images-from-a-pdf/1187844#1187844.

    Related:

    1. [How to turn a PDF into a searchable PDF w/pdf2searchablepdf] https://askubuntu.com/questions/473843/how-to-turn-a-pdf-into-a-text-searchable-pdf/1187881#1187881
    2. Cross-linked:
      1. How to convert a PDF into JPG with commandline in linux?
      2. https://unix.stackexchange.com/questions/11835/pdf-to-jpg-without-quality-loss-gscan2pdf/585574#585574
    0 讨论(0)
  • 2020-11-28 00:52

    I use pdftoppm on the command line to get the initial image, typically with a resolution of 300dpi, so pdftoppm -r 300, then use convert to do the trimming and PNG conversion.

    0 讨论(0)
  • 2020-11-28 00:52

    You can do it in LibreOffice Draw (which is usually preinstalled in Ubuntu):

    1. Open PDF file in LibreOffice Draw.
    2. Scroll to the page you need.
    3. Make sure text/image elements are placed correctly. If not, you can adjust/edit them on the page.
    4. Top menu: File > Export...
    5. Select the image format you need in the bottom-right menu. I recommend PNG.
    6. Name your file and click Save.
    7. Options window will appear, so you can adjust resolution and size.
    8. Click OK, and you are done.
    0 讨论(0)
提交回复
热议问题