I have an application that is supposed to print a badge using a Dymo
LabelWriter 330. The problem I am having is this - when I 'Print Preview'
the badge, it is displayed properly, but when I 'Print' the badge, it is
cropped.
Let me show a code snippet and some debugging data:
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrint.Click
printerSetup()
prtDocBadge.Print()
End Sub
Private Sub btnPreview_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPreview.Click
printerSetup()
Dim dlg As New PrintPreviewDialog
dlg.Document = prtDocBadge
dlg.Show()
End Sub
Private Sub printerSetup()
prtDocBadge.PrinterSettings.PrinterName = "DYMO LabelWriter 330-USB"
' Get the index for the desired paper type. Actual size is 2 5/16" x 4"
Dim i As Integer
For i = 0 To prtDocBadge.PrinterSettings.PaperSizes.Count - 1
If (prtDocBadge.PrinterSettings.PaperSizes(i).PaperNa me = "30256
Shipping") Then
Exit For
End If
Next
prtDocBadge.DefaultPageSettings.Margins.Bottom = 0
prtDocBadge.DefaultPageSettings.Margins.Left = 0
prtDocBadge.DefaultPageSettings.Margins.Top = 0
prtDocBadge.DefaultPageSettings.Margins.Right = 0
prtDocBadge.DefaultPageSettings.PaperSize =
prtDocBadge.PrinterSettings.PaperSizes(i)
End Sub
Private Sub prtDocBadge_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles prtDocBadge.PrintPage
Dim bLeft, bRight, bTop, bBottom As Single
Dim hdc As IntPtr = e.Graphics.GetHdc
GetHardMargins(hdc, bLeft, bRight, bTop, bBottom) ' for debugging only
e.Graphics.ReleaseHdc(hdc) ' break point at next line in code
End Sub
When I examine the data at the break point
For 'Print Preview': Left Right Top Bottom
Width Height
e.Graphics.ClipBounds -1398101.38 1398101.38 -1398101.38
1398101.38 2796202.75 2796202.75
e.Graphics.VisibleClipBounds -1398101.38 1398101.38 -1398101.38
1398101.38 2796202.75 2796202.75
e.MarginBounds 0 231 0 400
231 400
e.PageBounds 0 231 0 400
231 400
hard margins 0 0 90.5 157.5
For 'Print': Left Right Top Bottom
Width Height
e.Graphics.ClipBounds -1398101.38 1398101.38 -1398101.38
1398101.38 2796202.75 2796202.75
e.Graphics.VisibleClipBounds 0 91 0 157.3
91 157.3
e.MarginBounds 0 231 0 400
231 400
e.PageBounds 0 231 0 400
231 400
hard margins 0 0 90.5 157.5
The underlying problem seems to be that the printer's 'hard margin' is not
properly set. For the 'Print' case, this seems to manifest itself as a
limitation on VisibleClipBounds which causes the document to be cropped when
it gets printed.
Would you please suggest a solution to this problem.
Thank you!.
--
Gerry Roston
Pair of Docs Consulting
ge***@pairofdocs.net