将页面添加到现有PDF com.itextpdf.text.exceptions.InvalidPdfException:找不到PDF标题签名 [英] Adding page to existing PDF com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found
问题描述
我正在尝试使用Java 1.5使用iText 1.02b向已创建的PDF添加页面。当我将新页面添加到现有PDF时,我得到了包含的异常。以下是我们遇到问题的方法中的代码。
I am trying to add a page to an already created PDF using iText 1.02b using Java 1.5. When I add the new page to the existing PDF I get the exception that I included. Here is the code in the method we are having the issue.
public static File addSignaturePageToPDF(String fileName, InputStream fileInputStream, SignatureTemplateInfo signaturePageInfo, HttpServletRequest argRequest) throws Exception {
int splitIdx = fileName.lastIndexOf(".");
File signedFile = File.createTempFile(fileName.substring(0,splitIdx), fileName.substring(splitIdx));
SignatureModel signatureModel = SignatureHelper.getSignatureModel(signaturePageInfo.getCaseHeaders(), signaturePageInfo.getEventSubTp(), signaturePageInfo.getSignatureId(), argRequest);
byte[] signaturePdfAsBytes = SignatureHelper.createSignature(signatureModel, argRequest);
byte[] mainPdfAsBytes = getByteArrayFromInputStream(fileInputStream);
PdfReader mainPdfReader = new PdfReader(mainPdfAsBytes); << Exception here
PdfReader signaturePdfReader = new PdfReader(signaturePdfAsBytes);
例外:
com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found.
at com.itextpdf.text.pdf.PRTokeniser.checkPdfHeader(PRTokeniser.java:205)
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:496)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:189)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:178)
at icis.common.util.ConvertDocument.addSignaturePageToPDF(ConvertDocument.java:96)
at icis.cr.common.file.ViewFileAction.executeProcess(ViewFileAction.java:71)
at icis.common.action.BaseICISAction.execute(BaseICISAction.java:134)
at icis.cr.common.BaseCRAction.execute(BaseCRAction.java:41)
谢谢。
推荐答案
该异常告诉您从第一个字节获取的你的 fileInputStream
不等于'%'
,'P'
,'D'
,'F'
,' - '
,'1'
,'。'
。
The exception tells you that the first bytes obtained from your fileInputStream
aren't equal to '%'
, 'P'
, 'D'
, 'F'
, '-'
, '1'
, '.'
.
也许您要检查的文件是空的,可能无法正确读取 InputStream
,...
Maybe the file you're trying to inspect is empty, maybe the InputStream
can't be read correctly,...
许多人遇到并修复了同样的问题:
Many people before you have encountered and fixed the same problem:
- 如何解决未找到pdf标题签名错误?
- 找不到PDF标题签名,iText
- com。 itextpdf.text.exceptions.InvalidPdfException:找不到PDF标题签名
- iTextSharp异常:找不到PDF标题签名
- 找不到错误的PDF标题签名
- itextsharp multipage pdf form
- ...
- How to solve pdf header signature not found error?
- PDF header signature not found, iText
- com.itextpdf.text.exceptions.InvalidPdfException: PDF header signature not found
- iTextSharp exception: PDF header signature not found
- Error PDF header signature not found
- itextsharp multipage pdf form
- ...
您应该通过将 mainPdfAsBytes
保存到文件并检查该文件来调试代码。它真的是一个PDF文件吗? iText告诉你它不是以%PDF-1开头。
。
You should debug your code, by saving mainPdfAsBytes
to a file and by examining that file. Is it really a PDF file? iText tells you it doesn't start with %PDF-1.
.
这篇关于将页面添加到现有PDF com.itextpdf.text.exceptions.InvalidPdfException:找不到PDF标题签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!