Ghostscript无法将PDF转换为PNG:nostringval
尝试将PDF转换为PNG时,我遇到以下Ghostscript无法将PDF转换为PNG:nostringval,pdf,pdf-generation,ghostscript,Pdf,Pdf Generation,Ghostscript,尝试将PDF转换为PNG时,我遇到以下stdout错误。有人知道PDF文件有什么问题吗 这个问题只影响某些PDF文件,而这个特定的PDF实际上是从一个更大的PDF中分割出来的,并通过GhostScript进行了大小调整和压缩 命令运行时不会返回错误,但标准输出具有以下警告,并且输出PNG文件存在,但维度为0和0 stdout: **** Error reading a content stream. The page may be incomplete. Out
stdout
错误。有人知道PDF文件有什么问题吗
这个问题只影响某些PDF文件,而这个特定的PDF实际上是从一个更大的PDF中分割出来的,并通过GhostScript进行了大小调整和压缩
命令运行时不会返回错误,但标准输出具有以下警告,并且输出PNG文件存在,但维度为0和0
stdout:
**** 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
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();
}
});
})
}
以下是原始PDF的详细信息(在拆分/调整大小之前):
内容创建者:Bluebeam Revu x64
编码软件:macOS版本10.14.6(Build 18G95)Quartz PDFContext
代码(Node.js):
**** 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
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();
}
});
})
}
这个错误其实是不言自明的,PDF文件在某种程度上被破坏了。Ghostscript试图恢复,但无法恢复,因此发出错误并停止(这就是PNG为空的原因)。请注意,这不是警告,而是错误 错误是一个类型检查;因此,Ghostscript遇到了一个类型不适合该操作的对象。例如,算术运算的字符串操作数,或预期为字符串的数字等 没有看到文件,我只能说更多。你还没有说Ghostscript的版本是什么,我也不知道“lmbda Ghostscript”是什么,但它听起来不像是标准版本。如果我是你,我要做的第一件事就是获取Ghostscript源代码并构建它,然后从shell中尝试。如果失败了,那么你可以打开一个bug报告,有人可以告诉你原因
啊,显然“lmbda鬼脚本”是一种AWS的东西。不仅如此,它还很古老。最新的版本似乎是9.20,已有三年历史,存在一些众所周知和公开的安全漏洞。我仍然建议您尝试使用当前版本(9.50)从开始到结束的整个流程,如果这样做有效,那么您确实需要弄清楚如何使用它。如果没有,您可以报告错误。感谢您的见解。在转换为PNG之前第一次调整pdf的大小时,我可以通过更改这3个参数来解决此问题:
-dCompatibilityLevel=1.3
-dEmbedAllFonts=true-dPDFSETTINGS=/ebook如果要将其呈现为PNG,为什么还要创建新的pdf文件?PDFSETTINGS开关改变的方式不止一件事,即一次改变许多配置参数。这些都记录在我决定尝试之前实际引用了该表中。我调整PDF的大小是因为我需要1)压缩PDF 2)将其调整到所需的尺寸,然后根据需要单独调整,有时我需要将其转换为不同用例的图像。是否有一种工具可以在Mac上用于检查PDF文件的错误?Adobe Acrobat Pro(飞行前工具)、VeraPDF(专用PDF一致性工具),Ghostscript将告诉您PDF文件是否存在问题(并尝试修复或忽略它们),毫无疑问还有其他问题。