如何使用PHP / Imagemagik / Ghostscript将PDF转换为与PDF完全相似的图像

时间:2022-10-30 11:52:12

Im generating PDF documents with PHP(TCPDF is the library behind) and for displaying them Im converting them as images using ghostscript, and displaying the previews, but the preview doesnt actually similar to the PDF document.

我用PHP生成PDF文档(TCPDF是后面的库)并用于显示它们使用ghostscript将它们转换为图像,并显示预览,但预览实际上与PDF文档类似。

The code Im using to convert is here

我用来转换的代码就在这里

$pdf = 'my_report.pdf';
$output = 'my_preview.jpg';
$quality=90;
$res='300x300';
$exportPath=$output;
set_time_limit(900);
exec("'gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4' '-o$exportPath' '-r$res' '-dJPEGQ=$quality' '$pdf'",$output);

and the preview generated with the code for this document is right below 如何使用PHP / Imagemagik / Ghostscript将PDF转换为与PDF完全相似的图像

并且使用此文档的代码生成的预览就在下面

where as my actual PDF file looks like below 如何使用PHP / Imagemagik / Ghostscript将PDF转换为与PDF完全相似的图像

我的实际PDF文件如下所示

You can see a lot of inequalities between, I need a way to convert like just a copy of it. and im sure there is nothing wrong in the PDf report, I tried it uploading it into Google mail, that gave a perfect image, and I did convert the PDf into jpeg here http://pdf2jpg.net/ That to gave a perfect copy of the document, only the Imagemagick/Gjostscript is unable to generate an exact one. Any help would be helpful.

你可以看到很多不平等之处,我需要一种转换方式,就像它的副本一样。并且我确定PDf报告没有任何问题,我尝试将其上传到谷歌邮件,这给了一个完美的图像,我确实把PDF转换成了jpeg http://pdf2jpg.net/那给了一个完美的副本在文档中,只有Imagemagick / Gjostscript无法生成一个精确的文件。任何帮助都会有所帮助。

1 个解决方案

#1


0  

What are you using to view the 'correct' display of the PDF ? Does Ghostscript issue you any warnings when rendering ?

你用什么来查看PDF的“正确”显示? Ghostscript在渲染时是否会向您发出警告?

It looks to me like there 'may' be fonts missing in your original PDF file, which will lead to font substitution.

在我看来,原始PDF文件中可能会丢失字体,这将导致字体替换。

Why are you using -dUseCIEColor ? This will almost certainly lead to colour shifts, which I also see in your images. If you have a good reason for using this, what is it ? If you don't have a good reason, don't do that.

你为什么用-dUseCIEColor?这几乎肯定会导致颜色变化,我也会在你的图像中看到。如果你有充分的理由使用它,它是什么?如果你没有充分的理由,不要这样做。

Is the second image a JPEG ? The first clearly is, and jpeg is a lossy compression, have you tried using TIFF instead ?

第二张图片是JPEG吗?第一个显然是,jpeg是一个有损压缩,你试过使用TIFF吗?

It is always useful with these sorts of questions to post a link to the original PDF file, so that some investigation can be done, without that, this is all guesswork I'm afraid.

发布这些类型的问题总是有用的,可以发布原始PDF文件的链接,这样就可以进行一些调查,如果不这样做,这就是我担心的所有猜测。

#1


0  

What are you using to view the 'correct' display of the PDF ? Does Ghostscript issue you any warnings when rendering ?

你用什么来查看PDF的“正确”显示? Ghostscript在渲染时是否会向您发出警告?

It looks to me like there 'may' be fonts missing in your original PDF file, which will lead to font substitution.

在我看来,原始PDF文件中可能会丢失字体,这将导致字体替换。

Why are you using -dUseCIEColor ? This will almost certainly lead to colour shifts, which I also see in your images. If you have a good reason for using this, what is it ? If you don't have a good reason, don't do that.

你为什么用-dUseCIEColor?这几乎肯定会导致颜色变化,我也会在你的图像中看到。如果你有充分的理由使用它,它是什么?如果你没有充分的理由,不要这样做。

Is the second image a JPEG ? The first clearly is, and jpeg is a lossy compression, have you tried using TIFF instead ?

第二张图片是JPEG吗?第一个显然是,jpeg是一个有损压缩,你试过使用TIFF吗?

It is always useful with these sorts of questions to post a link to the original PDF file, so that some investigation can be done, without that, this is all guesswork I'm afraid.

发布这些类型的问题总是有用的,可以发布原始PDF文件的链接,这样就可以进行一些调查,如果不这样做,这就是我担心的所有猜测。