1 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個(gè)贊
使用接受 的重載保存方法,并使用 。OutputStreamByteArrayOutputStream
public static void main(String[] args) throws IOException
{
String formTemplate = "myFormPdf.pdf";
try (PDDocument pdfDocument = PDDocument.load(new File(formTemplate)))
{
PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
if (acroForm != null)
{
PDTextField field = (PDTextField) acroForm.getField( "sampleField" );
field.setValue("Text Entry");
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pdfDocument.save(baos);
byte[] pdfBytes = baos.toByteArray(); // PDF Bytes
}
}
添加回答
舉報(bào)