0
我期望以下代碼用適當的元數據創建一個空白PDF。相反,我最終得到一個0kb的pdf文件,當然Acrobat不會打開。我已經瀏覽了http://www.avajava.com/tutorials/lessons/how-do-i-write-to-a-pdf-file-using-itext.html和http://www.java4s.com/core-java/creating-pdf-with-java-and-itext-generating-pdf-using-java-example/。通過iText創建帶有0kb和無內容的.pdf文件
我似乎正在做這個正確的...但是...不是。
public class BuildSheet {
JobSetEntity jobSetEntity;
public BuildSheet(JobSetEntity jobSetEntity) {
this.jobSetEntity = jobSetEntity;
}
public boolean generate(File destinationFile) {
try {
Document document = new Document();
FileOutputStream stream = new FileOutputStream(destinationFile);
PdfWriter.getInstance(document, stream);
document.open();
addMetaData(document);
document.close();
stream.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
private void addMetaData(Document document) {
document.addAuthor(ApplicationContextProvider.getProperty("application.name"));
document.addCreator(ApplicationContextProvider.getProperty("application.name"));
document.addTitle("Build sheet for JobSet #"+jobSetEntity.getId());
document.addLanguage("EN");
}
}