在Pdf文件中绘制Html字符串内容 [英] Drawing Html String Content in Pdf File

查看:134
本文介绍了在Pdf文件中绘制Html字符串内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个字符串,这是一个html页面内容,我想将此内容绘制为pdf文件,或将html页面转换为pdf文件。我之前搜索了很多,我发现了很多代码,但他们都使用现成的库,如iTextSharp和DynamicPDF ....,我不想要这个,如果有任何机构知道任何其他解决方案,请告诉我是


谢谢

解决方案

这是一种方法,开源pandoc: http://johnmacfarlane.net/pandoc/ [ ^ ]。



我希望你知道HTML。您可以使用iText或其.NET端口iTextSharp创建PDF:

http://en.wikipedia .org / wiki / IText [ ^ ],

http://itextpdf.com/ [ ^ ],

http:// sourceforge .net / projects / itextsharp / [ ^ ],

http://www.javatips.net / blog / 2011/09 / create-pdf-with-itext-java-tutorial [ ^ ]。



我也提供了Java参考,因为大多数那里有文件。如果您了解C#,那么理解它就不会有问题。



请注意,HTML和PDF概念非常不同,因此一对一的通信不能成立。 HTML很流畅,但PDF在格式化纸质文档中更像是固定的。您可以为一些典型的HTML渲染案例创建一些合理的映射(可能带有选项)。



-SA


当我使用ITextSharp编写此代码时,一个例外告诉我路径不是合法形式。

  string  table1 = GetHtmlPage(我的HTML代码); 
StringReader reader = new StringReader(table1);
凭证凭证= 凭证(PageSize.A4);
HTMLWorker parser = new HTMLWorker(document);
string PDF_FileName = Server.MapPath( )+ / Shopping_cart / billformat / PDF_File.pdf;
PdfWriter.GetInstance(document, new FileStream(PDF_FileName,FileMode.OpenOrCreate));
document.Open();
尝试
{
parser.Parse(reader);
}
catch (例外情况)
{
段落段落= 段落( 错误! + ex.Message);
Chunk text = paragraph.Chunks [ 0 ] as Chunk;
if (text!= null
{
text。 Font.Color = BaseColor.RED;
}
document.Add(paragraph);
}
最后
{
document.Close();
}





任何帮助!!!!!!!!!!!!!!!! !


Hi all,
i have a string which is a html page content, and i want to draw this content as pdf file , or converting html page to a pdf file . i searched a lot before and i have found a lot of codes but all of them using ready made libraries such as iTextSharp and DynamicPDF...., and i didn''t want this, if any body know any other solution, please tell me

thanks

解决方案

This is one of the approaches, open-source pandoc: http://johnmacfarlane.net/pandoc/[^].

I hope you know HTML. You can create PDF using iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^],
http://www.javatips.net/blog/2011/09/create-pdf-with-itext-java-tutorial[^].

I provided Java reference, too, because most of the documentation is there. If you know C#, you won''t have problem to understand it.

Note that HTML and PDF concepts are very different, so one-to-one correspondence cannot be established. HTML is fluid, but PDF is more like a fixed in its formatting paper document. You can create some reasonable mapping (perhaps with options) for some typical cases of HTML rendering.

—SA


when i wrote this code using ITextSharp, an exception tells me "The path is not of a legal form."

string table1 = GetHtmlPage(MY HTML CODE);
       StringReader reader = new StringReader(table1);
       Document document = new Document(PageSize.A4);
       HTMLWorker parser = new HTMLWorker(document);
       string PDF_FileName = Server.MapPath("~") + "/Shopping_cart/billformat/PDF_File.pdf";
       PdfWriter.GetInstance(document, new FileStream(PDF_FileName, FileMode.OpenOrCreate));
       document.Open();
       try
       {
           parser.Parse(reader);
       }
       catch (Exception ex)
       {
           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();
       }



ANY HELP!!!!!!!!!!!!!!!!!


这篇关于在Pdf文件中绘制Html字符串内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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