944,068 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 11259
  • VB.NET RSS
Sep 26th, 2007
0

To print Html page using PrintDialog and Print Document

Expand Post »
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...............
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
thirunavukaras is offline Offline
23 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: autoscroll is not a member of Systems.Windows.Forms.Panel
Next Thread in VB.NET Forum Timeline: Convert it into application





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC