Skip to content

Commit b837cbf

Browse files
Added sample for find a corrupted PDF file.
1 parent 5b6cf15 commit b837cbf

File tree

9 files changed

+190
-2
lines changed

9 files changed

+190
-2
lines changed
22.9 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<RootNamespace>Open_repair_PDF_file_demo</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="17.3.0.9-beta" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29215.179
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Open-repair-PDF-file-demo", "Open-repair-PDF-file-demo.csproj", "{376A64EF-E253-453C-8B3A-BF537D9E4E99}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{376A64EF-E253-453C-8B3A-BF537D9E4E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{376A64EF-E253-453C-8B3A-BF537D9E4E99}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{376A64EF-E253-453C-8B3A-BF537D9E4E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{376A64EF-E253-453C-8B3A-BF537D9E4E99}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0E6FAB31-44B4-4A1A-AFDC-EAB94D9238A5}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System;
2+
using System.IO;
3+
using Syncfusion.Pdf.Parsing;
4+
5+
namespace Open_repair_PDF_file_demo
6+
{
7+
class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (FileStream pdfStream = new FileStream(@"..\..\..\Data\input.pdf", FileMode.Open, FileAccess.Read))
12+
{
13+
//load the corrupted document by setting the openAndRepair flag as true to repair the document
14+
PdfLoadedDocument loadedPdfDocument = new PdfLoadedDocument(pdfStream, true);
15+
16+
//Do PDF processing
17+
18+
//Save the document.
19+
using (FileStream outputStream = new FileStream(@"result.pdf", FileMode.Create))
20+
{
21+
loadedPdfDocument.Save(outputStream);
22+
}
23+
//Close the document
24+
loadedPdfDocument.Close(true);
25+
}
26+
}
27+
}
28+
}

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,45 @@
1-
# find-corrupted-pdf-files-csharp-vb-net
2-
This repo contains the examples about how to find the corrupted PDF files using Syncfusion's C# PDF library.
1+
# How to find the corrupted PDF files in C# using Syncfusion PDF
2+
3+
Syncfusion PDF Library provides support to find the existing PDF document corruptions and provides the corruption details
4+
5+
## Finding the corrupted PDF document
6+
7+
Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/) NuGet package as a reference to your .NET Core applications from [NuGet.org](https://www.nuget.org/).
8+
9+
The following namespace should be included in the application:
10+
11+
```C#
12+
using Syncfusion.Pdf;
13+
using Syncfusion.Pdf.Parsing;
14+
```
15+
16+
17+
The following code snippet explains how to find the corrupted PDF document.
18+
19+
```C#
20+
using (FileStream pdfStream = new FileStream(@"..\..\..\PDF-Files\barcode.pdf", FileMode.Open, FileAccess.Read))
21+
{
22+
//Create a new instance of PDF document syntax analyzer.
23+
PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
24+
//Analyze the syntax and return the results
25+
SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();
26+
27+
//Check whether the document is corrupted or not
28+
if (analyzerResult.IsCorrupted)
29+
{
30+
StringBuilder strBuilder = new StringBuilder();
31+
strBuilder.AppendLine("The PDF document is corrupted.");
32+
int count = 1;
33+
foreach (PdfException exception in analyzerResult.Errors)
34+
{
35+
strBuilder.AppendLine(count++.ToString() + ": " + exception.Message);
36+
}
37+
Console.WriteLine(strBuilder);
38+
}
39+
else
40+
{
41+
Console.WriteLine("No syntax error found in the provided PDF document");
42+
}
43+
analyzer.Close();
44+
}
45+
```
22.9 KB
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Syncfusion.Pdf;
2+
using Syncfusion.Pdf.Parsing;
3+
using System;
4+
using System.IO;
5+
using System.Text;
6+
7+
namespace find_corrupted_pdf_file_demo
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
//Load the PDF file as stream
14+
using (FileStream pdfStream = new FileStream(@"..\..\..\PDF-Files\input-open-repair.pdf", FileMode.Open, FileAccess.Read))
15+
{
16+
//Create a new instance of PDF document syntax analyzer.
17+
PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
18+
//Analyze the syntax and return the results
19+
SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();
20+
21+
//Check whether the document is corrupted or not
22+
if (analyzerResult.IsCorrupted)
23+
{
24+
StringBuilder strBuilder = new StringBuilder();
25+
strBuilder.AppendLine("The PDF document is corrupted.");
26+
int count = 1;
27+
foreach (PdfException exception in analyzerResult.Errors)
28+
{
29+
strBuilder.AppendLine(count++.ToString() + ": " + exception.Message);
30+
}
31+
Console.WriteLine(strBuilder);
32+
}
33+
else
34+
{
35+
Console.WriteLine("No syntax error found in the provided PDF document");
36+
}
37+
analyzer.Close();
38+
}
39+
}
40+
}
41+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
<RootNamespace>find_corrupted_pdf_file_demo</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Syncfusion.Pdf.Net.Core" Version="17.3.0.9-beta" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29215.179
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "find-corrupted-pdf-file-demo", "find-corrupted-pdf-file-demo.csproj", "{C68DBB07-DFA1-4577-B68B-AC5DD96EDE25}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C68DBB07-DFA1-4577-B68B-AC5DD96EDE25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{C68DBB07-DFA1-4577-B68B-AC5DD96EDE25}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{C68DBB07-DFA1-4577-B68B-AC5DD96EDE25}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{C68DBB07-DFA1-4577-B68B-AC5DD96EDE25}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {08941112-DCF5-4CC9-BDA8-86AB29CA3C71}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)