【问题标题】:Failed to convert pdf to image by imagick in php无法通过 php 中的 imagick 将 pdf 转换为图像
【发布时间】:2021-02-04 20:45:57
【问题描述】:

这是异常跟踪:

Postscript 委托失败 `[ghostscript library 8.70] -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 - dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/tmp/magick-17649SdGWHr3z3794%d' '-f/tmp/magick-17649w9uyEgynEd2e' '-f/tmp/magick-17649t0lFMpipemUo'': 错误: /typecheck in --run -- 操作数栈:--dict:11/11(L)-- --dict:11/11(L)-- --dict:11/11(L)-- --nostringval-- --nostringval- - --nostringval-- --nostringval-- --nostringval-- 执行堆栈:%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval- - --nostringval-- 假 1 %stopped_push 1862 1 3 %oparray_pop 1861 1 3 %oparray_pop 1845 1 3 %oparray_pop --nostringval-- --nostringval-- 2 1 1 --nostringval-- %for_pos_int_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- %array_continue --nostringval-- --nostringval-- --nostringval-- --nostringval-- - -nostringval-- 字典栈:--dict:1142/1684(ro)(G)-- --dict:1/20(G)-- --dict:75/200(L)-- --dict: 75/200(L)-- --dict:106/127(ro)(G)-- --dict:286/300(ro)(G)-- --dict:22/25(L)-- --dict:4/6(L)-- --dict:25/40(L)-- 当前分配模式为本地 GPL Ghostscript 8.70: Unrecoverable error, exit code 1 @error/ghostscript-private.h/InvokeGhostscriptDelegate/ 171

这是我的 php

if (file_exists($pdf_path)) {
    try {
        $image = new Imagick($pdf_path);
        $image->readImage($pdf_path);
        $totalPage = $image->getNumberImages();
    } catch (ImagickException $e) {
        throw $e;
    }
}

任何想法都将不胜感激

【问题讨论】:

    标签: php ghostscript imagick


    【解决方案1】:

    从一些类似的错误报告来看,当 PDF 不太有效时,似乎会发生这种类型的错误:

    您可能可以通过使用像这样的在线 PDF 验证器来确认这一点:

    https://www.pdf-online.com/osa/validate.aspx

    如果它无效,具体该怎么做并不明显。如果 PDF 是由您控制的东西生成的,您可以修复生成无效 PDF 的任何东西。如果它是用户提供的文件,您可以尝试使用以下方式修复它:https://pdf.recoverytoolbox.com/

    【讨论】:

    • 嘿,谢谢你的建议
    猜你喜欢
    • 2011-05-11
    • 2018-04-07
    • 2017-01-22
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 2012-03-10
    • 2012-02-06
    • 2018-05-09
    相关资源
    最近更新 更多