簡體   English   中英

為什么我收到和IOException:創建PDF時找不到PDF標頭簽名?

[英]Why am I receiving and IOException: PDF header signature not found when creating a PDF?

我試圖用空頁創建一個PDF文件,但是代碼拋出java.io.IOException: P PDF header signature not found當我嘗試讀取臨時文件時, java.io.IOException: P PDF header signature not found 為什么?

相關代碼:

Document testDoc = new Document();
File testFile = File.createTempFile("pdfTemp", ".tmp");
String test = testFile.getName();
PdfWriter testWriter = PdfWriter.getInstance(document, new FileOutputStream(test));
testDoc.open();
for (int x=1; x<=pdfReader.getNumberOfPages(); x++){
    testWriter.setPageEmpty(false);
    testDoc.newPage();
}
testDoc.close();
PdfReader testReader = new PdfReader(test);

這可能是編碼問題。 您的代碼使用

PdfWriter testWriter = PdfWriter.getInstance(document, new FileOutputStream(test));

但是沒有在任何地方聲明document變量。 我懷疑您是要使用以下內容:

PdfWriter testWriter = PdfWriter.getInstance(testDoc, new FileOutputStream(test));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM