I am updating the values of an editable PDF using PDFBox. Instead of saving, I want to return stream. I saved it, it works all fine. Now I want to return byte[] instead of saving it.
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");
}
pdfDocument.save("updatedPdf.pdf"); // instead of this I need STREAM
}
}
I tried SerializationUtils.serialize but it fails to serialize it.
Failed to serialize object of type: class org.apache.pdfbox.pdfmodel.PDDcoumemt