Preflight validate() 无效但在控制台有效
Preflight validate() is invalid but in Console valid
目前我正在使用控制台解码 Base64:
base64 -di "myfile.txt" > mypdf.pdf
哪个returns一个有效 pdf文件。
但是当我尝试这个时
DataSource dataSource = new ByteArrayDataSource(
new ByteArrayInputStream(Base64.getDecoder().decode(pdf.getEncodedContent())));
PreflightParser parser = new PreflightParser(dataSource);
parser.parse();
try (PreflightDocument document = parser.getPreflightDocument()) {
document.validate();
return !document.isEncrypted();
}
catch (ValidationException ex) {
return false;
}
我总是收到 validationException(pdf 无效)。
我想我需要更改配置。我已经尝试过以下方法,但似乎没有帮助:
PreflightConfiguration config = document.getContext().getConfig();
config.setLazyValidation(true);
堆栈跟踪:
test.pdf 无效:无法解析字体元数据,原因是:例外的 xpacket 'end' 属性(必须存在并放在第一位)
这张票我解决了。有兴趣者:
验证工作完美,pdf 文件不正确,即使 reader / 浏览器可以打开它(pdf reader/browser 没有显示任何警告或错误消息)。
尝试将您的 pdf 转换为 二进制文本 并至少检查您的前两行和最后一行是否 'pdf default' 如:
%PDF-1.7
%µµµµ
...
%%EOF
如果不是,则pdf生成错误,验证将失败。
目前我正在使用控制台解码 Base64:
base64 -di "myfile.txt" > mypdf.pdf
哪个returns一个有效 pdf文件。
但是当我尝试这个时
DataSource dataSource = new ByteArrayDataSource(
new ByteArrayInputStream(Base64.getDecoder().decode(pdf.getEncodedContent())));
PreflightParser parser = new PreflightParser(dataSource);
parser.parse();
try (PreflightDocument document = parser.getPreflightDocument()) {
document.validate();
return !document.isEncrypted();
}
catch (ValidationException ex) {
return false;
}
我总是收到 validationException(pdf 无效)。
我想我需要更改配置。我已经尝试过以下方法,但似乎没有帮助:
PreflightConfiguration config = document.getContext().getConfig();
config.setLazyValidation(true);
堆栈跟踪:
test.pdf 无效:无法解析字体元数据,原因是:例外的 xpacket 'end' 属性(必须存在并放在第一位)
这张票我解决了。有兴趣者:
验证工作完美,pdf 文件不正确,即使 reader / 浏览器可以打开它(pdf reader/browser 没有显示任何警告或错误消息)。
尝试将您的 pdf 转换为 二进制文本 并至少检查您的前两行和最后一行是否 'pdf default' 如:
%PDF-1.7
%µµµµ
...
%%EOF
如果不是,则pdf生成错误,验证将失败。