本文介绍了PDF使用Java进行映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将PDF页面转换为图像(PNG,JPEG / JPG或GIF)。我想要它们以整页大小。

I to want convert PDF pages into an image (PNG,JPEG/JPG or GIF). I want them in full-page sizes.

如何使用Java完成这项工作?有哪些库可用于实现此目的?

How can this be done using Java? What libraries are available for achieving this?

推荐答案

您需要一个PDF渲染器。市场上有一些或多或少好的(ICEPdf,pdfrenderer),但没有,你将不得不依赖外部工具。免费的PDF渲染器也无法渲染嵌入字体,因此只能用于创建缩略图(最终需要的东西)。

You will need a PDF renderer. There are a few more or less good ones on the market (ICEPdf, pdfrenderer), but without, you will have to rely on external tools. The free PDF renderers also cannot render embedded fonts, and so will only be good for creating thumbnails (what you eventually want).

我最喜欢的外部工具是Ghostscript,它可以使用单个命令行调用将PDF转换为图像。

My favorite external tool is Ghostscript, which can convert PDFs to images with a single command line invocation.

这会将Postscript(和PDF?)文件转换为bmp for us ,就像根据您的需要修改指南(知道您需要让gs工作的env vars!):

This converts Postscript (and PDF?) files to bmp for us, just as a guide to modify for your needs (Know you need the env vars for gs to work!):

pushd 
setlocal

Set BIN_DIR=C:\Program Files\IKOffice_ACME\bin
Set GS=C:\Program Files\IKOffice_ACME\gs
Set GS_DLL=%GS%\gs8.54\bin\gsdll32.dll
Set GS_LIB=%GS%\gs8.54\lib;%GS%\gs8.54\Resource;%GS%\fonts
Set Path=%Path%;%GS%\gs8.54\bin
Set Path=%Path%;%GS%\gs8.54\lib

call "%GS%\gs8.54\bin\gswin32c.exe" -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE#bmpmono -r600x600 -sOutputFile#%2 -f %1

endlocal
popd

这篇关于PDF使用Java进行映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:17