pdf签名无效红叉,无效pdfexception未找到pdf标头签名

博主使用iTextSharp读取PDF文件时,代码在特定行失败,已知问题源于PDF格式无效,但无法让用户重新生成PDF。解决方案指出,若文件不以%PDF-开头则非PDF文件;也可能是创建InputStream时文件长度为零,或服务器返回HTML而非PDF。出现异常时应存储字节并检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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()

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?

解决方案

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

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值