问题
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.
来源:https://stackoverflow.com/questions/8141448/modifying-an-existing-pdf-without-creating-an-new-pdf-file