2

您好我正在尝试阅读 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 header signature not found。

4

1 回答 1

1

面临同样的异常!确保你已经包含了TableHeader和一个作家PageEvent集。我只是把它们加起来,这个异常就消失了!希望对你有帮助

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filePath));
TableHeader includeHeader = new TableHeader();
writer.setPageEvent(includeHeader);
于 2013-09-10T17:00:38.850 回答