将HTML转换成PDF格式 - 为ASP.net的任何库转换成、格式、HTML、PDF

2023-09-04 01:20:27 作者:木冇鱼丸

有没有.NET库,将一个HTML输出转换为PDF格式---在一个asp.net应用程序。

Is there any .net library which would convert a HTML output to PDF --- in an asp.net application.

不要紧,如果它是免费的或不

Doesn't matter if it is free or not

推荐答案

根据我自己的经验,我建议的 ABCpdf 库(它不是免费的,但你可以得到一个试用许可证)。看看他们文档部分。

Based on my own experience I'd suggest ABCpdf library (it's not free, but you can get a trial license). Check out their documentation section for how to add HTML output to the PDF document.

简单的例子:

string html = "<html>....</html>";
WebSupergoo.ABCpdf7.Doc doc = new WebSupergoo.ABCpdf7.Doc();

doc.Rect.Left = 10;
doc.Rect.Bottom = 50;
doc.Rect.Top = 750;
doc.Rect.Right = 600;    

doc.SetInfo(0, "License", "[your license code || trial license"]);    
doc.Page = doc.AddPage();

int pageID = doc.AddImageHtml(html, true, 1024, true);
while (doc.Chainable(pageID))
{
    doc.Page = doc.AddPage();
    pageID = doc.AddImageToChain(pageID);
}

for(int i = 1; i < doc.PageCount; i++)
{
    doc.PageNumber = i;
    doc.Flatten();
}

doc.Save("myfile.pdf");

希望这会帮助你。

Hope this will help you.