未找到PDF标题签名,iText

时间:2012-09-20 18:03:12

标签: pdf itext

您好我正在尝试读取由servlet上传的PDF文件。

这是代码

//out = byte array
out = readInItem(item);
fileToUpload = new ByteArrayInputStream(out.toByteArray());

Map<String, AcroFields.Item> pdfBoxNames = new HashMap<String, AcroFields.Item>();
PdfReader reader = new PdfReader(fileToUpload);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PdfStamper stamper = new PdfStamper(reader, os);
AcroFields acroFields = stamper.getAcroFields();
pdfBoxNames = acroFields.getFields();

我的pdf就像这个%PDF-1.6

一样开始

错误讯息是 java.io.IOException:找不到PDF标题签名。

1 个答案:

答案 0 :(得分:1)

面对同样的异常!确保您已为此设置了TableHeader和作者PageEvent。我刚添加它们,这个例外消失了!希望它能帮到你

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
TableHeader includeHeader = new TableHeader();
writer.setPageEvent(includeHeader);