要显示mkl建议与代码合并的内容:
String filePath = System.getProperty("user.home") + "\\Documents\\"+fileName; //Test use
Document document = new Document(PageSize.A4, 72f, 72f, 72f, 72f);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter.getInstance(document, baos);
document.open();
addMetaData(document);
addImages(document);
addTitlePage(document, recipeDetails, recipeName, servings, servingSize);
document.close();
byte[] pdfData = baos.toByteArray();
return pdfData;
} catch (Exception e) {
e.printStackTrace();
}
pdfData是一个byte[](字节数组)。这可以作为实际的pdf文件直接流式传输/存储到任何地方。请记住,这是将PDF写入内存,因此如果同时执行大量大型PDF,则会出现可伸缩性问题。
我希望这有帮助。