Good morning! A friend asked me to create a simple programme that prints a .pdf file. But he needs it to print using two paper sources, one for odd pages and another for even pages. The problem is that the code prints only blank pages!
Imports System.Drawing.Printing
Public Class Form1
Dim pd As New PrintDocument
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
ComboBox1.Items.Clear()
ComboBox2.Items.Clear()
ComboBox1.DisplayMember = "SourceName1"
ComboBox2.DisplayMember = "SourceName2"
Dim pkSource As PaperSource
pd.DocumentName = TextBox1.Text
For i = 0 To pd.PrinterSettings.PaperSources.Count - 1
pkSource = pd.PrinterSettings.PaperSources.Item(i)
ComboBox1.Items.Add(pkSource)
ComboBox2.Items.Add(pkSource)
Next
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
TextBox1.Text = OpenFileDialog1.FileName
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If TextBox1.Text <> "" And ComboBox1.SelectedIndex <> -1 And ComboBox2.SelectedIndex <> -1 Then
With pd
Dim n As Integer = 0
Try
While (True)
n = n + 1
.DefaultPageSettings.PrinterSettings.FromPage = n
.DefaultPageSettings.PrinterSettings.ToPage = n
If (n Mod 2) = 0 Then
.DefaultPageSettings.PaperSource =
.PrinterSettings.PaperSources.Item(ComboBox1.SelectedIndex)
Else
.DefaultPageSettings.PaperSource =
.PrinterSettings.PaperSources.Item(ComboBox2.SelectedIndex)
End If
.Print()
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
End With
End If
End Sub
End Class