How To Permently Set the PrintDocument page settings in Visual Basics 2010 Express

  • Thread starter Thread starter Tasipeka
  • Start date Start date
T

Tasipeka

Guest
Ive spent the whole day trying to figure out a way to set the PrintDocument PageSettings to A4. Everytime I run the program, I always have to open a PrintSetup Dialog and set the papersize to A4 before generating and saving the pdf document through PrintDocument. If not it will be printed in Letter papersize. Need Help

Private Sub setpage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles setpage.Click
PageSetUpDialog1.PageSettings = PrintDocument1.DefaultPageSettings
If PageSetUpDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then 'Then
PrintDocument1.DefaultPageSettings = PageSetUpDialog1.PageSettings
End If
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
' Turn on antialias for text
e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
' Print a string at the origin
' Read margins into local variables
Dim Lmargin, Rmargin, Tmargin, Bmargin As Integer
With PrintDocument1.DefaultPageSettings.Margins
Lmargin = .Left
Rmargin = .Right
Tmargin = .Top
Bmargin = .Bottom
End With
' Calculate the dimensions of the printable area
Dim PrintWidth, PrintHeight As Integer
With PrintDocument1.DefaultPageSettings.PaperSize
PrintWidth = .Width - Lmargin - Rmargin
PrintHeight = .Height - Tmargin - Bmargin
End With
Dim pFont As Font
pFont = New Font("Times New Roman Sans MS", 14, FontStyle.Bold)
e.Graphics.DrawString("Vehicle Information Register", pFont, Brushes.Black, 180, 40)
' Now print the rectangle
Dim R As Rectangle
R = New Rectangle(Lmargin, Tmargin, PrintWidth, PrintHeight)
e.Graphics.DrawRectangle(Pens.Blue, R)
Private Sub btngenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btngenerate.Click
printdoc1.Print()

End Sub

lp

Continue reading...
 
Back
Top