如何从HTML生成PDF? [英] How to Generate PDF from HTML?
本文介绍了如何从HTML生成PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从以下html字符串生成pdf
< < span class =code-leadattribute> font face = verdana = size = 2 = > < span style = > 会计< / span > < / font >
解决方案
我在我的项目中使用了PDFDuo-NET.dll(版本2.3)非常有用。首先,您需要将ASPX的内容转换为HTML,然后将该HTML内容转换为PDF文件,或者我使用的另一种方法是创建一个简单的HTML字符串,然后将其转换。请参阅下面的C#代码:
使用系统;
使用 System.Web;
使用 System.Web.UI;
使用 System.IO;
使用 DuoDimension;
public partial class _Default:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
string html = < table width = 240 > +
< tr style = background-color:#00AAFF >< td width = 50% >产品< / td>< td width = 25% >数量< / td>< td>费用< / td>< / tr> +
< tr>< td>产品名称1< / td>< td> 5< / td>< td>
100< / td>< / tr> ; +
< tr>< td>产品名称2< / td> ;< td> 15< / td>< td>
300< / td>< / tr> +
< tr>< td>产品名称3< / td>< td> 55< / td>< td>
Generate pdf from following html string
<font face="" verdana="" size="" 2=""><span style=""> Accounting</span></font>
解决方案
I have used PDFDuo-NET.dll (version 2.3) in my project which is very useful. First, you need to convert content of your ASPX to HTML and then converted that HTML content into a PDF file or another way which I use is to create a simple HTML string and then convert it.See below C# code:
using System; using System.Web; using System.Web.UI; using System.IO; using DuoDimension; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string html = "<table width="240">" + "<tr style="background-color:#00AAFF"><td width="50%">Product</td><td width="25%">Quantity</td><td>Cost</td></tr>" + "<tr><td>Product Name 1</td><td>5</td><td>
100</td></tr>" + "<tr><td>Product Name 2</td><td>15</td><td>
300</td></tr>" + "<tr><td>Product Name 3</td><td>55</td><td>
这篇关于如何从HTML生成PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文