473,402 Members | 2,046 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,402 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 5111
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.