To print Html page using PrintDialog and Print Document

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2007
Posts: 23
Reputation: thirunavukaras is an unknown quantity at this point 
Solved Threads: 0
thirunavukaras thirunavukaras is offline Offline
Newbie Poster

To print Html page using PrintDialog and Print Document

 
0
  #1
Sep 26th, 2007
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...............
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC