Skip to content

Commit 52aa256

Browse files
committed
WPF-60240 - How to create PDF thumbnails with horizontal scrolling
1 parent d4caac4 commit 52aa256

14 files changed

+549
-0
lines changed
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.31320.298
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WPFThumbnailSample", "WPFThumbnailSample\WPFThumbnailSample.csproj", "{EEA9D1D2-AF12-4800-AEE0-00EC33FE12D4}"
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+
{EEA9D1D2-AF12-4800-AEE0-00EC33FE12D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EEA9D1D2-AF12-4800-AEE0-00EC33FE12D4}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EEA9D1D2-AF12-4800-AEE0-00EC33FE12D4}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EEA9D1D2-AF12-4800-AEE0-00EC33FE12D4}.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 = {BCB19BD1-1043-46FD-91D3-72BD4CB9E28A}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
5+
</startup>
6+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="WPFThumbnailSample.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:WPFThumbnailSample"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace WPFThumbnailSample
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Window xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF" x:Class="WPFThumbnailSample.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:WPFThumbnailSample"
7+
mc:Ignorable="d"
8+
Title="MainWindow" WindowState="Maximized">
9+
<Grid Name="ParentGrid">
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="200"></RowDefinition>
12+
<RowDefinition Height="*"></RowDefinition>
13+
</Grid.RowDefinitions>
14+
<ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Visible">
15+
<Grid Name="ThumbnailGrid" Background="Gray" />
16+
</ScrollViewer>
17+
<PdfViewer:PdfViewerControl Name="pdfViewerControl" Grid.Row="1"/>
18+
</Grid>
19+
</Window>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Windows;
3+
using System.Drawing;
4+
using System.Windows.Media.Imaging;
5+
using System.Windows.Controls;
6+
using System.Windows.Input;
7+
8+
namespace WPFThumbnailSample
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
public MainWindow()
16+
{
17+
InitializeComponent();
18+
pdfViewerControl.Load(@"../../Data/JavaScript Succinctly.pdf");
19+
//Rise PdfViewer document loaded event
20+
pdfViewerControl.DocumentLoaded += PdfViewerControl_DocumentLoaded;
21+
//Rise PdfViewer document unloaded event
22+
pdfViewerControl.DocumentUnloaded += PdfViewerControl_DocumentUnloaded;
23+
}
24+
25+
/// <summary>
26+
/// Convert pdf pages as imag and add the images into thumbnail grid
27+
/// </summary>
28+
private void PdfViewerControl_DocumentLoaded(object sender, EventArgs args)
29+
{
30+
//Export pdf pages as image using PdfViewer ExportAsImage method with a custom size of 200 X 400
31+
BitmapSource[] Pages = pdfViewerControl.ExportAsImage(0, pdfViewerControl.PageCount - 1, new SizeF(200, 400), true);
32+
33+
for (int i = 0; i < Pages.Length; i++)
34+
{
35+
//Create image control from the exported Pdf page bitmap source
36+
System.Windows.Controls.Image image = new System.Windows.Controls.Image();
37+
image.Source = Pages[i];
38+
image.Margin = new Thickness(5);
39+
image.HorizontalAlignment = HorizontalAlignment.Center;
40+
image.MouseUp += Image_MouseUp;
41+
//Create column in the thumbnail grid and add the image into the column
42+
ColumnDefinition column = new ColumnDefinition();
43+
ThumbnailGrid.ColumnDefinitions.Add(column);
44+
Grid.SetColumn(image, i);
45+
ThumbnailGrid.Children.Add(image);
46+
}
47+
}
48+
49+
/// <summary>
50+
/// Navigate to the page in PdfViewer based on the thumbnail grid image selection
51+
/// </summary>
52+
private void Image_MouseUp(object sender, MouseButtonEventArgs e)
53+
{
54+
System.Windows.Controls.Image img = sender as System.Windows.Controls.Image;
55+
if (img != null)
56+
{
57+
//Get the pageindex from the thumbnail grid based on selected image
58+
int pageIndex = (int)img.GetValue(Grid.ColumnProperty);
59+
//Navigate to the particular page
60+
pdfViewerControl.GotoPage(pageIndex + 1);
61+
}
62+
}
63+
64+
/// <summary>
65+
/// Clear the columns in the Thumbnail grid
66+
/// </summary>
67+
private void PdfViewerControl_DocumentUnloaded(object sender, EventArgs e)
68+
{
69+
ThumbnailGrid.ColumnDefinitions.Clear();
70+
}
71+
}
72+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("WPFThumbnailSample")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("WPFThumbnailSample")]
15+
[assembly: AssemblyCopyright("Copyright © 2022")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

Navigation/Horizontal_Thumbnails/WPFThumbnailSample/Properties/Resources.Designer.cs

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)