473,396 Members | 1,933 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,396 software developers and data experts.

Printing HTML file

Hello!
I would like to print an HTML file in C#.
I can open the file as a stream and send it to the printer.... but
obviously, the source code is printed.
What I need is to print the document content itself, not the HTML source
code.

Thanks.

Arcadius
Nov 16 '05 #1
3 2109
Hi Arcadius
One easy way to do it is to save this area as an image then print that
image . fist of course you need to capture that area of the screen ( where
your HTML document is displayed ) as an image , they you send this image to
the printed .
Here you are code that capture a selected area of the screen and save it as
an image

[System.Runtime.InteropServices.DllImportAttribute( "gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);

Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"c:\Captured.jpg",
System.Drawing.Imaging.ImageFormat.Jpeg);
Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

hi,

if you got an answer, could you post it to us?

regards,
michael thompson


news.microsoft.com wrote:
Hello!
I would like to print an HTML file in C#.
I can open the file as a stream and send it to the printer.... but
obviously, the source code is printed.
What I need is to print the document content itself, not the HTML source
code.

Thanks.

Arcadius

Nov 16 '05 #3
You need to render the HTML code.
To achieve this just write something like MS Internet Explorer.

You can also use MS HTML WebBrowser control if you want to save time.
"Michael Thompson" <mi******@nationalmerchant.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...

hi,

if you got an answer, could you post it to us?

regards,
michael thompson


news.microsoft.com wrote:
Hello!
I would like to print an HTML file in C#.
I can open the file as a stream and send it to the printer.... but
obviously, the source code is printed.
What I need is to print the document content itself, not the HTML source
code.

Thanks.

Arcadius

Nov 16 '05 #4

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

Similar topics

5
by: Donnal Walter | last post by:
We want to be able to print HTML or PDF files to a given printer from Python in a kind of batch mode (without opening a preview window or printer dialog for each file). The printer is on a network,...
0
by: DotNetDummy | last post by:
Hi all, I am trying to set the printing setting e.g duplex mode etc. on a default printer when I.E object started printing a particular html doc. Here's the partial code, any help would be...
16
by: cyranoVR | last post by:
This is the approach I used to automate printing of Microsoft Access reports to PDF format i.e. unattended and without annoying "Save As..." dialogs, and - more importantly - without having to use...
3
by: Ahmad Abu-Raddad | last post by:
Hey Guys, Does anyone knows of a way to print HTML source directly to the printer (Server Side)?. I tried the PrintDocument class and the e.Graphics.DrawString and e.Graphics.DrawImage() but...
6
by: Bruno Hardmeier | last post by:
Hi How can I redirect a print job to a file? There is a checkbox in the print dialog, but I would like to do it in code indicating a filename. Thanks Bruno Hardmeier
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
4
by: Lucas Ponzo | last post by:
Hi All, I have an ASP.NET 2.0 app. The users access the pages, uniquely via pocket pc ... I need to print a page. But I need that the page print on a printer installed on the web server...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
2
by: =?Utf-8?B?TUFUVA==?= | last post by:
What i am trying to accomplish is programatically creating Invoices and then Printing them out. I don't really need to "View" them before they print. How I am trying to do this is I have created...
7
by: Iain Wilson | last post by:
I am pulling my hair out trying to print various objects from a .net web page My apologies for cross posting but I need an answer and my previous post has attracted no interest. ASP.Net 2.0...
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: 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
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
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
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 project—planning, 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.