Modifying an Existing PDF without creating an new

2019-06-09 16:18发布

问题:

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?

回答1:

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)


回答2:

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.



标签: java itext