没有生成 tif 图像有人看到错误吗?我没有收到任何错误。我现在看到 ghosscript 正在运行的消息,但仍然没有得到输出 tif。从输出中我现在得到“GPL Ghostscript 9.02 (2011-03-30)\n版权所有 (C) 2010 Artifex Software, Inc. 保留所有权利。\n此软件不提供任何保证:有关详细信息,请参阅文件 PUBLIC。\n”越来越近
根据评论的建议进行了编辑修改**
from subprocess import Popen, PIPE,STDOUT
output = Popen([
r'C:\Program Files (x86)\gs\gs9.02\bin\gswin32c.exe',
'-dNOPAUSE',
'-dBATCH',
'-sDEVICE=tiffg4',
'-dDEBUG',
'-r196X204',
'-sPAPERSIZE=a4',
'-sOutputFile=%s' % (r'C:\Python25\pdfmining\page.tif'),
'%s' %(r'C:\Python25\pdfmining\nca.pdf'),
],stdout=PIPE,stderr = STDOUT).communicate()[0]
Run Code Online (Sandbox Code Playgroud) 我正在尝试上传 pdf 并将其转换为 jpeg 图像,我正在使用 Ghostscript 和 imagick 和 php。问题是 jpeg 的质量不太令人满意。
这是我的设置和我使用的
exec('转换-密度400 -colorspace sRGB“'.$pdf_path.'[0]”-resize 842 -quality 100“'.$save_path.'.jpg”');
我应该使用哪些设置?
正如你所看到的,图片很暗,文字不清楚。这是原始 pdf 的网址“
http://icebergfeeds.co.uk/admin/images/magazine-content/54085a9d5a03d.pdf ”,这是示例结果,

我正在使用 GS 9.15 在 Windows 机器上批量打印一些 PDF。这是我正在使用的命令:
gswin64 -dNoCancel=true -dBATCH -dNOPAUSE -dNOSAFER -q -sDEVICE=ljet4d -sOutputFile=%printer%[printer path] "[pdf path]"
Run Code Online (Sandbox Code Playgroud)
尽管这有效,但在打印过程中会弹出一个窗口,然后关闭。
有办法隐藏吗?
要求是使用嵌入的宏将 PDF 转换为 PCL(目前正在 Windows 上测试,但我需要在应用程序中使用此运行时并从 UNIX 打印它)。该宏稍后将在另一个文档中用于嵌入此裁剪图像并打印在单个页面上。我将使用 PCL 转义码来调用 MacroNumber,然后将打印图像。(您可以将其视为徽标图像。)
我可以使用 CropBox 将带有空格的 PDF 转换为没有任何空格的 PDF。
"c:\progra~1\gs\gs9.15\bin\gswin64.exe" -o _sourcePDFcropped.pdf \
-sDEVICE=pdfwrite -c "[/CropBox [1 140 320 650] /PAGES pdfmark" \
-f _sourcePDF.pdf
Run Code Online (Sandbox Code Playgroud)
但是,当我将其转换_sourcePDFcropped.pdf为 PCL 时,这仍然会添加空格。
"c:\progra~1\gs\gs9.15\bin\gswin64c.exe" -dBATCH -dNOPAUSE \
-sDEVICE=pxlcolor -g100x200 -sOutputFile=_sourceFedGroundCroppedTest.pcl \
-f _sourceFedGroundCropped.pdf
Run Code Online (Sandbox Code Playgroud)
我尝试使用MKPCL ,它完成了这项工作。因为它没有太多支持,我正在尝试使用 Ghostscript。
MKPCL.EXE -c4 -t -m 100 -p Image.jpg Image.MAC
Run Code Online (Sandbox Code Playgroud)
我还尝试了内部使用 Ghostscript 的 ImageMagick。所以我猜测,如果我在 GS 中使用正确的开关,我应该能够实现我的目标。
输入PDF文件:点击这里
PS:我在 Stackoverflow 上看到了其他 PDF 到 PCL 的查询,其他人更直接地 PDF 到 PCL。我的是裁剪PDF,输出应该是PCL。
问题继续:链接
将 Laravel 用于 Web 应用程序,我在其中使用https://github.com/clegginabox/pdf-merger合并 pdf 文件,并在尝试将两个 pdf 文件合并到一起超过 1.4 版时遇到以下错误:
Exception in pdf_parser.php line 133:
This document (C:\path-to-doc\file.pdf) probably uses a compression technique
which is not supported by the free parser shipped with FPDI.
(See https://www.setasign.com/fpdi-pdf-parser for more details)
in pdf_parser.php line 133
Run Code Online (Sandbox Code Playgroud)
我按照以下答案中的建议使用 ghostscript 将任何 1.4 以上的 pdf 转换为 1.4,以便合并工作。
FPDF 错误:此文档 (testcopy.pdf) 可能使用了 FPDI 附带的免费解析器不支持的压缩技术
我已经成功安装了 ghostscript 并将其添加到我的路径中。为了测试,我有一个名为 1.5 版的示例 pdf 文件,test.pdf我从 Windows 终端运行以下命令:
gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -sOutputFile=new-file.pdf test-file.pdf
我得到了我的 …
我正在向现有 Web 应用程序添加一项新功能,该功能将验证上传的 PDF 文件的大小以确保其不小于 A4。Web 应用程序是使用 PHP/Laravel 构建的。
\n我考虑了两种方法来解决这个问题:
\n至于 Ghostscript,我在 SO 上找到了这个答案,建议使用一个名为的附加脚本pdf_info.ps(我确实按照评论建议首先下载了这个脚本)。但是,我无法让它正常工作。在将其添加到任何 PHP 脚本之前,我尝试运行以下命令:
\xce\xbb .\\gswin64c -dNODISPLAY -q -sFile=c:\\test.pdf [-dDumpMediaSizes=false] [-dDumpFontsNeeded=false] [-dDumpXML] [-dDumpFontsUsed [-dShowEmbeddedFonts] ] ..\\toolbin\\pdf_info.ps\nError: /undefinedfilename in ([-dDumpMediaSizes=false])\nOperand stack:\n\nExecution stack:\n %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push\nDictionary stack:\n --dict:1196/1684(ro)(G)-- --dict:0/20(G)-- --dict:78/200(L)--\nCurrent allocation mode is local\nLast …Run Code Online (Sandbox Code Playgroud) 我正在使用 linux (ubuntu 9.26) 版本的 Ghostscript。当我尝试使用以下命令将 postscript 文件转换为 pdf 时:
$ gs -dNOPAUSE -dBATCH -sOutputFile=test.pdf -sDEVICE=pdfwrite -c . setpdfwrite -f d00040-001.ps
我得到的输出如下:
GPL Ghostscript 9.26 (2018-11-20)
Copyright (C) 2018 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefined in .
Operand stack:
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack:
--dict:970/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)-- …Run Code Online (Sandbox Code Playgroud) 我尝试使用以下参数:
'-dPDFA=2 ' +
'-dBATCH ' +
'-DNOSAFER ' +
'-dNOPAUSE ' +
'-sColorConversionStrategy=UseDeviceIndependentColor ' +
'-sDEVICE=pdfwrite ' +
'-dPDFACompatibilityPolicy=1 ' +
'-o ./temp.pdf' +
'./PDFA_def.ps' +
'./out/temp.pdf'
Run Code Online (Sandbox Code Playgroud)
我的 PDFA_def.ps 如下所示:
%!
% This is a sample prefix file for creating a PDF/A document.
% Users should modify entries marked with "Customize".
% This assumes an ICC profile resides in the file (srgb.icc),
% in the current directory unless the user modifies the corresponding line below.
% Define entries in …Run Code Online (Sandbox Code Playgroud) 我可以运行以下 GhostScript 成功地将多个 PDF 合并到一个文件中:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=test.pdf file1.pdf file2.pdf file3.pdf
Run Code Online (Sandbox Code Playgroud)
我还需要向 PDF 添加自定义叠加层,因此我执行以下操作:
convert -density 300 -quality 100 file1.pdf -font /usr/share/fonts/urw-base35/NimbusSansNarrow-Regular.otf -pointsize 15 -fill '#000000' -draw 'rectangle 21,1114,675,1220' -fill white -annotate +440+1160 '1 / 3' -annotate +34+1213 'file1.pdf' file1_a.pdf
Run Code Online (Sandbox Code Playgroud)
...对于每个 PDF,然后我再次运行第一个gs命令来合并这些带注释的 PDF,但是当我这样做时,我收到以下错误:
**** Error: ICCbased space /N value does not match the ICC profile.
Using the number of channels from the profile.
Output may be incorrect.
Run Code Online (Sandbox Code Playgroud)
我确实找到了一些看起来相关的东西,表明 PDF 是错误的:https://bugs.ghostscript.com/show_bug.cgi ?id=697223
好吧,从根本上来说,您的 PDF 文件已损坏。它使用ICCBased色彩空间,并且色彩空间中声明的分量数量与ICC配置文件的实际内容不匹配。 …
我想将 pdf 文件转换为 jpg。我正确安装了imagick并安装了ghoscript 9.53.3 64x但出现此错误。我把ghoscript/bin和lib路径放在环境变量中。
致命错误:未捕获 ImagickException:PDFDelegateFailed `系统找不到指定的文件。' @ error/pdf.c/ReadPDFImage/794 in C:\xampp7.4\htdocs\kOnline\vendor\spatie\pdf-to-image\src\Pdf.php:40 堆栈跟踪:#0 C:\xampp7。 4\htdocs\kOnline\vendor\spatie\pdf-to-image\src\Pdf.php(40): Imagick->pingimage('C:/xampp7.4/htd...') #1 C:\xampp7 .4\htdocs\kOnline\pdfToImaage.php(8): Spatie\PdfToImage\Pdf->__construct('C:/xampp7.4/htd...') #2 {main} 扔在 C:\xampp7.4 中\htdocs\kOnline\vendor\spatie\pdf-to-image\src\Pdf.php 第 40 行
我的代码:
$pdf = new Spatie\PdfToImage\Pdf($pathToPdf);
foreach (range(1, $pdf->getNumberOfPages()) as $pageNumber) {
$pdf->setPage($pageNumber);
$pdf->saveImage("Image_name".$pageNumber.".png");
}
Run Code Online (Sandbox Code Playgroud)
PHP 版本 7.4.11
Apache 版本 Apache/2.4.46 (Win64) OpenSSL/1.1.1g PHP/7.4.11
戈脚本 9.53.3 64x
imagick 模块版本 3.4.4
操作系统 Windows 10 64x
ghostscript ×10
pdf ×6
php ×3
imagick ×2
fpdf ×1
fpdi ×1
imagemagick ×1
pdfa ×1
php-7.4 ×1
postscript ×1
python ×1
shell-exec ×1
windows ×1