简体   繁体   English

如何使用ImageMagick将PDF文件转换为图像文件

[英]How to Convert PDF File into Image File using ImageMagick

How should I convert pdf file into image (.jpg, .gif etc) using ImageMagick on c# programming platform? 如何在C#编程平台上使用ImageMagick将pdf文件转换为图像(.jpg,.gif等)? or is there any third party library aside from ImageMagick that can be used to do this? 还是有除ImageMagick之外的任何第三方库可用于执行此操作?

Ghostscript can read PDF (as well as PostScript and EPS) and convert it to many different image formats. Ghostscript可以读取PDF(以及PostScript和EPS)并将其转换为许多不同的图像格式。

*BTW, ImageMagick cannot do that itself -- ImageMagick also utilizes Ghostscript for exactly that conversion as an external 'delegate'. *顺便说一句,ImageMagick本身无法做到这一点-ImageMagick还利用Ghostscript将该转换作为外部“委托”来进行。 ImageMagick is great for continuing to process and manipulate image files -- at which jobs it really excels! ImageMagick非常适合继续处理和操作图像文件-它真正擅长的工作!

The command gs -h (or on Windows: gswin32c.exe -h ) should give you an overview about the different devices that are built into your Ghostscript: gs -h命令(或在Windows上: gswin32c.exe -h )应为您提供有关Ghostscript内置的不同设备的概述:

GPL Ghostscript GIT PRERELEASE 9.05 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
Usage: gs [switches] [file1.ps file2.ps ...]
Most frequently used switches: (you can use # in place of =)
 -dNOPAUSE           no pause after page   | -q       `quiet', fewer messages
 -g<width>x<height>  page size in pixels   | -r<res>  pixels/inch resolution
 -sDEVICE=<devname>  select device         | -dBATCH  exit after last file
 -sOutputFile=<file> select output file: - for stdout, |command for pipe,
                                         embed %d or %ld for page #
Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PostScriptLevel3 PDF
Default output device: x11alpha
Available devices:
   alc1900 [....] bmp16 bmp16m [...]
   bmp256 bmp32b bmpgray bmpmono bmpsep1 bmpsep8 [....] jpeg jpegcmyk jpeggray 
   pamcmyk32 pamcmyk4 pbm pbmraw pcl3 pcx16 pcx24b [....]
   pcx256 pcx2up pcxcmyk pcxgray pcxmono pdfwrite pgm pgmraw pgnm pgnmraw
   png16 png16m png256 png48 pngalpha
   pnggray pngmono pnm pnmraw ppm ppmraw [....] tiff12nc tiff24nc tiff32nc tiff48nc
   tiff64nc tiffcrle tiffg3 tiffg32d tiffg4 tiffgray tifflzw tiffpack
   tiffscaled tiffscaled24 tiffscaled8 tiffsep tiffsep1 [....]

So, to create a series of PNGs from the multipage PDF my_pdf.pdf with a certain image size (I chose DIN A4 paper format at 72 dpi) and resolution, use the pngalpha device. 因此, 要从具有特定图像尺寸(我选择72 dpi的DIN A4纸张格式)和分辨率的多页PDF my_pdf.pdf创建一系列PNG,请使用pngalpha设备。 Try this command: 试试这个命令:

 gswin32c ^
    -o my_pdf_page_%03d.png ^
    -sDEVICE=pngalpha ^
    -dPDFFitPage ^
    -g595x842 ^
    -r72x72 ^
     my_pdf.pdf

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

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