Skip to content

Commit 229a1d0

Browse files
authored
Merge pull request #1 from SyncfusionExamples/workingbranch
Workingbranch
2 parents 5b6cf15 + be43bfd commit 229a1d0

File tree

9 files changed

+212
-2
lines changed

9 files changed

+212
-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: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,67 @@
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+
# Easy way to find the corrupted PDF files in C#
2+
3+
You might have a lot of PDF files in your disc or database; you need to find out the corrupted files and take necessary actions. But it is not possible for you to open every single file with a PDF reader to check whether it is corrupted or not.
4+
5+
To save your effort and time, [Syncfusion PDF library](https://www.syncfusion.com/pdf-framework/net/pdf-library) provides you the support to identify the corrupted PDF files using C#, VB.NET by checking whether the PDF format syntax are proper.
6+
7+
Let’s dive into the details about how to find the corrupted PDF files.
8+
9+
* [PdfDocumentAnalyzer](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Base~Syncfusion.Pdf.Parsing.PdfDocumentAnalyzer.html) class is used to find the corrupted PDF files by analyzing the PDF document structure and syntax.
10+
* [AnalyzeSyntax()](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.Pdf.Base~Syncfusion.Pdf.Parsing.PdfDocumentAnalyzer~AnalyzeSyntax.html) method of PdfDocumentAnalyzer class will invoke analysis of the PDF document structure and syntax and returns the result (an instance of [SyntaxAnalyzerResult](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Base~Syncfusion.Pdf.Parsing.SyntaxAnalyzerResult.html)).
11+
* [IsCorrupted](https://help.syncfusion.com/cr/cref_files/file-formats/Syncfusion.Pdf.Base~Syncfusion.Pdf.Parsing.SyntaxAnalyzerResult~IsCorrupted.html) property of SyntaxAnalyzerResult is used to identify whether the processed PDF file is corrupted or not.
12+
13+
Using these APIs, you can ensure that the PDF document is not corrupted and then start processing it.
14+
15+
For example:
16+
17+
1. To avoid uploading corrupted any PDF report or resume to your web applications.
18+
1. To avoid unexpected behavior or hanging when invoking PDF print programmatically.
19+
20+
The following code example will check whether the given PDF file is corrupted or not.
21+
22+
```C#
23+
using Syncfusion.Pdf;
24+
using Syncfusion.Pdf.Parsing;
25+
using System;
26+
using System.IO;
27+
using System.Text;
28+
29+
namespace find_corrupted_pdf_file_demo
30+
{
31+
class Program
32+
{
33+
static void Main(string[] args)
34+
{
35+
//Load the PDF file as stream
36+
using (FileStream pdfStream = new FileStream(“inputFile.pdf", FileMode.Open, FileAccess.Read))
37+
{
38+
//Create a new instance of PDF document syntax analyzer.
39+
PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
40+
//Analyze the syntax and return the results
41+
SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();
42+
43+
//Check whether the document is corrupted or not
44+
if (analyzerResult.IsCorrupted)
45+
{
46+
StringBuilder strBuilder = new StringBuilder();
47+
strBuilder.AppendLine("The PDF document is corrupted.");
48+
int count = 1;
49+
foreach (PdfException exception in analyzerResult.Errors)
50+
{
51+
strBuilder.AppendLine(count++.ToString() + ": " + exception.Message);
52+
}
53+
Console.WriteLine(strBuilder);
54+
}
55+
else
56+
{
57+
Console.WriteLine("No syntax error found in the provided PDF document");
58+
}
59+
analyzer.Close();
60+
}
61+
}
62+
}
63+
}
64+
65+
```
66+
67+
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)