How to Find Corrupted PDF Files in C# Easily | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (182).NET Core  (28).NET MAUI  (231)Angular  (117)ASP.NET  (49)ASP.NET Core  (81)ASP.NET MVC  (87)Azure  (42)Black Friday Deal  (1)Blazor  (242)BoldSign  (14)DocIO  (24)Essential JS 2  (110)Essential Studio  (201)File Formats  (74)Flutter  (138)JavaScript  (227)Microsoft  (122)PDF  (84)Python  (1)React  (107)Streamlit  (1)Succinctly series  (131)Syncfusion  (985)TypeScript  (33)Uno Platform  (3)UWP  (3)Vue  (46)Webinar  (53)Windows Forms  (59)WinUI  (72)WPF  (164)Xamarin  (159)XlsIO  (38)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (11)Business intelligence  (55)Button  (4)C#  (164)Chart  (152)Chart of the week  (61)Cloud  (16)Company  (440)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (74)Development  (692)Doc  (7)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (7)Essential Tools  (13)Excel  (43)Extensions  (31)File Manager  (8)Gantt  (22)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (526)Mobile MVC  (9)OLAP server  (2)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (46)Performance  (13)PHP  (2)PivotGrid  (5)Predictive Analytics  (6)Report Server  (3)Reporting  (8)Reporting / Back Office  (9)Rich Text Editor  (12)Road Map  (12)Scheduler  (54)Security  (5)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (32)Solution Services  (4)Spreadsheet  (11)SQL  (15)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (420)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (643)What's new  (353)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
How to Find Corrupted PDF Files in C# Easily

How to Find Corrupted PDF Files in C# Easily

You might have a lot of PDF files on your disc or database; to automate or process the PDF files, you need to find any corrupted files and take necessary actions. But it’s tedious for anyone to open every single file with a PDF reader to check whether it is corrupt or not.

Say goodbye to tedious PDF tasks and hello to effortless document processing with Syncfusion's PDF Library.

To save effort and time, Syncfusion PDF Library provides you support to identify corrupted PDF files using C# or VB.NET by checking the PDF format syntax from the 2019 Volume 3 beta release.

Let’s dive into the details of how to find corrupted PDF files:

  • PdfDocumentAnalyzer class can be used to find corrupted PDF files by analyzing the PDF document structure and syntax.
  • AnalyzeSyntax() method of PdfDocumentAnalyzer class will initiate analysis of the PDF document structure and syntax and return the result (an instance of SyntaxAnalyzerResult).
  • IsCorrupted property of SyntaxAnalyzerResult is used to identify whether the processed PDF file is corrupted or not.

Using these APIs, you can ensure that a PDF document is not corrupted and start processing it.

For example:

  • To avoid uploading any corrupted PDF report or resume to your web applications.
  • To avoid unexpected behavior or application hanging when invoking PDF print programmatically.

The following C# code example will check whether the given PDF file is corrupted or not.

static void Main(string[] args)
   //Load the PDF file as stream.
   using (FileStream pdfStream = new FileStream(“inputFile.pdf", FileMode.Open, FileAccess.Read))
        //Create a new instance of PDF document syntax analyzer.
        PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
        //Analyze the syntax and return the results.
        SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();

        //Check whether the document is corrupted or not.
        if (analyzerResult.IsCorrupted)
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.AppendLine("The PDF document is corrupted.");
            int count = 1;
            foreach (PdfException exception in analyzerResult.Errors)
                strBuilder.AppendLine(count++.ToString() + ": " + exception.Message);
            Console.WriteLine("No syntax error found in the provided PDF document");

Embark on a virtual tour of Syncfusion's PDF Library through interactive demos.

Open and repair PDF file

Syncfusion PDF Library can repair basic cross-reference offset issues in PDF files and open them for further processing. This is done using the overloads of PdfLoadedDocument constructors with openAndRepair parameters.

The following code example will repair the basic cross-reference offset issues and open the PDF document.

static void Main(string[] args)
    using (FileStream pdfStream = new FileStream(@"input.pdf", FileMode.Open, FileAccess.Read))
        //load the corrupted document by setting the openAndRepair flag to true to repair the document.
        PdfLoadedDocument loadedPdfDocument = new PdfLoadedDocument(pdfStream, true);

        //Do PDF processing.

        //Save the document.
        using (FileStream outputStream = new FileStream(@"result.pdf", FileMode.Create))
        //Close the document.

Note: It cannot repair complex document corruption.

You can use these PDF corruption validation and repair APIs in .NET Framework, .NET Core, UWP, and Xamarin applications.

GitHub Sample

You can download the samples to check for the corrupted PDF files and repair the PDF file from this location.

Join thousands of developers who rely on Syncfusion for their PDF needs. Experience the difference today!


As you can see, Syncfusion PDF Library provides APIs to find out whether a PDF file is corrupt or not by analyzing its structure and syntax. It also provides APIs to repair basic cross-reference offset-level corruption in PDF files. You can use these to avoid unexpected behavior while processing the PDF files in your .NET applications.

If you are new to our PDF Library, we highly recommend you to follow our Getting Started guide.

If you’re already a Syncfusion user, you can download the product setup here. Otherwise, you can download a free, 30-day trial here.

Have any questions or require clarification about these features? Please let us know in the comments below. You can also contact us through our support forum, Direct-Trac or feedback portal. We are happy to assist you!

Related Blogs

If you liked this blog post, we think you’ll also enjoy the following related blog posts:


Share this post:

Comments (1)

[…] How to Find Corrupted PDF Files in C# Easily (Vijaya Kumar) […]

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed