| | |
To print Html page using PrintDialog and Print Document
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2007
Posts: 23
Reputation:
Solved Threads: 0
Hai....
To print Html page using PrintDialog and Print Document
i am created one windows appication..
the windows application have many pages
in my booking page i have two buttons one btnprint,btnclose
i am go to click btnprint button and corresponding i reader one html file .
then in local string i got the stream reader file string
then replace some value to that string then i am go to write the another html file..
next my requirement is print this html file
this my code
Private Sub pgPrintDocument_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles pgPrintDocument.BeginPrint
lobjStreamReader = New StreamReader(Application.StartupPath & "\BlankCarHtml\CarBooking.htm")
lobjStreamWriter = New StreamWriter(Application.StartupPath & "\PreviewCarHtml\Ticket.htm")
pstrGuestName="kannana"
mstrReturn = lobjStreamReader.ReadToEnd()
lobjStreamReader.Close()
mstrReturn = mstrReturn.Replace("{GuestName}", pstrGuestName)
mstrReturn = mstrReturn.Replace("{GuestMobileNo}", pstrGuestMobileNo
lobjStreamWriter.WriteLine(mstrReturn)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Try
pgPrintDialog.Document = pgPrintDocument
pgPrintDocument.Print()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "btnPrint_Click", MessageBoxIcon.Warning)
End Try
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 8)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
End With
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(mstrReturn, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(mstrReturn, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
If intCurrentChar < RichTextBox1.Text.Length Then
e.HasMorePages = True
'HasMorePages tells the printing module whether another PrintPage event should be fired
Else
e.HasMorePages = False
intCurrentChar = 0
End If
End Sub
the corresponding ticket view source code only printed
i want tom print the html design page..
please any help to me..
how to print the html design page
reply please...............
To print Html page using PrintDialog and Print Document
i am created one windows appication..
the windows application have many pages
in my booking page i have two buttons one btnprint,btnclose
i am go to click btnprint button and corresponding i reader one html file .
then in local string i got the stream reader file string
then replace some value to that string then i am go to write the another html file..
next my requirement is print this html file
this my code
Private Sub pgPrintDocument_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles pgPrintDocument.BeginPrint
lobjStreamReader = New StreamReader(Application.StartupPath & "\BlankCarHtml\CarBooking.htm")
lobjStreamWriter = New StreamWriter(Application.StartupPath & "\PreviewCarHtml\Ticket.htm")
pstrGuestName="kannana"
mstrReturn = lobjStreamReader.ReadToEnd()
lobjStreamReader.Close()
mstrReturn = mstrReturn.Replace("{GuestName}", pstrGuestName)
mstrReturn = mstrReturn.Replace("{GuestMobileNo}", pstrGuestMobileNo
lobjStreamWriter.WriteLine(mstrReturn)
End Sub
Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Try
pgPrintDialog.Document = pgPrintDocument
pgPrintDocument.Print()
Catch ex As Exception
MessageBox.Show(ex.Message.ToString(), "btnPrint_Click", MessageBoxIcon.Warning)
End Try
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
Static intCurrentChar As Int32
Dim font As New Font("Verdana", 8)
Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
With PrintDocument1.DefaultPageSettings
PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
marginLeft = .Margins.Left
marginTop = .Margins.Top
End With
Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
Dim intLinesFilled, intCharsFitted As Int32
e.Graphics.MeasureString(Mid(mstrReturn, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
e.Graphics.DrawString(Mid(mstrReturn, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
intCurrentChar += intCharsFitted
If intCurrentChar < RichTextBox1.Text.Length Then
e.HasMorePages = True
'HasMorePages tells the printing module whether another PrintPage event should be fired
Else
e.HasMorePages = False
intCurrentChar = 0
End If
End Sub
the corresponding ticket view source code only printed
i want tom print the html design page..
please any help to me..
how to print the html design page
reply please...............
![]() |
Similar Threads
- Can I use a template html page within another html page (Site Layout and Usability)
- Print control to print the Content Page from a Master Page (ASP.NET)
- How do you print part of a page in Javascript? (JavaScript / DHTML / AJAX)
- print web page (JavaScript / DHTML / AJAX)
- Print HTML page / download updates (VB.NET)
- Print a web page in ASP.net (ASP.NET)
- want to print a html document in landscape orientation (HTML and CSS)
- Calling function to add HTML to the page (ASP.NET)
- IN Nero cover designer when I click print ican I get a page without a print command. (Windows Software)
- Page counter print accounting (*nix Software)
Other Threads in the VB.NET Forum
- Previous Thread: autoscroll is not a member of Systems.Windows.Forms.Panel
- Next Thread: Convert it into application
| Thread Tools | Search this Thread |
.net .net2008 2008 access advanced application array basic beginner browser button buttons center click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function generatetags html images input intel internet listview map mobile module monitor msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms winsock wpf wrapingcode xml year





