Skip to content

Commit af96d53

Browse files
authored
Merge pull request #67 from SyncfusionExamples/WPF-883304_1
883304 - How to load the document which contain fundamental syntax errors.
2 parents 2cfa657 + 8d8e81b commit af96d53

File tree

5 files changed

+99
-62
lines changed

5 files changed

+99
-62
lines changed

DisplayPDF_fundamental_syntax_errors/LoadFundamentalSyntaxErrorDocument.csproj

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
34
<PropertyGroup>
45
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
56
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
67
<ProjectGuid>{EBAB83B0-807A-48CE-A538-28DF711C35C4}</ProjectGuid>
78
<OutputType>WinExe</OutputType>
89
<RootNamespace>SimpleSample</RootNamespace>
910
<AssemblyName>SimpleSample</AssemblyName>
10-
<TargetFramework>net48</TargetFramework>
11+
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
1112
<FileAlignment>512</FileAlignment>
1213
<WarningLevel>4</WarningLevel>
1314
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
1415
<Deterministic>true</Deterministic>
15-
<LangVersion>latest</LangVersion>
16-
<UseWPF>true</UseWPF>
16+
<TargetFrameworkProfile />
1717
</PropertyGroup>
1818
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1919
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,10 +35,66 @@
3535
<WarningLevel>4</WarningLevel>
3636
</PropertyGroup>
3737
<ItemGroup>
38-
<PackageReference Include="CommunityToolkit.Mvvm" Version="*" />
38+
<Reference Include="System" />
3939
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Drawing" />
42+
<Reference Include="System.Xml" />
43+
<Reference Include="Microsoft.CSharp" />
44+
<Reference Include="System.Core" />
45+
<Reference Include="System.Xml.Linq" />
46+
<Reference Include="System.Data.DataSetExtensions" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xaml">
49+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
50+
</Reference>
51+
<Reference Include="WindowsBase" />
52+
<Reference Include="PresentationCore" />
53+
<Reference Include="PresentationFramework" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<ApplicationDefinition Include="App.xaml">
57+
<Generator>MSBuild:Compile</Generator>
58+
<SubType>Designer</SubType>
59+
</ApplicationDefinition>
60+
<Page Include="MainWindow.xaml">
61+
<Generator>MSBuild:Compile</Generator>
62+
<SubType>Designer</SubType>
63+
</Page>
64+
<Compile Include="App.xaml.cs">
65+
<DependentUpon>App.xaml</DependentUpon>
66+
<SubType>Code</SubType>
67+
</Compile>
68+
<Compile Include="MainWindow.xaml.cs">
69+
<DependentUpon>MainWindow.xaml</DependentUpon>
70+
<SubType>Code</SubType>
71+
</Compile>
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="Properties\AssemblyInfo.cs">
75+
<SubType>Code</SubType>
76+
</Compile>
77+
<Compile Include="Properties\Resources.Designer.cs">
78+
<AutoGen>True</AutoGen>
79+
<DesignTime>True</DesignTime>
80+
<DependentUpon>Resources.resx</DependentUpon>
81+
</Compile>
82+
<Compile Include="Properties\Settings.Designer.cs">
83+
<AutoGen>True</AutoGen>
84+
<DependentUpon>Settings.settings</DependentUpon>
85+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
86+
</Compile>
87+
<EmbeddedResource Include="Properties\Resources.resx">
88+
<Generator>ResXFileCodeGenerator</Generator>
89+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
90+
</EmbeddedResource>
91+
<None Include="Properties\Settings.settings">
92+
<Generator>SettingsSingleFileGenerator</Generator>
93+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
94+
</None>
4095
</ItemGroup>
4196
<ItemGroup>
4297
<None Include="App.config" />
4398
</ItemGroup>
44-
</Project>
99+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
100+
</Project>

DisplayPDF_fundamental_syntax_errors/LoadFundamentalSyntaxErrorDocument_NET.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="CommunityToolkit.Mvvm" Version="*" />
1312
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
1413
</ItemGroup>
1514

DisplayPDF_fundamental_syntax_errors/MainWindow.xaml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,19 @@
77
xmlns:syncfusion="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
88
mc:Ignorable="d"
99
Title="MainWindow" WindowState="Maximized">
10-
<Window.DataContext>
11-
<local:MainWindowViewModel />
12-
</Window.DataContext>
1310
<Grid>
1411
<Grid.RowDefinitions>
1512
<RowDefinition Height="Auto" />
1613
<RowDefinition />
1714
</Grid.RowDefinitions>
1815
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center"
1916
Margin="12">
20-
<Button Content="Open"
21-
Command="{Binding OpenPDFFileCommand}"
17+
<Button Content="Open"
2218
Width="50"
23-
Height="30"/>
19+
Height="30"
20+
Click="Button_Click"/>
2421
</StackPanel>
2522
<syncfusion:PdfViewerControl Grid.Row="1"
26-
Margin="12"
27-
ZoomMode="FitPage"
28-
ItemSource="{Binding PdfDocument, UpdateSourceTrigger=PropertyChanged}" />
23+
x:Name="pdfViewer" />
2924
</Grid>
3025
</Window>
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using System.Windows;
1+
using Microsoft.Win32;
2+
using Syncfusion.Pdf.Parsing;
3+
using System;
4+
using System.IO;
5+
using System.Windows;
26

37
namespace LoadFundamentalSyntaxErrorDocument
48
{
@@ -7,9 +11,37 @@ namespace LoadFundamentalSyntaxErrorDocument
711
/// </summary>
812
public partial class MainWindow : Window
913
{
14+
PdfLoadedDocument pdfDocument;
1015
public MainWindow()
1116
{
1217
InitializeComponent();
1318
}
19+
20+
private void Button_Click(object sender, RoutedEventArgs e)
21+
{
22+
var dialog = new OpenFileDialog
23+
{
24+
Filter = "PDF files (*.pdf)|*.pdf",
25+
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
26+
};
27+
if (dialog.ShowDialog() == true)
28+
{
29+
LoadPdfFile(dialog.FileName);
30+
}
31+
}
32+
private void LoadPdfFile(string value)
33+
{
34+
if (!string.IsNullOrEmpty(value) && File.Exists(value))
35+
{
36+
//Repair the PDF document with basic syntax errors
37+
pdfDocument = new PdfLoadedDocument(new FileStream(value, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
38+
pdfViewer.Load(pdfDocument);
39+
}
40+
else
41+
{
42+
pdfDocument = null;
43+
return;
44+
}
45+
}
1446
}
1547
}

DisplayPDF_fundamental_syntax_errors/MainWindowViewModel.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)