Good afternoon. I’m using Aspose.PDF version 25.7.0. I have a PDF 1.7 file and want to programmatically create another PDF document based on it:
csharp
using Aspose.Pdf;
class Program
{
static void Main()
{
var pdfDoc = new Document(@“D:\broken.pdf”);
}
}
However, an error is thrown:
image.png (13.7 KB)
The original PDF file also fails to open in Acrobat Reader with a similar error. Nevertheless, the file opens fine in a web browser and, for example, in FoxitReader.
@directum
Good afternoon! The error message “The root object missing or invalid” typically indicates that the PDF file you are trying to open is corrupted or not compliant with PDF standards. Since the original PDF file also fails to open in Acrobat Reader, it confirms that the file is likely damaged.
Cause: The PDF file is corrupted, which prevents it from being opened in multiple readers.
Solution: Here are some steps you can take to address this issue:
-
Check the PDF File: Ensure that the PDF file is not corrupted. You can try opening it in different PDF readers (like Foxit Reader, which you mentioned works) to confirm its integrity.
-
Repair the PDF: If the file is indeed corrupted, you can use Aspose.PDF to attempt to repair it. Here’s a simple code snippet to help you with that:
using Aspose.Pdf;
using Aspose.Pdf.Facades;
class Program
{
static void Main()
{
string inputFilePath = @"D:\broken.pdf";
string outputFilePath = @"D:\repaired.pdf";
// Create a PdfFileEditor instance
PdfFileEditor pdfEditor = new PdfFileEditor();
// Attempt to repair the PDF
pdfEditor.Repair(inputFilePath, outputFilePath);
}
}
-
Update Aspose.PDF: Since you are using version 25.7.0, consider updating to the latest version of Aspose.PDF. Newer versions often include bug fixes and improvements that might resolve your issue.
-
Check for Known Issues: Review the Aspose documentation or forums for any known issues related to the version you are using.
Next Steps: Please try the above steps and let me know if the issue persists or if you have any further questions. I am here to help!