Modifying an Existing PDF without creating an new pdf file

只愿长相守 提交于 2020-01-23 17:16:21

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!