-
June 8th, 2016, 09:06 AM
#1
Speed up printing proccess!
Hi all.
I have one issue on my code, the problem is that I print several forms using OnPrintPage events. Everything works fine, but once that the paper size is very small, the printer takes too much time spinning out, before takes another page to print. It seems like it is ignoring my paper size settings, and steel printing on the largest paper that it supports.
I need to speed up this printing process, and right after the printer prints one page, immediately loads a new paper and continue to print, reducing dramatically the total printing time for let’s say, 200 pages.
In my code I have tree combo box, one I choose the printer, one I choose the printer resolution, and another with paper sizes. The code that I am using until now to select the paper size is this below:
Code:
Public PD As New System.Drawing.Printing.PrintDocument
Private Sub CBX_papersize_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CBX_papersize.SelectedIndexChanged
If CBX_papersize.SelectedIndex = 0 Then Exit Sub
PD.DefaultPageSettings.PaperSize = PD.PrinterSettings.PaperSizes.Item(CBX_papersize.SelectedIndex - 1)
End Sub
Is there anything I missing?
Regards.
-
June 12th, 2016, 10:08 AM
#2
Re: Speed up printing proccess!
What type of printer are you working on?
Could you please supply the code ( that you have used to make your pages smaller or bigger ) as well
-
June 12th, 2016, 06:22 PM
#3
Re: Speed up printing proccess!
Hi HanneSThEGreaT!
I am using a Samsung laser model 2165-W, but I made tests on HP inkjet also. The behavior is equal on both printers. Well, regarding with code (it is big and complex, so I cut a lots of things that is not necessary for understanding ok), there are some parts of it I use for different issues, as below:
Code:
Public SX, SY, V_SIZEX, V_SIZEY, IDX_X, IDX1_Y, IDX2_Y, IDX3_Y, PRS_X, PRS_Y, PPAW, scale_x, scale_y, pixel_x, pixel_y, offset_h, offset_v, scale_all As Single
Public N_ROWS, N_COLS, N_PAGES, N_LINHAS, AUX_LINE, A_START, A_STOP, AP_VOL As Single
Public MARKS As New List(Of Point)
Public GTYPE, IDX_V1, IDX_V2, IDX_V3, GAMENAME As String
Public LOCK_CONTORNO As Boolean = True
Public PAR_IMPAR As Boolean = False 'TRUE = ODD - FALSE = EVEN
Public PD As New System.Drawing.Printing.PrintDocument
Public Sub SET_GAME_INFO()
V_SIZEX = 313
SX = 83 'Set the printed document width, in my case the disered is 83mm
IDX_X = 278
IDX1_Y = 25
IDX2_Y = 35
IDX3_Y = 45
Select Case GTYPE
Case "MSN" 'MSN TYPE
V_SIZEY = 508
SY = 140 'Set the printed document height, in my case the disered is 140mm
Case "MSV" 'MSV TYPE
V_SIZEY = 693
SY = 183 'Set the printed document height, in my case the disered is 183mm
IDX1_Y = 75
IDX2_Y = 85
IDX3_Y = 95
End Select
End Sub
Public Sub DRAW_MARKS(g As Graphics)
If FRM_01.CB_cxcontorno.Checked And LOCK_CONTORNO = False Then g.DrawRectangle(Pens.Black, 0, 0, V_SIZEX, V_SIZEY)
If FRM_01.CB_printidx.Checked = True Then
Dim drawFont As New Font("Arial", 1)
Dim drawBrush As New SolidBrush(Color.Black)
g.DrawString(IDX_V1, drawFont, drawBrush, IDX_X, IDX1_Y)
g.DrawString(IDX_V2, drawFont, drawBrush, IDX_X, IDX2_Y)
g.DrawString(IDX_V3, drawFont, drawBrush, IDX_X, IDX3_Y)
End If
For i = 0 To MARKS.Count - 1
If FRM_01.Elipse.Checked = True Then
g.FillEllipse(New SolidBrush(Color.Black), New Rectangle(MARKS(i).X, MARKS(i).Y, 12, 6)) 'ELIPSE
Else
g.FillRectangle(New SolidBrush(Color.Black), New Rectangle(MARKS(i).X, MARKS(i).Y, 12, 6)) 'SQUARE
End If
Next
End Sub
Public Sub CONFIG_DOC()
scale_all = NUM_scl.Value
PD.DefaultPageSettings.Landscape = False
PD.OriginAtMargins = False 'Set origen at page margin
PRS_X = PD.DefaultPageSettings.PrinterResolution.X 'Get printer resolution X
PRS_Y = PD.DefaultPageSettings.PrinterResolution.Y 'Get printer resolution Y
PPAW = PD.DefaultPageSettings.PrintableArea.Width * PRS_X / 200 'Conversion to pixel divided by two - Page area
pixel_x = ((SX * (scale_all / 100)) / 25.4) * PRS_X 'Calculate the pixels needed to achieve the desire print output size X
pixel_y = ((SY * (scale_all / 100)) / 25.4) * PRS_Y 'Calculate the pixels needed to achieve the desire print output size Y
scale_x = pixel_x / V_SIZEX 'Calculate the scale factor X
scale_y = pixel_y / V_SIZEY 'Calculate the scale factor Y
offset_h = NUM_hor.Value
offset_v = NUM_ver.Value
'Use the Screen Resolutions - For Windows is 96 PPI, for MAC is 72 PPI
'V_SIZEX = SX * 96 / 25.4 'This is the actual size of the form on screen X (83mm) - 83 * 96 / 25.4 = 314 pixels
'V_SIZEY = SY * 96 / 25.4 'This is the actual size of the form on screen Y (140mm) - 140 * 96 / 25.4 = 529 pixels
End Sub
Private Sub OnPrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.PageUnit = GraphicsUnit.Pixel
If CHB_imp_left.Checked = True Then
e.Graphics.TranslateTransform(0 + offset_h, 0 + offset_v)
End If
If CHB_imp_center.Checked = True Then
e.Graphics.TranslateTransform(PPAW - pixel_x / 2 + offset_h, 0 + offset_v)
End If
If CHB_imp_right.Checked = True Then
e.Graphics.TranslateTransform(PPAW * 2 - pixel_x + offset_h, 0 + offset_v)
End If
e.Graphics.ScaleTransform(scale_x, scale_y)
Select Case GTYPE
Case "TESTE"
e.HasMorePages = False
PCT_02.Refresh()
Case "MSN"
N_PAGES -= 1
If N_PAGES = 0 Then
e.HasMorePages = False
Else
e.HasMorePages = True
End If
IDX_V2 = ""
IDX_V3 = ""
Call CLEAR_MARKS()
For i As Integer = 1 To N_COLS
Call COORDS_MSN(DTGV_impressao.Rows(A_START).Cells(i).Value, 1)
If A_START + 1 < A_STOP Then
Call COORDS_MSN(DTGV_impressao.Rows(A_START + 1).Cells(i).Value, 2)
AUX_LINE = 1
End If
Next i
IDX_V1 = DTGV_impressao.Rows(A_START).Cells(0).Value
Call COORDS_MSN(N_COLS * 10 + 1, 0) 'APOSTAS POR JOGO
A_START += 1
If AUX_LINE = 1 Then
IDX_V2 = DTGV_impressao.Rows(A_START).Cells(0).Value
A_START += 1
End If
AUX_LINE = 0
PCT_02.Refresh()
Case "MSV"
N_PAGES -= 1
If N_PAGES = 0 Then
e.HasMorePages = False
Else
e.HasMorePages = True
End If
IDX_V2 = ""
IDX_V3 = ""
Call CLEAR_MARKS()
For i As Integer = 1 To N_COLS
Call COORDS_MSV(DTGV_impressao.Rows(A_START).Cells(i).Value, 1)
If A_START + 1 < A_STOP Then
Call COORDS_MSV(DTGV_impressao.Rows(A_START + 1).Cells(i).Value, 2)
AUX_LINE = 1
End If
If A_START + 2 < A_STOP Then
Call COORDS_MSV(DTGV_impressao.Rows(A_START + 2).Cells(i).Value, 3)
AUX_LINE = 2
End If
Next i
IDX_V1 = DTGV_impressao.Rows(A_START).Cells(0).Value
Call COORDS_MSV(N_COLS * 10 + 1, 0) 'APOSTAS POR JOGO
A_START += 1
If AUX_LINE > 0 Then
IDX_V2 = DTGV_impressao.Rows(A_START).Cells(0).Value
A_START += 1
End If
If AUX_LINE > 1 Then
IDX_V3 = DTGV_impressao.Rows(A_START).Cells(0).Value
A_START += 1
End If
AUX_LINE = 0
PCT_02.Refresh()
End Select
Call DRAW_MARKS(e.Graphics)
End Sub
Private Sub BTN_printall_Click(sender As Object, e As EventArgs) Handles BTN_printall.Click
A_START = 1
AUX_LINE = DTGV_impressao.RowCount - 1
A_STOP = DTGV_impressao.Rows(AUX_LINE).Cells(0).Value
N_COLS = DTGV_impressao.ColumnCount - 1
AP_VOL = 2
If GTYPE = "MSV" Or GTYPE = "DSV" Then AP_VOL = 3 'INFORMAR A QUANTIDADE DE APOSTAS POR VOLANTE
N_PAGES = 1
AUX_LINE = 0
For i As Integer = A_START To A_STOP - 1
AUX_LINE += 1
If AUX_LINE = AP_VOL Then
N_PAGES += 1
AUX_LINE = 0
End If
Next i
A_START -= 1
Call SET_GAME_INFO()
Call CONFIG_DOC()
PD.Print()
End Sub
Please help me with this issue.
Regards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|