HTML-file to pdf

  • Thread starter Thread starter Morten Snedker
  • Start date Start date
M

Morten Snedker

From an aspx I wish to grab a html-file from the same directory and
push it to PDF via Response.ContentType = "application/pdf".

Alternatively the html-content can be held in a string variable, which
can be used instead.

Can someone push me in the right direction as to how?

Regards /Snedker
 
From an aspx I wish to grab a html-file from the same directory and push
it to PDF via Response.ContentType = "application/pdf".

In order to stream a PDF file, you need to actually have a PDF file to
stream in the first place - you can't e,g, open an HTML file and just
"pretend" it's a PDF by changing the MIME type...

There are many utilities which will convert an HTML file to PDF:
http://www.google.co.uk/search?sour...lz=1T4GGIH_en-GBGB220GB220&q=HTML+PDF+convert
Alternatively the html-content can be held in a string variable, which can
be used instead.


using System.IO;

string strFileContents = String.Empty;
using (StreamReader objSR = new StreamReader("TestFile.txt"))
{
strFileContents = objSR.ReadToEnd();
}
 
Thanks for your response. I came across http://www.primopdf.com/ which
will generate the PDF. It's quite free, which is the way I prefer it. :-)

The desktop version which installs a printer driver and allows PDF
conversion that way is free - I don't think any of the server-side versions
are, though...
 
almost all the html to pdf converters work by loading the html in an ie
instance, then having ie print to a fake printer via the pdf driver and
capturing the printer output.

there are some converters that do the paring, but they are limited to
simple html or more often simple xhtml.


-- bruce (sqlwork.com)
 
Back
Top