无效pdfexception未找到pdf标头签名 [英] Invalidpdfexception pdf header signature not found

查看:3686
本文介绍了无效pdfexception未找到pdf标头签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以读取 pdf 文件。该代码在以下行中失败:

I have some code that reads pdf files. The code fails at the line :

iTextSharp.text.pdf.PRTokeniser.CheckPdfHeader() at
                                 iTextSharp.text.pdf.PdfReader.ReadPdf()

我从其他条目中得知此问题来自某些无效格式化为pdf。但是我不能告诉我的用户重做他们的pdf。有没有其他方法来解决这个问题,即使出现这个问题,还是可以读取pdf吗?

I know from other entries that this issue is coming from some invalid formatting in the pdf. However I'm not in a position to tell my users to redo their pdfs. Is there some other way around this issue, that can allow reading of the pdf despite this problem?

推荐答案

如果文件没有'从%PDF开始 - 然后没有什么可修复的:文件不是PDF文件。

If a file doesn't start with %PDF- then there's nothing to fix: the file isn't a PDF file.

然而,可能还有另一个问题:也许你正试图在创建InputStream时,由于某些问题,访问长度为零的文件。我看到这种情况发生的另一个背景是从服务器加载的PDF,其中服务器以HTML而不是PDF文件返回404消息; - )

However, there may be another problem: maybe you're trying to access a file that has zero length due to some problem while creating the InputStream. Another context in which I've seen this happen, is a PDF loaded from a server, where the server returned a 404 message in HTML instead of a PDF file ;-)

每当发生异常时,您应该将字节存储在某处,并检查它们。没有这些字节,没有人能够给你有用的建议。

Whenever that exception happens, you should store the bytes somewhere, and examine them. Without those bytes, nobody will be able to give you useful advice.

这篇关于无效pdfexception未找到pdf标头签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆