2013-10-15 44 views
0

我尝试我的网页转换为PDF格式,我看到这个代码:如何转换网页,以PDF

Response.ContentType = "application/pdf"; 
    Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf"); 
    Response.Cache.SetCacheability(HttpCacheability.NoCache); 
    StringWriter sw = new StringWriter(); 
    HtmlTextWriter hw = new HtmlTextWriter(sw); 
    this.Page.RenderControl(hw); 
    StringReader sr = new StringReader(sw.ToString()); 
    Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); 
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc); 
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream); 
    pdfDoc.Open(); 
    htmlparser.Parse(sr); 
    pdfDoc.Close(); 
    Response.Write(pdfDoc); 
    Response.End(); 

我不是真的知道什么每一行这里没有,但我用它在一个新的网站,它工作,当即时通讯尝试在我的项目上使用它我得到错误,这是给出错误的行: htmlparser.Parse(sr);

这是错误: 找不到路径 'C:\ Program Files文件\ Common Files文件\ Microsoft共享\ DevServer \ 10.0 \ PIC \ 1.JPG' 的一部分

我的PIC \ 1 .jpg在我的项目中,所以我将它添加到该路径(我不知道如果多数民众赞成我需要做的),但它给了我另一个错误: 字体大小太小:0

我接近问题的权利?我需要做些什么来解决它?

+0

这是iTextSharp的。首先,'HTMLWorker'已经被弃用了很长时间,并且不支持CSS。请改用'XMLWorker'。请参阅http://stackoverflow.com/q/9611535/231316和http://stackoverflow.com/a/15362705/231316 –

+0

[将网页转换为HTML到PDF?](http://stackoverflow.com/问题/ 13689255/convert-webpage-to-html-to-pdf) – Thomas

回答