IronPDF 中 PDF 解析錯誤故障排除
使用 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物件中時,通常會發生此錯誤:
// Attempt to load a PDF document from a file
var pdf = PdfDocument.FromFile("Test.pdf");// Attempt to load a PDF document from a file
var pdf = PdfDocument.FromFile("Test.pdf");' Attempt to load a PDF document from a file
Dim pdf = PdfDocument.FromFile("Test.pdf")可能的原因
1.受密碼保護的PDF
-所有者密碼:出現此例外情況的最常見原因是 PDF 受所有者密碼保護。 當 PDF 檔案設定了所有者密碼時,會限制某些操作,例如編輯或複製。 若要載入此類文檔,您必須提供密碼。
2.損壞的PDF文件
- PDF 檔案可能已損壞或不是有效的 PDF 格式。 文件損壞會導致 IronPDF 在解析過程中失敗。
解決方案
1.處理受密碼保護的PDF文件
如果您知道 PDF 檔案的密碼,您可以將其傳遞給PdfDocument.FromFile()方法:
// Load a password-protected PDF by specifying the owner password
var pdf = PdfDocument.FromFile("test.pdf", "ownerpassword");// Load a password-protected PDF by specifying the owner password
var pdf = PdfDocument.FromFile("test.pdf", "ownerpassword");' Load a password-protected PDF by specifying the owner password
Dim pdf = PdfDocument.FromFile("test.pdf", "ownerpassword")您也可以透過在 Adobe Acrobat 中檢查檔案屬性來驗證檔案是否受密碼保護。 有關識別 PDF 安全狀態的更多信息,請參閱本文。
2.處理損壞的PDF文件
若要檢查 PDF 檔案是否損壞,請使用第三方驗證工具。 如果檔案已損壞,IronPDF 將無法解析它。
如果這些故障排除步驟未能解決問題,請提交工程支援請求,以便我們的支援工程師提供進一步的協助。






