-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
60 lines (50 loc) · 2.25 KB
/
Program.cs
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
using DevExpress.Drawing;
using DevExpress.Pdf;
using System;
using System.Drawing;
using System.IO;
namespace CustomizePrintSettings
{
class Program
{
static void Main(string[] args)
{
// Create a PDF Document Processor instance and load a PDF into it.
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
{
documentProcessor.LoadDocument(@"..\..\..\Demo.pdf");
// Declare the PDF printer settings.
PdfPrinterSettings settings = new PdfPrinterSettings();
// Specify the page numbers to be printed.
settings.PageNumbers = new int[] { 1, 2, 3, 4, 5, 6 };
// Handle the PrintPage event to specify print output.
documentProcessor.PrintPage += OnPrintPage;
// Handle the QueryPageSettings event to customize settings for a page to be printed.
documentProcessor.QueryPageSettings += OnQueryPageSettings;
// Print the document using the specified printer settings.
documentProcessor.Print(settings);
// Unsubscribe from PrintPage and QueryPageSettings events.
documentProcessor.PrintPage -= OnPrintPage;
documentProcessor.QueryPageSettings -= OnQueryPageSettings;
}
}
private static void OnQueryPageSettings(object sender, PdfQueryPageSettingsEventArgs e)
{
// Print the second page with the landscape orientation.
if (e.PageNumber == 2)
{
e.PageSettings.Landscape = true;
}
else e.PageSettings.Landscape = false;
}
// Specify what happens when the PrintPage event is raised.
private static void OnPrintPage(object sender, PdfPrintPageEventArgs e)
{
// Draw a picture on each printed page.
byte[] imageBytes = File.ReadAllBytes(@"..\..\..\DevExpress.png");
string imageBase64 = Convert.ToBase64String(imageBytes);
using (DXImage image = DXImage.FromBase64String(imageBase64))
e.Graphics.DrawImage(image, new RectangleF(10, 30, image.Width / 2, image.Height / 2));
}
}
}