Skip to content

Commit 3901421

Browse files
992849: Added Sample for print collate support
1 parent 4b18dec commit 3901421

File tree

14 files changed

+557
-0
lines changed

14 files changed

+557
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="Syncfusion.Compression.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-100.2462.1.0" newVersion="100.2462.1.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="PrintCollate.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:PrintCollate"
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 PrintCollate
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Window x:Class="PrintCollate.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:PrintCollate" xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
7+
mc:Ignorable="d"
8+
Title="MainWindow" Height="450" Width="800">
9+
<Grid>
10+
<Grid.RowDefinitions>
11+
<RowDefinition Height="Auto"/>
12+
<RowDefinition Height="*"/>
13+
</Grid.RowDefinitions>
14+
<Button Content="Button" HorizontalAlignment="Left" Margin="10" Grid.Row="0" VerticalAlignment="Top" Click="Button_Click"/>
15+
<PdfViewer:PdfViewerControl x:Name="PDFViewer" Grid.Row ="1"/>
16+
</Grid>
17+
</Window>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
using Syncfusion.PdfToImageConverter;
2+
using Syncfusion.Windows.Tools.Controls;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Drawing;
6+
using System.Drawing.Printing;
7+
using System.IO;
8+
using System.Linq;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using System.Windows;
12+
using System.Windows.Controls;
13+
using System.Windows.Data;
14+
using System.Windows.Documents;
15+
using System.Windows.Input;
16+
using System.Windows.Media;
17+
using System.Windows.Media.Imaging;
18+
using System.Windows.Navigation;
19+
using System.Windows.Shapes;
20+
21+
namespace PrintCollate
22+
{
23+
/// <summary>
24+
/// Interaction logic for MainWindow.xaml
25+
/// </summary>
26+
public partial class MainWindow : Window
27+
{
28+
public MainWindow()
29+
{
30+
InitializeComponent();
31+
}
32+
private void Button_Click(object sender, RoutedEventArgs e)
33+
{
34+
PdfToImageConverter imageConverter = new PdfToImageConverter();
35+
36+
FileStream inputStream = new FileStream("../../testing.pdf", FileMode.Open, FileAccess.ReadWrite);
37+
imageConverter.Load(inputStream);
38+
39+
int pageCount = imageConverter.PageCount;
40+
List<System.Drawing.Image> images = new List<System.Drawing.Image>();
41+
42+
for (int i = 0; i < pageCount; i++)
43+
{
44+
Stream outputStream = imageConverter.Convert(i, false, true);
45+
Bitmap image = new Bitmap(outputStream);
46+
images.Add(new Bitmap(image));
47+
}
48+
49+
PrintImages(images);
50+
}
51+
52+
private void PrintImages(List<System.Drawing.Image> images)
53+
{
54+
bool collate = false;
55+
short copies = 2;
56+
PrintDocument printDoc = new PrintDocument();
57+
printDoc.PrinterSettings.Collate = collate;
58+
int totalPages = images.Count;
59+
int printIndex = 0;
60+
printDoc.PrintPage += (s, e) =>
61+
{
62+
int pageIndex;
63+
if (collate)
64+
{
65+
// Print full document, then repeat
66+
pageIndex = printIndex % totalPages;
67+
}
68+
else
69+
{
70+
// Print each page multiple times before moving to next
71+
pageIndex = printIndex / copies;
72+
}
73+
74+
e.Graphics.DrawImage(images[pageIndex], e.MarginBounds);
75+
76+
printIndex++;
77+
e.HasMorePages = printIndex < copies * totalPages;
78+
79+
};
80+
printDoc.Print();
81+
}
82+
}
83+
}
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="utf-8"?>
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')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{66A2D5E8-3C56-4D63-931E-2CBD8B5749D1}</ProjectGuid>
8+
<OutputType>WinExe</OutputType>
9+
<RootNamespace>PrintCollate</RootNamespace>
10+
<AssemblyName>PrintCollate</AssemblyName>
11+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
14+
<WarningLevel>4</WarningLevel>
15+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
16+
<Deterministic>true</Deterministic>
17+
<NuGetPackageImportStamp>
18+
</NuGetPackageImportStamp>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<PlatformTarget>AnyCPU</PlatformTarget>
22+
<DebugSymbols>true</DebugSymbols>
23+
<DebugType>full</DebugType>
24+
<Optimize>false</Optimize>
25+
<OutputPath>bin\Debug\</OutputPath>
26+
<DefineConstants>DEBUG;TRACE</DefineConstants>
27+
<ErrorReport>prompt</ErrorReport>
28+
<WarningLevel>4</WarningLevel>
29+
</PropertyGroup>
30+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
31+
<PlatformTarget>AnyCPU</PlatformTarget>
32+
<DebugType>pdbonly</DebugType>
33+
<Optimize>true</Optimize>
34+
<OutputPath>bin\Release\</OutputPath>
35+
<DefineConstants>TRACE</DefineConstants>
36+
<ErrorReport>prompt</ErrorReport>
37+
<WarningLevel>4</WarningLevel>
38+
</PropertyGroup>
39+
<ItemGroup>
40+
<Reference Include="Syncfusion.Compression.Base, Version=100.2462.1.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
41+
<HintPath>packages\Syncfusion.Compression.Base.100.2.1574\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
42+
</Reference>
43+
<Reference Include="Syncfusion.Licensing, Version=32.1462.19.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
44+
<HintPath>packages\Syncfusion.Licensing.32.1.19\lib\net462\Syncfusion.Licensing.dll</HintPath>
45+
</Reference>
46+
<Reference Include="Syncfusion.Pdf.Base, Version=32.1462.19.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
47+
<HintPath>packages\Syncfusion.Pdf.Wpf.32.1.19\lib\net462\Syncfusion.Pdf.Base.dll</HintPath>
48+
</Reference>
49+
<Reference Include="Syncfusion.PdfToImageConverter.Base, Version=32.1462.19.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
50+
<HintPath>packages\Syncfusion.PdfToImageConverter.WPF.32.1.19\lib\net462\Syncfusion.PdfToImageConverter.Base.dll</HintPath>
51+
</Reference>
52+
<Reference Include="Syncfusion.PdfViewer.WPF, Version=32.1462.19.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
53+
<HintPath>packages\Syncfusion.PdfViewer.WPF.32.1.19\lib\net462\Syncfusion.PdfViewer.WPF.dll</HintPath>
54+
</Reference>
55+
<Reference Include="Syncfusion.Shared.WPF, Version=32.1462.19.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
56+
<HintPath>packages\Syncfusion.Shared.WPF.32.1.19\lib\net462\Syncfusion.Shared.WPF.dll</HintPath>
57+
</Reference>
58+
<Reference Include="System" />
59+
<Reference Include="System.Data" />
60+
<Reference Include="System.Drawing" />
61+
<Reference Include="System.Xml" />
62+
<Reference Include="Microsoft.CSharp" />
63+
<Reference Include="System.Core" />
64+
<Reference Include="System.Xml.Linq" />
65+
<Reference Include="System.Data.DataSetExtensions" />
66+
<Reference Include="System.Net.Http" />
67+
<Reference Include="System.Xaml">
68+
<RequiredTargetFramework>4.0</RequiredTargetFramework>
69+
</Reference>
70+
<Reference Include="WindowsBase" />
71+
<Reference Include="PresentationCore" />
72+
<Reference Include="PresentationFramework" />
73+
</ItemGroup>
74+
<ItemGroup>
75+
<ApplicationDefinition Include="App.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</ApplicationDefinition>
79+
<Page Include="MainWindow.xaml">
80+
<Generator>MSBuild:Compile</Generator>
81+
<SubType>Designer</SubType>
82+
</Page>
83+
<Compile Include="App.xaml.cs">
84+
<DependentUpon>App.xaml</DependentUpon>
85+
<SubType>Code</SubType>
86+
</Compile>
87+
<Compile Include="MainWindow.xaml.cs">
88+
<DependentUpon>MainWindow.xaml</DependentUpon>
89+
<SubType>Code</SubType>
90+
</Compile>
91+
</ItemGroup>
92+
<ItemGroup>
93+
<Compile Include="Properties\AssemblyInfo.cs">
94+
<SubType>Code</SubType>
95+
</Compile>
96+
<Compile Include="Properties\Resources.Designer.cs">
97+
<AutoGen>True</AutoGen>
98+
<DesignTime>True</DesignTime>
99+
<DependentUpon>Resources.resx</DependentUpon>
100+
</Compile>
101+
<Compile Include="Properties\Settings.Designer.cs">
102+
<AutoGen>True</AutoGen>
103+
<DependentUpon>Settings.settings</DependentUpon>
104+
<DesignTimeSharedInput>True</DesignTimeSharedInput>
105+
</Compile>
106+
<EmbeddedResource Include="Properties\Resources.resx">
107+
<Generator>ResXFileCodeGenerator</Generator>
108+
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
109+
</EmbeddedResource>
110+
<None Include="packages.config" />
111+
<None Include="Properties\Settings.settings">
112+
<Generator>SettingsSingleFileGenerator</Generator>
113+
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
114+
</None>
115+
<None Include="testing.pdf" />
116+
</ItemGroup>
117+
<ItemGroup>
118+
<None Include="App.config" />
119+
</ItemGroup>
120+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
121+
<Import Project="packages\Syncfusion.PdfToImageConverter.WPF.32.1.19\build\net462\Syncfusion.PdfToImageConverter.WPF.targets" Condition="Exists('packages\Syncfusion.PdfToImageConverter.WPF.32.1.19\build\net462\Syncfusion.PdfToImageConverter.WPF.targets')" />
122+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
123+
<PropertyGroup>
124+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
125+
</PropertyGroup>
126+
<Error Condition="!Exists('packages\Syncfusion.PdfToImageConverter.WPF.32.1.19\build\net462\Syncfusion.PdfToImageConverter.WPF.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Syncfusion.PdfToImageConverter.WPF.32.1.19\build\net462\Syncfusion.PdfToImageConverter.WPF.targets'))" />
127+
</Target>
128+
</Project>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Solution>
2+
<Project Path="PrintCollate.csproj" />
3+
</Solution>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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("PrintCollate")]
11+
[assembly: AssemblyDescription("")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("")]
14+
[assembly: AssemblyProduct("PrintCollate")]
15+
[assembly: AssemblyCopyright("Copyright © 2025")]
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+
[assembly: AssemblyVersion("1.0.0.0")]
52+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)