Reid Mac
Reid Mac

Reputation: 2509

Modifying an Existing PDF without creating an new pdf file

Using iText, I am wanting to open a PDF file, add some more pages with text to it, and then close it. I have found some questions like this on here, but all require creating a new PDF file. Is there any way to read in the pdf file and modify it and then overwrite the original?

Upvotes: 0

Views: 1829

Answers (2)

gigadot
gigadot

Reputation: 8969

Of course, you can always overwrite a file (if it is not locked by the OS) by writing to the whole content to the FileOutputStream. You cannot partially write to part of a file unless it is to append data at the end of file. This is limited by the operating system itself so there is nothing you can do.

Upvotes: 1

Ralph
Ralph

Reputation: 120871

Of course you can create a new pdf file, and afterwards overwriting the old file with the new one.

Commons Apache File Util

forceDelete(oldPdf)
moveFile(newPdf, oldPdf)

Upvotes: 1

Related Questions