Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.97/5 (5 votes)
See more: , +
Actually i want to do the conversion from html to pdf, (and i want the css work also), but i have stucked here and get the error which is pointing to my document no page. what happened with it and how to make it work with the css as well?

Here is my C# code:
C#
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Form.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document doc = new Document(PageSize.A4);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
contentwrapper.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
PdfWriter writer = PdfWriter.GetInstance(doc,Response.OutputStream);
doc.Open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(
                                                    new CssAppliersImpl());
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
var cssResolver = new StyleAttrCSSResolver();
var cssFile = XMLWorkerHelper.GetCSS(
 new FileStream(HttpContext.Current.Server.MapPath("~/css/style.css"),
 FileMode.Open));
cssResolver.AddCss(cssFile);
IPipeline pipeline = new CssResolverPipeline(cssResolver,
                             new HtmlPipeline(htmlContext,
new iTextSharp.tool.xml.pipeline.end.PdfWriterPipeline(doc, writer)));
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser p = new XMLParser(worker);
p.Parse(sr);
doc.Close();


Please help me and thank you very much!(Urgent)
Posted
Updated 31-Mar-14 6:03am
v5
Comments
OriginalGriff 31-Mar-14 14:11pm    
Stop bumping your question.
Adding information is fine, but trivial changes such as you are making just to bring it back to the top is rude and unnecessary.
And it's probably the "(Urgent)" bit that is slowing responses anyway...it may be urgent for you, but every question is urgent to it's asker: and not to us who are answering them...
James Rupinson 31-Mar-14 21:21pm    
Okay, thanks a lots that taught me something that i do not know which is don keep bumping my question.. and sorry about that, i m new in here but i just try to get help from here and hopefully you all can help..
navi_s_Patil 7-Apr-14 7:18am    
http://www.c-sharpcorner.com/UploadFile/9f0ae2/convert-aspx-page-into-pdf-in-Asp-Net/

i think this will help you.
James Rupinson 14-Apr-14 2:28am    
thank you very much!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900