duangu9666 2010-09-13 09:29
浏览 51
已采纳

PHP将PDF转换为图像-dUseCropBox

I'm trying to convert a PDF to an image and I need to make sure that the -dUseCropBox parameter is specified for when calling Ghostscript. Can this be done?

convert "/var/www/vhosts/site.co.uk/httpdocs/uploads/source_pdf/PP4SDpdf.pdf" -resize 500X500 "/var/www/vhosts/site.co.uk/httpdocs/uploads/image_pdf/SaturdayTest.jpg"

It works well but just need to get the Ghostscript parameter in.

  • 写回答

2条回答 默认 最新

  • douwei6478 2010-09-13 12:59
    关注

    Is it acceptable for you to run Ghostscript directly (instead of having convert call it anyway) ?

    I ask, because convert does not do the PDF => JPEG conversion by itself. It calls Ghostscript as its 'delegate' to do the job. So for convert to work you need to have access to a functional Ghostscript installation on that system anyway... .

    But how to add custom parameters to converts commandline to pass them through to Ghostscript's commandline isn't easy to figure out. Ghostscript's commandline isn't exactly easy either, but at least it is fully documented at a well-known place (see Use.htm, Devices.htm and Ps2pdf.htm there).

    Here is a command that would convert your input PDF to a series of JPEGs (one file for each PDF page). I'm assuming Windows -- for Linux just replace the ^ by \ and gswin32c.exe by gs:

    gswin32c.exe ^
      -o "d:/path with spaces/to/output/dir/input_page_%03d.jpeg ^
      -sDEVICE=jpeg ^
      -dJPEQ=95 ^
      -r720 ^
      -g5000x5000 ^
      -dUseCropBox=true ^
      "d:/path/to/input.pdf"
    

    Explanation:

    • -dJPEGQ sets the JPEG quality. Accepts integer values in the range 0..100. Higher values create bigger files... (Ghostscript's default for JPEGQ is set to 75.)
    • -r720 sets a (rather high) resolution of 720dpi. Higher values create bigger files... (Ghostscript's default for its jpeg output device would be 72dpi.)
    • -g5000x5000 gives the file dimension in pixels. (Note: when decreasing the -r... value you MUST also accordingly decrease the -g... value to keep the same dimension in userspace inches or mm.)

    You could also add -dPDFFitPage=true if that is useful for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)