473,503 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

To print Html page using PrintDialog and Print Document

21 New Member
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...............
Sep 26 '07 #1
0 2348

Sign in to post your reply or Sign up for a free account.

Similar topics

1
21497
by: Myrilath | last post by:
I was just wondering how I should go about printing an html document. I can read it in and print it out as source but I would like to print it as it should display. At the moment I hace been having...
0
3242
by: KohlerTommy | last post by:
In my application I need to give the user the ability to print duplex if the selected printer supports duplex printing. Many of the printer options do not make much sense in my application, and...
1
8407
by: ekey | last post by:
Hi follow function to print many copies but it only print one copy, my document is only one page; but i want to print many copies .such as three copies. how to do? Where do it error? THS ...
1
2512
by: Rainbow | last post by:
Hi, I tried to change the print setting by PrintDialog dlg = new PrintDialog(); dlg.AllowSomePages = true; dlg.AllowSelection = true; dlg.Document = pd; dlg.PrinterSettings.MinimumPage = 1;...
3
8601
by: Chase | last post by:
The print preview dialog will display the preview of the document but will print a blank page when the print icon is clicked. Printing is fine otherwise. Can i set the print icon in the...
2
1040
by: Rich | last post by:
Hi, I am working on a large Text Editor program. I have features like save, but I need help on how to print. I need to print the string "textbox1.text" using a printdialog. I would also like a way...
1
5682
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
2
7581
by: Artie | last post by:
Hi, I've searched the web but can't find a solution to an apparently really simple problem. My app contains an HTML string and I need to be able to invoke the Print Dialog to print the HTML...
9
3107
by: Autostrad | last post by:
Hi everybody, I need your help. The code below is good if I want to print a sketch. The book did not show how to print a simple text file. Right now if I run this program (as is)it will show...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.