我正在使用PDFBox從我的webapp中提取數據並將其放入PDF中。我有一個方法可以在每個PDF頁面上繪製標題。但是,當我將圖像添加到每個頁面時,文檔耗盡內存。我想知道是否有人對解決方案有任何想法?這裏是我的drawHeader方法:PDFBox添加圖像時內存不足
公共靜態無效drawHeader(PDDocument DOC,PDPage頁,PDPageContentStream contentStream,INT []列寬,INT PAGENUMBER)拋出IOException異常{
contentStream.beginText();
PDFont font = PDType1Font.HELVETICA_BOLD;
contentStream.setFont(font, 24);
contentStream.moveTextPositionByAmount(50, 750);
contentStream.drawString("Producer License Report");
contentStream.endText();
contentStream.beginText();
contentStream.moveTextPositionByAmount(550, 750);
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 8);
contentStream.drawString("Page " + pageNumber);
contentStream.endText();
contentStream.drawLine(50, 740, 340, 740);
contentStream.drawLine(16, 680, 595, 680);
List<String> headerList = new LinkedList<String>();
headerList.add("NPN");
headerList.add("First Name");
headerList.add("Last Name");
headerList.add("Suffix");
headerList.add("License State");
headerList.add("Resident State");
headerList.add("License Number");
contentStream.setFont(PDType1Font.HELVETICA_BOLD, 9);
float textx = 15;
float texty = 685;
InputStream in = new FileInputStream(new File("logo.jpg"));
PDJpeg img = new PDJpeg(doc, in);
contentStream.drawImage(img, 375, 720);
for (int i = 0; i < headerList.size(); i++) {
String text = headerList.get(i);
contentStream.beginText();
contentStream.moveTextPositionByAmount(textx, texty);
contentStream.drawString(text);
contentStream.endText();
textx += (columnWidths[i] * 6.5);
}
}
忘了提,圖像只有6 KB有同樣的問題 – FrenchMyToast
IM,我懷疑它可能是圖像不適合在PDF頁面由於其大小 –