Print problem on different printers

Locutus

Member
Joined
Jan 25, 2012
Messages
5
Programming Experience
Beginner
Hello.

I have a strange problem, I'm writing small application in. vb.net which should print out a simple form. On my printer OKI B4350 and HP 4200n the print out looks good, but on HP 2015 the print out is bad, really bad. The fonts are different, the graphic
elements are out of margins. Can anybody tells me how to adjust my code to prints out looks good on every printer?

Here is my code.

Imports System.Drawing
Imports System.Drawing.Printing

Public Class Form1

 Private Sub btnDrukuj_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrukuj.Click


 '-----USTAWIENIE MARGINESÓW NA 5MM-----


 PageSetupDialog1.Document = printDokument
 PageSetupDialog1.Document.DefaultPageSettings.Marg ins.Left = cm(0.5)
 PageSetupDialog1.Document.DefaultPageSettings.Marg ins.Right = cm(0.5)
 PageSetupDialog1.Document.DefaultPageSettings.Marg ins.Top = cm(0.5)
 PageSetupDialog1.Document.DefaultPageSettings.Marg ins.Bottom = cm(0.5)
 PageSetupDialog1.Document.OriginAtMargins = True


 podgladDokumentu.Width = Screen.PrimaryScreen.Bounds.Width
 podgladDokumentu.Height = Screen.PrimaryScreen.Bounds.Height
 podgladDokumentu.PrintPreviewControl.Zoom = 2.0
 podgladDokumentu.ShowDialog()


 End Sub

 Private Sub printDokument_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDokument.PrintPage


 

 Dim grX1, grY1, grSzerokosc, grWysokosc, drX1, drY1, drSzerokosc, drWysokosc As Single
 Dim grOlowek As New Pen(Brushes.Black, 3)
 Dim grOlowekKropki As New Pen(Brushes.Black, 1)
 Dim czcionkaInna As New Font("Courier", 8)
 Dim czcionka As New Font("Times", 8)
 Dim czcionkaIndex As New Font("Times", 5)
 Dim czcionkaOpis As New Font("Times", 7)
 Dim czionkaPogrubionaZwykla As New Font("Times", 8, FontStyle.Bold)
 Dim czionkaPogrubionaNaglowek As New Font("Times", 12, FontStyle.Bold)
 Dim czcionkaZwyklaNaglowek As New Font("Times", 12)




 '-----RYSOWANIE GÓRNEJ RAMKI-----

 grX1 = 0 'printDokument.DefaultPageSettings.Margins.Left
 grY1 = 0 'printDokument.DefaultPageSettings.Margins.Top
 grSzerokosc = e.MarginBounds.Size.Width
 grWysokosc = cm(11.5)
 'e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias

 e.Graphics.FillRectangle(Brushes.LightGray, grX1 + grSzerokosc / 3, grY1, grSzerokosc / 3, cm(1.5)) 'WYPEŁNIENIE W2
 e.Graphics.DrawRectangle(Pens.Black, grX1 + grSzerokosc / 3, grY1, grSzerokosc / 3, cm(1.5)) 'PROSTOKĄT W2

 e.Graphics.DrawRectangle(grOlowek, grX1, grY1, grSzerokosc, grWysokosc) 'RAMKA GÓRNA
 e.Graphics.DrawLine(grOlowek, grX1, cm(1.5), grSzerokosc, cm(1.5)) 'LINIA NAGŁÓWKA 1 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1, grY1 + cm(3), grX1 + grSzerokosc, grY1 + cm(3)) 'LINIA 2 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1, grY1 + cm(4.5), grX1 + grSzerokosc, grY1 + cm(4.5)) 'LINIA 3 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1, grY1 + cm(9.5), grX1 + grSzerokosc, grY1 + cm(9.5)) 'LINIA 4 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1, grY1 + cm(10.5), grX1 + grSzerokosc / 2, grY1 + cm(10.5)) 'LINIA 5 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1 + grSzerokosc / 2, grY1 + cm(1.5), grX1 + grSzerokosc / 2, grY1 + grWysokosc) '-----LINIA PIONOWA
 e.Graphics.DrawLine(Pens.Black, grX1 + grSzerokosc / 2, grY1 + cm(6), grX1 + grSzerokosc, grY1 + cm(6)) 'LINIA 6 OD GÓRY
 e.Graphics.DrawLine(Pens.Black, grX1 + grSzerokosc / 2, grY1 + cm(7.5), grX1 + grSzerokosc, grY1 + cm(7.5)) 'LINIA 7 OD GÓRY

 '-----WYPEŁNIENIE W1-----
 grOlowekKropki.DashStyle = Drawing2D.DashStyle.Dot
 e.Graphics.DrawLine(grOlowekKropki, grX1 + cm(0.6), grY1 + cm(0.6), grX1 + (grSzerokosc / 3) - cm(0.6), grY1 + cm(0.6))
 e.Graphics.DrawString("/", czcionkaInna, Brushes.Black, grX1 + cm(4), grY1 + cm(0.3))
 e.Graphics.DrawString("Numer i data wystawienia faktury / listu " & vbCrLf & "przewozowego", czcionka, Brushes.Black, grX1 + cm(1), grY1 + cm(0.7))
 e.Graphics.DrawString("1)", czcionkaIndex, Brushes.Black, grX1 + cm(2.7), grY1 + cm(1))

 '-----WYPEŁNIENIE W2-----

 e.Graphics.DrawString("DOKUMENT DOSTAWY", czionkaPogrubionaNaglowek, Brushes.Black, (grX1 + grSzerokosc / 3) + cm(1), grY1 + cm(0.3))
 e.Graphics.DrawString("wyrobów węglowych", czcionkaZwyklaNaglowek, Brushes.Black, (grX1 + grSzerokosc / 3) + cm(1.5), grY1 + cm(0.7))

 '-----WYPEŁNIENIE W3-----

 e.Graphics.DrawString("NR", czionkaPogrubionaNaglowek, Brushes.Black, grX1 + cm(13.5), grY1 + cm(0.2))
 e.Graphics.DrawString("/No/", czcionkaZwyklaNaglowek, Brushes.Black, grX1 + cm(14.5), grY1 + cm(0.2))
 e.Graphics.DrawString("8", czcionkaZwyklaNaglowek, Brushes.Black, grX1 + cm(13.5), grY1 + cm(0.8))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(13.8), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(14.2), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(14.6), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawString("/", czcionkaZwyklaNaglowek, Brushes.Black, grX1 + cm(14.95), grY1 + cm(0.8))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(15.2), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(15.6), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(16), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(16.4), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(16.8), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(17.1), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawString("/", czcionkaZwyklaNaglowek, Brushes.Black, grX1 + cm(17.45), grY1 + cm(0.8))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(17.7), grY1 + cm(0.8), cm(0.3), cm(0.4))
 e.Graphics.DrawRectangle(Pens.Black, grX1 + cm(18.1), grY1 + cm(0.8), cm(0.3), cm(0.4))
 
 '-----WYPEŁNIENIE W4-----
 e.Graphics.DrawString("1.) Nazwa/nazwisko i imię podmiotu, który wystawił dokument dostawy :", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(1.6))
 e.Graphics.DrawString("2)", czcionkaIndex, Brushes.Black, grX1 + cm(7.3), grY1 + cm(1.53))
 e.Graphics.DrawString("2.) Adres siedziby/miejsca zamieszkania ww. podmiotu:", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(2.28))

 '-----WYPEŁNIENIE W5-----
 e.Graphics.DrawString("3.) Nazwa/nazwisko i imię podmiotu, który wydaje do przemieszczenia wyroby węglowe :", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(3.1))
 e.Graphics.DrawString("3)", czcionkaIndex, Brushes.Black, grX1 + cm(9), grY1 + cm(3))
 e.Graphics.DrawString("4.) Adres siedziby/miejsca zamieszkania ww. podmiotu :", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(3.78))

 '-----WYPEŁNIENIE W6-----
 e.Graphics.DrawString("5.) Adres miejsca wydania do przemieszczenia wyrobów węglowych :", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(4.6))
 e.Graphics.DrawString("6.) Data rozpoczęcia przemieszczenia wyrobów węglowych :", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(8.7))
 e.Graphics.DrawString("8)", czcionkaIndex, Brushes.Black, grX1 + cm(6.02), grY1 + cm(8.62))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + cm(0.2), grY1 + cm(9.4), grX1 + (grSzerokosc / 2) - cm(0.2), grY1 + cm(9.4))

 '-----WYPEŁNIENIE W7-----
 e.Graphics.DrawString("7.) Data i podpis podmiotu, który wystawił dokument dostawy, lub osoby" & _
 vbCrLf & "reprezentującej ten podmiot:", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(9.5))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + cm(0.2), grY1 + cm(10.4), grX1 + (grSzerokosc / 2) - cm(0.2), grY1 + cm(10.4))

 '-----WYPEŁNIENIE W8-----
 e.Graphics.DrawString("8.) Data i podpis podmiotu, który wydał wyroby węglowe do" & _
 vbCrLf & "przemieszczenia, lub osoby reprezentującej ten podmiot:", czcionkaOpis, Brushes.Black, grX1 + cm(0.1), grY1 + cm(10.5))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + cm(0.2), grY1 + cm(11.4), grX1 + (grSzerokosc / 2) - cm(0.2), grY1 + cm(11.4))

 '-----WYPEŁNIENIE W9-----
 e.Graphics.DrawString("9.) Podmiot odbierający/zwracający wyroby węglowe :", czcionkaOpis, Brushes.Black, grX1 + (grSzerokosc / 2) + cm(0.1), grY1 + cm(1.6))
 e.Graphics.DrawString("4)", czcionkaIndex, Brushes.Black, grX1 + (grSzerokosc / 2) + cm(5.45), grY1 + cm(1.53))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + (grSzerokosc / 2) + cm(0.2), grY1 + cm(2.9), grX1 + (grSzerokosc - cm(0.2)), grY1 + cm(2.9))

 '-----WYPEŁNIENIE W10-----
 e.Graphics.DrawString("10.) Adres siedziby/miejsca zamieszkania ww. podmiotu:", czcionkaOpis, Brushes.Black, grX1 + (grSzerokosc / 2) + cm(0.1), grY1 + cm(3.1))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + (grSzerokosc / 2) + cm(0.2), grY1 + cm(4.4), grX1 + (grSzerokosc - cm(0.2)), grY1 + cm(4.4))

 '-----WYPEŁNIENIE W11-----
 e.Graphics.DrawString("11.) Adres miejsca odbioru wyrobów węglowych :", czcionkaOpis, Brushes.Black, grX1 + (grSzerokosc / 2) + cm(0.1), grY1 + cm(4.6))
 e.Graphics.DrawString("5)", czcionkaIndex, Brushes.Black, grX1 + (grSzerokosc / 2) + cm(5.03), grY1 + cm(4.53))
 e.Graphics.DrawLine(grOlowekKropki, grX1 + (grSzerokosc / 2) + cm(0.2), grY1 + cm(5.9), grX1 + (grSzerokosc - cm(0.2)), grY1 + cm(5.9))


 End Sub

 

 Function cm(ByVal centymetry As Single) As Single

 Dim cale As Single

 cale = centymetry * 39.37

 Return cale

 End Function



End Class


Best Regards.
 
Back
Top