IronPDF 中 PDF 解析错误的故障排除
2022年一月19日
更新 2024年十月20日
This article was translated from English: Does it need improvement?
TranslatedView the article in English
在使用IronPDF解析PDF文件时,您可能会遇到以下异常:
Unhandled exception. System.IO.IOException: PDF can not be opened as a PDF. May be an incorrect file type or a password is required.
Please check file for corruption or validity by a 3rd party at: https://www.pdf-online.com/osa/validate.aspx
此错误通常发生在使用以下代码将 PDF 文档加载到PdfDocument
对象时:
var pdf = PdfDocument.FromFile("Test.pdf");
var pdf = PdfDocument.FromFile("Test.pdf");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText $csharpLabel
可能的原因
- 密码保护的PDF
- 所有者密码:出现此异常的最常见原因是PDF受所有者密码保护。 当PDF设置了所有者密码时,它会限制某些操作,例如编辑或复制。 要加载此文档,您必须提供密码。
- 损坏的PDF
- PDF文件可能已损坏或不是有效的PDF格式。 损坏的文件可能会导致IronPDF在解析过程中失败。
解决方案
处理受密码保护的PDF
如果您知道 PDF 的密码,可以将其传递给
PdfDocument.FromFile()
方法:
var pdf = PdfDocument.FromFile("test.pdf", "ownerpassword");
var pdf = PdfDocument.FromFile("test.pdf", "ownerpassword");
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText $csharpLabel
您也可以通过检查Adobe Acrobat中的文件属性来验证文件是否受密码保护。 有关识别PDF安全状态的更多信息,请参阅这篇文章。