Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Printing-Examples/Print_Collate/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="Print_Collate.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Print_Collate"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
14 changes: 14 additions & 0 deletions Printing-Examples/Print_Collate/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Configuration;
using System.Data;
using System.Windows;

namespace Print_Collate
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

}
10 changes: 10 additions & 0 deletions Printing-Examples/Print_Collate/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Binary file added Printing-Examples/Print_Collate/Data/testing.pdf
Binary file not shown.
17 changes: 17 additions & 0 deletions Printing-Examples/Print_Collate/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Window x:Class="Print_Collate.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Print_Collate" xmlns:PdfViewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Content="Button" HorizontalAlignment="Left" Margin="10" Grid.Row="0" VerticalAlignment="Top" Click="Button_Click"/>
<PdfViewer:PdfViewerControl x:Name="PDFViewer" Grid.Row ="1"/>
</Grid>
</Window>
69 changes: 69 additions & 0 deletions Printing-Examples/Print_Collate/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using Syncfusion.PdfToImageConverter;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Windows;

namespace Print_Collate
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
PdfToImageConverter imageConverter = new PdfToImageConverter();

FileStream inputStream = new FileStream("../../../Data/testing.pdf", FileMode.Open, FileAccess.ReadWrite);
imageConverter.Load(inputStream);

int pageCount = imageConverter.PageCount;
List<System.Drawing.Image> images = new List<System.Drawing.Image>();

for (int i = 0; i < pageCount; i++)
{
Stream outputStream = imageConverter.Convert(i, false, true);
Bitmap image = new Bitmap(outputStream);
images.Add(new Bitmap(image));
}

PrintImages(images);
}
private void PrintImages(List<System.Drawing.Image> images)
{
bool collate = true;
short copies = 2;
PrintDocument printDoc = new PrintDocument();
printDoc.PrinterSettings.Collate = collate;
int totalPages = images.Count;
int printIndex = 0;
printDoc.PrintPage += (s, e) =>
{
int pageIndex;
if (collate)
{
// Print full document, then repeat
pageIndex = printIndex % totalPages;
}
else
{
// Print each page multiple times before moving to next
pageIndex = printIndex / copies;
}

e.Graphics.DrawImage(images[pageIndex], e.MarginBounds);

printIndex++;
e.HasMorePages = printIndex < copies * totalPages;

};
printDoc.Print();
}
}
}
12 changes: 12 additions & 0 deletions Printing-Examples/Print_Collate/Print_Collate.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.PdfViewer.WPF" Version="*" />
<PackageReference Include="System.Drawing.Common" Version="10.0.1" />
</ItemGroup>
<Import Project="targets\MultiTargeting.targets" />
</Project>
3 changes: 3 additions & 0 deletions Printing-Examples/Print_Collate/Print_Collate.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Print_Collate.csproj" />
</Solution>
10 changes: 10 additions & 0 deletions Printing-Examples/Print_Collate/targets/MultiTargeting.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net462;net8.0-windows;net9.0-windows;net10.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<EnableDefaultItems>True</EnableDefaultItems>
<EnableDefaultEmbeddedResourceItems>True</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
</Project>