Printing HTML Server Side

  • Thread starter Ahmad Abu-Raddad
  • Start date
A

Ahmad Abu-Raddad

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 these does not take HTML.

If anyone can help please do.
 
L

Lau Lei Cheong

Could you explain what is "does not take HTML" means? Printing blank pages
or having exception?

To my understanding this function should treat the string to be normal ASCII
string and not trying to interprete it, so it may be just some coding error.

What parameter does you pass to StringFormat? Does you add the handler to
PrintDocument.PrintPage event?

Try printing some short string first would be worthwhile.
 
A

Ahmad Abu-Raddad

Thanks for your reply, I may have not said it clearly

what I have alraedy done is this:

'---------------------------------------------------------------------------
--------------------------------------------------------------------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

oPrintDocument.PrinterSettings.PrinterName = "HPLaserJ.2"

oPrintDocument.Print()

End Sub

Private Sub oPrintDocument_PrintPage(ByVal sender As Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs) Handles oPrintDocument.PrintPage

Dim printFont As New Font("Arial", 10)

e.Graphics.DrawString("Hello World!!!", printFont, Brushes.Black, 5, 5,
New StringFormat)

End Sub

'---------------------------------------------------------------------------
--------------------------------------------------------------------------

and it is working just fine, but this technique prints a string, I want to
print an HTML Page!!!

I tried reading an HTML page into a StreamReader and read StreamReader line
by line and print it, but the print out came with the HTML Tags, NOT the
inerpreted result in the browser.

Ahmad
 
P

Paul Glavich [MVP - ASP.NET]

You have answered your own question. HTML is text that the browser first
interprets and displays for you. The printer knows of no such
interpretation. It knows about raw ASCII, PCL and other printer/byte based
formats (Postscript not withstanding). IE (and other browsers) first
interpret the HTMl onto their canvas and represent as the graphical UI you
see. Thus when you ask IE to print, it prints what it has already interprted
and rendered from ist canvas to the printer. Printers dont know about HTML,
it needs to interpreted/rendered first.

You can try loading up an instance of the Internet Explorer COM component
and rendering the file to that, then getting it to print. I am sure there
are some browser type controls/objects you can use but I have never
personally done this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top