itextsharp 创建损坏/空白 pdf 文件、i-9 文件
我一直在使用 Itextsharp 来预填充 .aspx 页面中的可填充 pdf。但是当我尝试对 i-9 文件(从国土安全部下载)执行完全相同的操作时,它给了我一个大小为 0 的文件,该文件无法打开(我收到一条错误消息,说它是一个损坏的文件) 。
我只是复制代码片段(我的解决方案中有所有必要的 Itestsharp 引用),它生成一个损坏的 pdf 文件(大小 0)
string pdfTemplate = @"c:\PDF\i-9.pdf";
string newFile = @"c:\PDF\completed_i-9.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
newFile, FileMode.Create));
pdfStamper.Close();
但是,如果我对任何其他可填充的 pdf 文件(例如 w4)执行相同的操作,它工作得很好。大家有什么想法,这里出了什么问题吗?
谢谢
I have been using Itextsharp for prefilling the fillable pdfs in .aspx pages. But when I am trying to do the exact same thing with i-9 file (downloaded from dept of homeland security), its giving me a size 0 file, which couldnt be opened (i get an error msg saying, its a corrupted file).
I am just copying the code snippet (I have all the necessary Itestsharp references in my solution) which is generating a corrupt pdf file (size 0)
string pdfTemplate = @"c:\PDF\i-9.pdf";
string newFile = @"c:\PDF\completed_i-9.pdf";
PdfReader pdfReader = new PdfReader(pdfTemplate);
PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(
newFile, FileMode.Create));
pdfStamper.Close();
However, if I do the same thing with any other fillable pdfs e.g. w4 it works perfectly fine. Any idea guys, what is going wrong in here?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊。 追踪 PDF 后,我发现了问题。它有一个空白的打开密码,但仍然具有一定的文档安全性。
iText 的安全实现还不够细粒度,无法允许某些操作,而不允许其他操作,因此当您打开受密码保护的 PDF 文件时(此 PDF 的打开密码是一个空字符串,它会自动打开),我们会抛出异常,但它仍然在那里)除非您使用所有者密码打开它,在这种情况下一切都会发生。
如果您检查日志,您会看到异常。
只有国土安全部知道所有者密码,我怀疑他们会告诉你。好消息是,其他人提出了一个更具体的“如何使用 iText 修改带有“打开”密码的文件”类型的问题,并自己解决了这个问题。
然而,使用他们的答案在法律上是有问题的,所以我不会提供链接或告诉你答案(我已经知道,并且也没有告诉其他提问者)。
Ah. Having tracked down the PDF, I see the problem. It has a blank open password, but none the less has some document security.
iText's security implementation isn't fine-grained enough (yet) to allow some things and not others, so we throw an exception when you open a password protected PDF file (the open password to this PDF is an empty string, which opens automatically, but its still there) unless you open it with the OWNER password, in which case anything goes.
If you check your logs, you'll see the exception.
Only Homeland Security knows the owner password, and I doubt they'll tell you. The good news is that someone else asked a more specific "how can I use iText to modify a file with an "open" password" type question and figured it out for themselves.
Using their answer however, is Legally Questionable, so I'm not going to provide a link or tell you the answer (which I already knew, and didn't tell the other questioner either).