使用样式表将html url转换为pdf [英] convert html url to pdf with style sheets

查看:155
本文介绍了使用样式表将html url转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我使用ITextsharp库将html url转换为创建pdf文件。并且我在头部和身体的在线链接上有样式表和java脚本函数。

当我使用下面的代码时,

文件对这些样式表没有任何意义javascript,



解决这个问题的任何想法



hi all,
i'am using ITextsharp library to convert html url to create pdf file. and i have on the head and body online links with style sheets and java script functions.
when i used the below code,
file has no sense with those style sheets and javascript ,

any ideas to solve this problem

public void Text2PDF(string PDFText)
   {
       //HttpContext context = HttpContext.Current;
       StringReader reader = new StringReader(PDFText);
       //Create PDF document
       Document document = new Document(PageSize.A4);
       HTMLWorker parser = new HTMLWorker(document);
       string PDF_FileName = Server.MapPath("PDFddddd_File.pdf");
       PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.Create));
       document.Open();
       try
       {
           parser.Parse(reader);
       }
       catch (Exception ex)
       {
           //Display parser errors in PDF.
           Paragraph paragraph = new Paragraph("Error!" + ex.Message);
           Chunk text = paragraph.Chunks[0] as Chunk;
           if (text != null)
           {
               text.Font.Color = BaseColor.RED;
           }
           document.Add(paragraph);
       }
       finally
       {
           document.Close();
           DownLoadPdf(PDF_FileName);
       }
   }

推荐答案





我试过不同的方式





使用images.websnapr.com - '它有助于拍摄网页截图带风格的页面并返回图片'



然后,我们可以将其添加到PDF





Hi,

I tried Different way


Using images.websnapr.com - 'it help to take screen shot of web page with style and return an Image '

Then, we can add this to PDF


HttpWebRequest request = HttpWebRequest.Create("http://images.websnapr.com/?size=s&url=http%3A%2F%2Fwww.google.com") as HttpWebRequest;
    Bitmap bitmap;
    using (Stream stream = request.GetResponse().GetResponseStream())
    {
        bitmap = new Bitmap(stream);
         bitmap.save(imagepath + "/img1.jpg");
    }


    Image img= Image.GetInstance(imagepath + "/img1.jpg");
    doc.Add(img);





谢谢



Siva Rm K



Thanks

Siva Rm K


尝试将HTML格式化为pdf,您可以在HTML中包含CSS。
Try doing HTML to pdf, you can include CSS in html.


这篇关于使用样式表将html url转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆