Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a project written in vb.net2012. my program is printing but my papersize can not contain all the data that are supposed to be on the paper. that is the my data go beyond the print area. My code is showing below.
THE WORD "PEN_DUE" is not showing on the printable area of the paper
e.Graphics.DrawString("PEN_DUE.", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 1530, VerticalPrintLocationSingle)

THANKS

What I have tried:

Private Sub MONTHLYDEDUCTIONSSUMMARYToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MONTHLYDEDUCTIONSSUMMARYToolStripMenuItem.Click
       Dim printDialog11 As PrintDialog = New PrintDialog
       PrintDocument11.DefaultPageSettings.Landscape = True
       PrintDocument11.DefaultPageSettings.PaperSize = PrintDocument11.PrinterSettings.PaperSizes(5)
       PrintPreviewDialog11.ShowDialog()
       Dim result As DialogResult = PrintDialog11.ShowDialog
       If (result = Windows.Forms.DialogResult.OK) Then
           PrintDocument11.Print()
       End If
   End Sub


Private Sub PrintDocument11_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument11.PrintPage
        Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=c:\Users\Public\LOCAL GOVERNDATA.mdb;Jet OLEDB:Database Password=council12;"
        Dim cn As OleDb.OleDbConnection = New OleDb.OleDbConnection(strConnection)
        cn.Open()

        Dim HorizontalPrintLocationSingle As Single = e.MarginBounds.Left
        Dim VerticalPrintLocationSingle As Single = e.MarginBounds.Top - 80

        Dim hfont As New Font("Aria", 12, FontStyle.Bold)
        Dim sfont As New Font("Arial", 12, FontStyle.Bold)
        Dim pfont As New Font("Arial", 11, FontStyle.Regular) : Dim pdfont As New Font("Arial", 11, FontStyle.Bold) : Dim afont As New Font("arial", 10, FontStyle.Bold)


        Dim LineHeightSingle As Single = pfont.GetHeight + 2 ' Add two pixels for spacing
        VerticalPrintLocationSingle += LineHeightSingle * 2
        e.Graphics.DrawString("LAGELU  LOCAL /GOVT.,  IYANA OFFA", hfont, Brushes.Black, HorizontalPrintLocationSingle + 400, VerticalPrintLocationSingle)
        VerticalPrintLocationSingle += LineHeightSingle * 2
        e.Graphics.DrawString(" DEDUCTIONS SUMMARY  FOR  THE  MONTH  OF", hfont, Brushes.Black, HorizontalPrintLocationSingle + 300, VerticalPrintLocationSingle)
        e.Graphics.DrawString(Today.ToString("MMM") & "." & "," & " " & Year(Today), hfont, Brushes.Black, HorizontalPrintLocationSingle + 770, VerticalPrintLocationSingle)
        VerticalPrintLocationSingle += LineHeightSingle * 2
        VerticalPrintLocationSingle += LineHeightSingle
        e.Graphics.DrawString("PAYE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 50, VerticalPrintLocationSingle)
        e.Graphics.DrawString("NULGE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 140, VerticalPrintLocationSingle)
        e.Graphics.DrawString("CICS", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 220, VerticalPrintLocationSingle)
        e.Graphics.DrawString("IMPA", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 220, VerticalPrintLocationSingle)
        e.Graphics.DrawString("ADVANCE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 320, VerticalPrintLocationSingle)
        e.Graphics.DrawString("DEPOSIT", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 410, VerticalPrintLocationSingle)
        e.Graphics.DrawString("BANK-LN", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 490, VerticalPrintLocationSingle)
        e.Graphics.DrawString("MUSLIM", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 590, VerticalPrintLocationSingle)
        e.Graphics.DrawString("XTIAN", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 685, VerticalPrintLocationSingle)
        e.Graphics.DrawString("COMM.", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 780, VerticalPrintLocationSingle)
        e.Graphics.DrawString("MHW_DUE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 875, VerticalPrintLocationSingle)
        e.Graphics.DrawString("CHE-DUE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 970, VerticalPrintLocationSingle)
        'e.Graphics.DrawString("NMN-DUE", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 1050, VerticalPrintLocationSingle)
        e.Graphics.DrawString("PEN_DUE.", pdfont, Brushes.Black, HorizontalPrintLocationSingle + 1530, VerticalPrintLocationSingle)
.....
......
....
Endsub
Posted
Updated 1-Sep-19 6:53am
Comments
Richard MacCutchan 1-Sep-19 13:25pm    
You need to check the dimensions of your paper and ensure all the data can fit within those limits. You may need to adjust the margins or use a smaller font. In either case it is never a good idea to put absolute values in your code. You should calculate the positions of the data as you build the page. That way you can change the font or paper size and the code should still work correctly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900