admin管理员组文章数量:1202793
I am working in a project where I have to print a marksheet. I am using the following code. this code is working fine in my system but when I try to print on the client system, it's not printing properly, the edges are cutting. I am using a 16" screen(laptop) and the client is using 20" monitor.
Dim printDoc As New PrintDocument()
printDoc.DefaultPageSettings.PaperSize = New PaperSize("A4", 827, 1169)
printDoc.DefaultPageSettings.Landscape = True
AddHandler printDoc.PrintPage, AddressOf PrintPageHandler
' Set print settings
'printDoc.PrinterSettings.PrintQuality = PrintQuality.High
printDoc.Print()
Me.FormBorderStyle = FormBorderStyle.Sizable
Printbtn.Visible = True
Prevbtn.Visible = True
Nextbtn.Visible = True
Firstbtn.Visible = True
Lastbtn.Visible = True
Private Sub PrintPageHandler(sender As Object, e As PrintPageEventArgs)
Dim formBitmap As New Bitmap(Me.Width, Me.Height, Imaging.PixelFormat.Format64bppArgb)
Me.DrawToBitmap(formBitmap, New Rectangle(0, 0, Me.Width, Me.Height))
' Draw the bitmap onto the print page
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawImage(formBitmap, 0, 0)
' Clean up
formBitmap.Dispose()
e.HasMorePages = False
End Sub
I am working in a project where I have to print a marksheet. I am using the following code. this code is working fine in my system but when I try to print on the client system, it's not printing properly, the edges are cutting. I am using a 16" screen(laptop) and the client is using 20" monitor.
Dim printDoc As New PrintDocument()
printDoc.DefaultPageSettings.PaperSize = New PaperSize("A4", 827, 1169)
printDoc.DefaultPageSettings.Landscape = True
AddHandler printDoc.PrintPage, AddressOf PrintPageHandler
' Set print settings
'printDoc.PrinterSettings.PrintQuality = PrintQuality.High
printDoc.Print()
Me.FormBorderStyle = FormBorderStyle.Sizable
Printbtn.Visible = True
Prevbtn.Visible = True
Nextbtn.Visible = True
Firstbtn.Visible = True
Lastbtn.Visible = True
Private Sub PrintPageHandler(sender As Object, e As PrintPageEventArgs)
Dim formBitmap As New Bitmap(Me.Width, Me.Height, Imaging.PixelFormat.Format64bppArgb)
Me.DrawToBitmap(formBitmap, New Rectangle(0, 0, Me.Width, Me.Height))
' Draw the bitmap onto the print page
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawImage(formBitmap, 0, 0)
' Clean up
formBitmap.Dispose()
e.HasMorePages = False
End Sub
Share
Improve this question
asked Jan 21 at 5:34
Sujay GhoshSujay Ghosh
12 bronze badges
1
|
1 Answer
Reset to default 0When drawing the bitmap, scale it to fit the print area.
Dim printArea As RectangleF = e.MarginBounds
Dim scaleX As Single = printArea.Width / formBitmap.Width
Dim scaleY As Single = printArea.Height / formBitmap.Height
Dim scale As Single = Math.Min(scaleX, scaleY) ' Scale proportionally
Dim newWidth As Integer = CInt(formBitmap.Width * scale)
Dim newHeight As Integer = CInt(formBitmap.Height * scale)
Dim xPos As Integer = printArea.Left + (printArea.Width - newWidth) / 2
Dim yPos As Integer = printArea.Top + (printArea.Height - newHeight) / 2
本文标签: visual studioCan39t print document in vbnetStack Overflow
版权声明:本文标题:visual studio - Can't print document in vb.net - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738652970a2104980.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
e.Graphics.DrawImage(formBitmap, e.MarginBounds, 0, 0, formBitmap.Width, formBitmap.Height, GraphicsUnit.Pixel)
– dr.null Commented Jan 21 at 12:55