Ghostscript无法将PDF转换为PNG:nostringval

尝试将PDF转换为PNG时,出现以下stdout错误。任何人都知道PDF文件有什么问题吗?

此问题仅影响某些PDF文件,并且该特定PDF实际上是从较大的PDF中分离出来的,并由GhostScript调整大小和压缩。

该命令运行,没有返回错误,但是 stdout 具有以下警告,并且输出的PNG文件存在,但尺寸为0和0。

标准输出:

  **** Error reading a content stream. The page may be incomplete.
               Output may be incorrect.
Error: /typecheck in --run--
Operand stack:
   --dict:3/3(L)--   4   9463495   4   0   --nostringval--   MediaBox   --nostringval--   Parent   --nostringval--   Type   Page   Contents   --nostringval--   Resources   --nostringval--   ColorSpace   --nostringval--   ExtGState   --nostringval--   Font   --nostringval--   ProcSet   --nostringval--   XObject   --nostringval--   R1000   --nostringval--   R10000   --nostringval--   R10001   --nostringval--   R10002   --nostringval--   R10003   --nostringval--   R10004   --nostringval--   R10005   --nostringval--   R10006   --nostringval--   R10007   --nostringval--   R10008   --nostringval--   R10009   --nostringval--   R1001   --nostringval--   R10010   --nostringval--   R10011   --nostringval--   R10012   --nostringval--   R10013   --nostringval--   R10014   --nostringval--   R10015   --nostringval--   R10016   --nostringval--   R10017   --nostringval--   R10018   --nostringval--   R10019   --nostringval--   R1002   --nostringval--   R10020   --nostringval--   R10021   --nostringval--   R10022   --nostringval--   R10023   --nostringval--   R10024   --nostringval--   R10025   --nostringval--   R10026   --nostringval--   R10027   --nostringval--   R10028   --nostringval--   R10029   --nostringval--   R1003   --nostringval--   R10030   --nostringval--   R10031   --nostringval--   R10032   --nostringval--   R10033   --nostringval--   R10034   --nostringval--   R10035   --nostringval--   R10036   --nostringval--   R10037   --nostringval--   R10038   --nostringval--   R10039   --nostringval--   R1004   --nostringval--   R10040   --nostringval--   R10041   --nostringval--   R10042   --nostringval--   R10043   --nostringval--   R10044   --nostringval--   R10045   --nostringval--   R10046   --nostringval--   R10047   --nostringval--   R10048   --nostringval--   R10049   --nostringval--   R1005   --nostringval--   R10050   --nostringval--   R10051   --nostringval--   R10052   --nostringval--   R10053   --nostringval--   R10054   --nostringval--   R10055   --nostringval--   R10056   --nostringval--   R10057   --nostringval--   R10058   --nostringval--   R10059   --nostringval--   R1006   --nostringval--   R10060   --nostringval--   R10061   --nostringval--   R10062   --nostringval--   R10063   --nostringval--   R10064   --nostringval--   R10065   --nostringval--   R10066   --nostringval--   R10067   --nostringval--   R10068   --nostringval--   R10069   --nostringval--   R1007   --nostringval--   R10070   --nostringval--   R10071   --nostringval--   R10072   --nostringval--   R10073   --nostringval--   R10074   --nostringval--   R10075   --nostringval--   R10076   --nostringval--   R10077   --nostringval--   R10078   --nostringval--   R10079   --nostringval--   R1008   --nostringval--   R10080   --nostringval--   R10081   --nostringval--   R10082   --nostringval--   R10083   --nostringval--   R10084   --nostringval--   R10085   --nostringval--   R10086   --nostringval--   R10087   --nostringval--   R10088   --nostringval--   R10089   --nostringval--   R1009   --nostringval--   R10090   --nostringval--   R10091   --nostringval--   R10092   --nostringval--   R10093   --nostringval--   R10094   --nostringval--   R10095   --nostringval--   R10096   --nostringval--   R10097   --nostringval--   R10098   --nostringval--   R10099   --nostringval--   R1010   --nostringval--   R10100   --nostringval--   R10101   --nostringval--   R10102   --nostringval--   R10103   --nostringval--   R10104   --nostringval--   R10105   --nostringval--   R10106   --nostringval--   R10107   --nostringval--   R10108   --nostringval--   R10109   --nostringval--   R1011   --nostringval--   R10110   --nostringval--   R10111   --nostringval--   R10112   --nostringval--   R10113   --nostringval--   R10114   --nostringval--   R10115   --nostringval--   R10116   --nostringval--   R10117   --nostringval--   R10118   --nostringval--   R10119   --nostringval--   R1012   --nostringval--   R10120   --nostringval--   R10121   --nostringval--   R10122   --nostringval--   R10123   --nostringval--   R10124   --nostringval--   R10125   --nostringval--   R10126   --nostringval--   R10127   --nostringval--   R10128   --nostringval--   R10129   --nostringval--   R1013   --nostringval--   R10130   --nostringval--   R10131   --nostringval--   R10132   --nostringval--   R10133   --nostringval--   R10134   --nostringval--   R10135   --nostringval--   R10136   --nostringval--   R10137   --nostringval--   R10138   --nostringval--   R10139   --nostringval--   R1014   --nostringval--   R10140   --nostringval--   R10141   --nostringval--   R10142   --nostringval--   R10143   --nostringval--   R10144   --nostringval--   R10145   --nostringval--   R10146  

以下是原始PDF的详细信息(在拆分/调整大小之前):

Content Creator: Bluebeam Revu x64

Encoding Software: macOS Version 10.14.6 (Build 18G95) Quartz PDFContext

代码(Node.js):

exports.convert = function(pdfPath){
    return new Promise( (resolve,reject) => {
        //Convert pdf
        console.log('pdf2Image: Version',0.42);

        //Remove extension
        let path = pdfPath.split('.')[0];
        let splitPathTest = path.split('/');
        let outputFileName = splitPathTest[splitPathTest.length - 1] + '.png';
        let outputDirectory = splitPathTest.slice(0,splitPathTest.length - 1).join('/') + '/';
        let outputPath = outputDirectory + outputFileName;

        console.log('pdfPath',pdfPath);
        console.log('outputPath',outputPath);
        console.log('output Filename ',outputFileName);

        if (fs.existsSync(pdfPath)) {
            console.log('pdfPath exists. PDF found.');
        }else{
            console.warn('pdfPath does not exist. PDF not found.');
        }


        //============== Ghostscript
        //Conver PDF -> PNG
        console.log('gs - starting');
        gs()
            .batch()
            .nopause()
            .option('-r' + 50 * 2)
            .option('-dDownScaleFactor=2')
            .executablePath('lambda-ghostscript/bin/./gs')
            .device('png16m')
            .output(outputPath)
            .input(pdfPath)
            .exec(function (err,stdout,stderr) {
                if (!err) {
                    console.log('gs executed w/o error');            
                    console.log('stdout',stdout);            
                    console.log('stderr',stderr);
                    console.log('output saved to: ',outputPath);
                    resolve(outputPath);
                } else {
                    console.log('gs error:',err);
                    reject();
                }
            });
    })
}
a314068757 回答:Ghostscript无法将PDF转换为PNG:nostringval

错误确实是不言自明的,PDF文件以某种方式损坏。 Ghostscript尝试恢复并且无法恢复,因此它发出了一个错误并停止了(这就是您的PNG为空的原因)。请注意,这不是警告,而是错误

该错误是类型检查;因此Ghostscript遇到了一个对象,该对象的类型不适用于该操作。例如,将字符串操作数转换为算术运算,或者是期望使用字符串的数字等。

我看不到文件,而且说不完。您还没有说过Ghostscript的版本,我也不知道'lmbda-ghostscript'是什么,但是听起来不像它的规范发布。如果我是您,那么我要做的第一件事就是掌握Ghostscript源并进行构建,然后从Shell中尝试。如果失败,则可以打开一个错误报告,然后有人可以告诉您原因。

啊,显然,“ lmbda-ghostscript”是某种AWS事物。不仅如此,它非常古老。最新版本似乎是9.20,已有3年历史,并且存在一些知名的且已公开的安全漏洞。我仍然建议您尝试使用当前版本(9.50)从本地开始结束整个流程表单,如果可以的话,那么您确实需要弄清楚如何使用它。如果没有,则可以报告错误。

本文链接:https://www.f2er.com/3093024.html

大家都在问