-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
69 lines (61 loc) · 2.14 KB
/
MainWindow.xaml.cs
File metadata and controls
69 lines (61 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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();
}
}
}