Reputation: 2509
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
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
Reputation: 120871
Of course you can create a new pdf file, and afterwards overwriting the old file with the new one.
forceDelete(oldPdf)
moveFile(newPdf, oldPdf)
Upvotes: 1