I am really newbie with VB here. so I have a simple program within 4 button (Preview, Print, Setup, Save). These 4 buttons would like to print, preview, and saving a simple Graphic. The problem is when I call PrintDocument1.print() , It does not redirect me to saving a file neither printer selection.
Here's my code:
Imports System.Drawing.Printing
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub PrintDocument1_PrintPage_1(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
Dim font As New Font("Arial", 16, FontStyle.Regular)
e.Graphics.DrawString("Hello World", font, Brushes.Black, 200, 200)
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
PrintDialog1.Document = PrintDocument1
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PrintDocument1.Print()
End If
End Sub
Private Sub btnPreview_Click(sender As Object, e As EventArgs) Handles btnPreview.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog()
End Sub
Private Sub btnSetting_Click(sender As Object, e As EventArgs) Handles Button3.Click
PageSetupDialog1.Document = PrintDocument1
PageSetupDialog1.Document.DefaultPageSettings.Color = False
PageSetupDialog1.ShowDialog()
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
End Sub
End Class
I'd like to save my PrintDocument (that include e.graphic.drawstring) into PDF file locally within a Fialog to choose the file path.
Thank you guys, kindly need your help.
You can create a pdfPrintDocument class to use in place of PrintDocument. A bitmap image is created for each page on which we are going to be drawing our graphics. Using iTextSharp library, the images are converted to pdf. Example on the use is here
Using the code in you form.