HTML to PDF Question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

HTML to PDF Question

Yonatan Bisk
I've spent the last few days reading through the mailing list and thats where I've pulled my current code from.
 
I have an asp.net site that generates reports from database lookups.  I want to allow the customer to save these as a pdf.
 
I'm currently doing the following:
 

myHtml +=

"<html>";

myHtml +=

"<body>";

myHtml +=

"<font face=verdana>";

myHtml +=

"<table width=66% border=0>";

... etc ..

myHtml +=

"</table>";

myHtml +=

"</font>";

myHtml +=

"</body>";

myHtml +=

"</html>";

 

Document

document = new Document( PageSize.A4, 80, 50, 30, 65);

MemoryStream m = new MemoryStream ();

try

{

PdfWriter writer = PdfWriter.GetInstance(document, m);

writer.CloseStream =

false;

document.Open();

ITextHandler xmlHandler = new ITextHandler (document);

System.Xml.

XmlTextReader _xmlr = new System.Xml.XmlTextReader (new StringReader(myHtml));

xmlHandler.Parse(_xmlr);

}

catch(Exception ex)

{

Console.Error.WriteLine(ex.Message);

Console.Error.WriteLine(ex.StackTrace);

}

byte[] b = m.ToArray();

Response.Clear();

Response.ContentType =

"application/pdf";

Response.AppendHeader(

"Content-Length", b.Length.ToString());

Response.AppendHeader(

"Content-Disposition", "inline;filename=myPDF.pdf");

Response.OutputStream.Write(b, 0, b.Length);

Response.OutputStream.Flush();

Response.OutputStream.Close();

m.Close();

Response.End();

 
This always results in a "The File is damaged and cannot be repaired" error...
 
any asisstance would be greatly appreciated.
 
 
Thank you
 
 
 


--
Yonatan

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
itextsharp-questions mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/itextsharp-questions
Reply | Threaded
Open this post in threaded view
|

Re: HTML to PDF Question

joeller
This post has NOT been accepted by the mailing list yet.
Did you ever get a solution to this problem?