我正在使用Android 版 PdfBox来将数据附加到PDF文件中。
要附加的数据
public byte [] prerparePdfToAppend() {
final PDDocument document = new PDDocument();
final PDPage sourcePage = new PDPage();
document.addPage(sourcePage);
PDPageContentStream contentStream = new PDPageContentStream(document, sourcePage);
contentStream.beginText();
contentStream.setFont(PDType1Font.COURIER, 12);
contentStream.showText("Name: " + firstName + " " + lastName);
contentStream.newLine();
...
contentStream.endText();
contentStream.close();
output = new ByteArrayOutputStream();
document.save(output);
document.close();
byte [] bytesToAppend = new byte[output.size()];
output.write(bytes);
output.close();
return bytesToAppend;
}
Run Code Online (Sandbox Code Playgroud)
合并代码(简化)
public void merge (String assetFileName) {
byte [] toAppendPdf = prerparePdfToAppend();
PDFMergerUtility mergerUtility = …Run Code Online (Sandbox Code Playgroud)