473,382 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Best way to print a HTML file?

I have a C# application that generates its reports in HTML. After it creates
the report, it opens it in IE so it can be viewed or printed.

I would like to add the ability to print the report directly from the
application, but I haven't found an easy way to do this. I am probably making
it overly complicated, but this is what I am doing right now:

1. Instance an "AxWebBrowser" control
2. Navigate the browser control to the report HTML file
3. Sleep until the browser control is ready (finished rendering the HTML file)
4. Cast the browser’s Document to an IHTMLDocument2 class
5. Call .execCommands(“Print”,true,0) and tell the IHTMLDocument2 to print

This works fine, but it just seems like there should be a better way. I
would also like to have control over the document's header/footer, and have
the ability just to print directly to the default printer and bypass the
printer selection dialog box (if the user wanted to do it this way).

Does anyone happen to know of a better way to print HTML documents in C#?
Thanks in advance.
Nov 29 '05 #1
1 5099
Not sure what you mean by "better." But it looks like you've got the right
idea to me. An HTML document is plain text. It has to be interpreted to be
formatted, and have resources such as images downloaded and formatted in
line with the rest of the document. After that, to print, the final graphic
product must be sent to the printer as a graphic. So, you could always write
your own parser for HTML, have it build a graphic based on the markup, in
memory, and send that to a printer, but unless you are planning on marketing
a browser (essentially what you would build), you may as well use an
existing one.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"David Templet" <jd*******@gmail.com> wrote in message
news:DB**********************************@microsof t.com...
I have a C# application that generates its reports in HTML. After it
creates
the report, it opens it in IE so it can be viewed or printed.

I would like to add the ability to print the report directly from the
application, but I haven't found an easy way to do this. I am probably
making
it overly complicated, but this is what I am doing right now:

1. Instance an "AxWebBrowser" control
2. Navigate the browser control to the report HTML file
3. Sleep until the browser control is ready (finished rendering the HTML
file)
4. Cast the browser's Document to an IHTMLDocument2 class
5. Call .execCommands("Print",true,0) and tell the IHTMLDocument2 to print

This works fine, but it just seems like there should be a better way. I
would also like to have control over the document's header/footer, and
have
the ability just to print directly to the default printer and bypass the
printer selection dialog box (if the user wanted to do it this way).

Does anyone happen to know of a better way to print HTML documents in C#?
Thanks in advance.

Nov 29 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
4
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
2
by: Luis Serrano | last post by:
Hi all, I'm trying to generate labels to print in several different formats, all of them with their own height,width and page margins. We've got this done in MS Access 2000, using a designed...
7
by: Rhino | last post by:
I thought I'd take a second to step away from a specific problem and ask a general question about best practices; I know some of the people here are very experienced with CSS. Given the need to...
6
by: psbasha | last post by:
Hi , Currenty I am storing the Graphical User Interface options in a string memeber variable of a class as show below: SampleCode Tkinter Modules ( Graphical User Interface):...
0
by: thirunavukarasukm | last post by:
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...
2
by: bangad | last post by:
this code print file in browser but in in tabular form like in .csv file.....kindly help me out.... #!/usr/bin/perl -w # use lib use strict; use CGI; # limit 1000K bytes post, permit upload...
2
by: dmorand | last post by:
When I try to print a 'print version' of my page it looks fine in IE 7, but when I print in IE 6 the margins are all screwed up. The page itself looks the same in both browsers, it's just when I...
66
by: happyse27 | last post by:
Hi All, my html code is sno 1) and perl code is sno 2). a) I tried to print $filename and it cant print out the value, only blank was displayed, and the file could not be uploaded. And it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.