-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.vb
49 lines (44 loc) · 2.39 KB
/
Program.vb
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
Imports System.Drawing
Imports System.IO
Imports DevExpress.Drawing
Imports DevExpress.Pdf
Namespace CustomizePrintSettings
Friend Class Program
Shared Sub Main(ByVal args As String())
' Create a PDF Document Processor instance and load a PDF into it.
Using documentProcessor As PdfDocumentProcessor = New PdfDocumentProcessor()
documentProcessor.LoadDocument("..\..\..\Demo.pdf")
' Declare the PDF printer settings.
Dim settings As PdfPrinterSettings = New PdfPrinterSettings()
' Specify the page numbers to be printed.
settings.PageNumbers = New Integer() {1, 2, 3, 4, 5, 6}
' Handle the PrintPage event to specify print output.
AddHandler documentProcessor.PrintPage, AddressOf OnPrintPage
' Handle the QueryPageSettings event to customize settings for a page to be printed.
AddHandler documentProcessor.QueryPageSettings, AddressOf OnQueryPageSettings
' Print the document using the specified printer settings.
documentProcessor.Print(settings)
' Unsubscribe from PrintPage and QueryPageSettings events.
RemoveHandler documentProcessor.PrintPage, AddressOf OnPrintPage
RemoveHandler documentProcessor.QueryPageSettings, AddressOf OnQueryPageSettings
End Using
End Sub
Private Shared Sub OnQueryPageSettings(ByVal sender As Object, ByVal e As PdfQueryPageSettingsEventArgs)
' Print the second page with the landscape orientation.
If e.PageNumber = 2 Then
e.PageSettings.Landscape = True
Else
e.PageSettings.Landscape = False
End If
End Sub
' Specify what happens when the PrintPage event is raised.
Private Shared Sub OnPrintPage(ByVal sender As Object, ByVal e As PdfPrintPageEventArgs)
' Draw a picture on each printed page.
Dim imageBytes As Byte() = File.ReadAllBytes("..\..\..\DevExpress.png")
Dim imageBase64 As String = Convert.ToBase64String(imageBytes)
Using image As DXImage = DXImage.FromBase64String(imageBase64)
e.Graphics.DrawImage(image, New RectangleF(10, 30, image.Width \ 2, image.Height \ 2))
End Using
End Sub
End Class
End Namespace