本文翻譯自:Convert PDF to image with high resolution
I'm trying to use the command line program convert
to take a PDF into an image (JPEG or PNG). 我正在嘗試使用命令行程序convert
PDF轉換爲圖像(JPEG或PNG)。 Here is one of the PDFs that I'm trying to convert. 這是我要轉換的PDF之一 。
I want the program to trim off the excess white-space and return a high enough quality image that the superscripts can be read with ease. 我希望程序修剪掉多餘的空白並返回足夠高質量的圖像,以便可以輕鬆讀取上標。
This is my current best attempt . 這是我目前的最佳嘗試 。 As you can see, the trimming works fine, I just need to sharpen up the resolution quite a bit. 如您所見,修整效果很好,我只需要稍微提高一下分辨率即可。 This is the command I'm using: 這是我正在使用的命令:
convert -trim 24.pdf -resize 500% -quality 100 -sharpen 0x1.0 24-11.jpg
I've tried to make the following conscious decisions: 我嘗試做出以下有意識的決定:
- resize it larger (has no effect on the resolution) 調整它的大小(對分辨率沒有影響)
- make the quality as high as possible 使質量儘可能高
- use the
-sharpen
(I've tried a range of values) 使用-sharpen
(我嘗試了一系列值)
Any suggestions please on getting the resolution of the image in the final PNG/JPEG higher would be greatly appreciated! 任何關於在最終的PNG / JPEG中獲得更高圖像分辨率的建議,將不勝感激!
#1樓
參考:https://stackoom.com/question/RiGM/將PDF轉換爲高分辨率圖像
#2樓
它還可以爲您帶來良好的效果:
exec("convert -geometry 1600x1600 -density 200x200 -quality 100 test.pdf test_image.jpg");
#3樓
Personally I like this. 我個人喜歡這樣。
convert -density 300 -trim test.pdf -quality 100 test.jpg
It's a little over twice the file size, but it looks better to me. 它是文件大小的兩倍多,但對我來說看起來更好。
-density 300
sets the dpi that the PDF is rendered at. -density 300
設置渲染PDF的dpi。
-trim
removes any edge pixels that are the same color as the corner pixels. -trim
刪除與角像素顏色相同的所有邊緣像素。
-quality 100
sets the JPEG compression quality to the highest quality. -quality 100
將JPEG壓縮質量設置爲最高質量。
Things like -sharpen
don't work well with text because they undo things your font rendering system did to make it more legible. -sharpen
之類的東西不能很好地與文本配合使用,因爲它們會撤消字體渲染系統所做的使它更清晰的事情。
If you actually want it blown up use resize here and possibly a larger dpi value of something like targetDPI * scalingFactor
That will render the PDF at the resolution/size you intend. 如果您確實希望將其炸燬,請在此處使用調整大小,並可能使用較大的dpi值,例如targetDPI * scalingFactor
,它將以您想要的分辨率/大小呈現PDF。
Descriptions of the parameters on imagemagick.org are here 在這裏 imagemagick.org上的參數說明
#4樓
I have found it both faster and more stable when batch-processing large PDFs into PNGs and JPGs to use the underlying gs
(aka Ghostscript) command that convert
uses. 當將大型PDF批量處理爲PNG和JPG以使用convert
使用的基礎gs
(又名Ghostscript)命令時,我發現它既更快又更穩定。
You can see the command in the output of convert -verbose
and there are a few more tweaks possible there (YMMV) that are difficult / impossible to access directly via convert
. 您可以在convert -verbose
的輸出中看到命令,並且那裏還有一些可能的調整(YMMV),很難/不可能直接通過convert
訪問。
However, it would be harder to do your trimming and sharpening using gs
, so, as I said, YMMV! 但是,使用gs
修剪和銳化將更加困難,因此,正如我所說的,YMMV!
#5樓
One more suggestion is that you can use GIMP. 另一個建議是您可以使用GIMP。
Just load the PDF file in GIMP->save as .xcf and then you can do whatever you want to the image. 只需將GIMP-> PDF文件加載爲.xcf,然後就可以對圖像執行任何操作。
#6樓
PNG file you attached looks really blurred. 您附加的PNG文件看起來真的很模糊。 In case if you need to use additional post-processing for each image you generated as PDF preview, you will decrease performance of your solution. 如果您需要對作爲PDF預覽生成的每個圖像進行額外的後期處理,則會降低解決方案的性能。
2JPEG can convert PDF file you attached to a nice sharpen JPG and crop empty margins in one call: 2JPEG可以轉換您附加到一個不錯的JPG的PDF文件,並在一次調用中裁剪空白邊距:
2jpeg.exe -src "C:\In\*.*" -dst "C:\Out" -oper Crop method:autocrop