将PDF转换为高分辨率图像

    技术2022-07-13  70

    本文翻译自: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
    Processed: 0.009, SQL: 9