0
votes

I have following Code (IText 7):

PdfDocument pdfDoc = new PdfDocument(new PdfReader(url), new PdfWriter(urlTemp));
.....
pdfDoc.Close();

My Problem is, I would like to save the pdfDoc only, but not close. I like to save the changes when the user click on the button "Save". Then he can work so on, but itext says the document is closed. That´s logical for me, because i am call Close(). But exists maybe an Solution, that the document is only save or can I reopen the document?

Thank you!

1

1 Answers

4
votes

The call to close() ensures that the urlTemp OutputStream contains a complete PDF. Without it parts of the PDF may still be in memory and not flushed to the output stream, and since PDFs are binary files this will lead to a corrupted PDF.

You will need to call close(), allow the user to edit and save the file, and then construct a new PdfDocument object with the contents of the edited file.