用新插件将HTML转换为PDF
Spire.PDF for .NET 是一款专门对 Word 文档进行操作的 .NET 类库。致力于在于帮助开发人员轻松快捷高效地创建、编辑、转换和打印 Microsoft Word 文档,而无需安装 Microsoft Word。
行号用于在每行文本旁边显示 Word 自动计算的行数。当我们需要参考合同或法律文件等文档中的特定行时,它非常有用。word中的行号功能允许我们设置起始值、编号间隔、与文本的距离以及行号的编号方式。使用 Spire.Doc,我们可以实现上述所有功能。本文将介绍如何将 XPS 转为PDF 格式。
欢迎加入spire技术交流群:767755948
本节重点介绍新的HTML转PDF插件。有了这个新的插件,我们支持转换带有丰富元素的HTML页面,如HTTPS、CSS3、HTML5、JavaScript。
您需要下载Spire.PDF并安装到您的系统中,在下载的Bin文件夹中添加Spire.PDF.dll作为引用,路径如下'.\Spire.PDF\Bin\NET4.0\Spire.PDF.dll'。为了获得新的插件,您可以直接从下载文件中获取新的插件: .
在Windows系统中,您需要解压转换器插件包,并复制到Spire.Pdf.dll同一文件夹下的 "plugins "文件夹中。在使用QT插件将HTML转换为PDF之前,请确保您的计算机上安装了Microsoft Visual C++ 2015 Redistributable。
在Mac和Linux系统中,您需要将zip文件复制到系统下,然后解压convertor插件包,以成功使用插件。
C# 和 ,您可以下载并试用。
调用插件非常简单,请查看下面的C#代码将HTML转换为PDF。
[C#]
using System.Drawing;
using Spire.Pdf.Graphics;
using Spire.Pdf.HtmlConverter.Qt;
namespace SPIREPDF_HTMLtoPDF
{
class Program
{
static void Main(string[] args)
{
HtmlConverter.Convert("//www.wikipedia.org/", "HTMLtoPDF.pdf",
//enable javascript
true,
//load timeout
100 * 1000,
//page size
new SizeF(612, 792),
//page margins
new PdfMargins(0, 0));
System.Diagnostics.Process.Start("HTMLtoPDF.pdf");
}
}
}
[VB.NET]
Imports System.Drawing
Imports Spire.Pdf.Graphics
Imports Spire.Pdf.HtmlConverter.Qt
Module Module1
Sub Main()
HtmlConverter.Convert("//www.wikipedia.org/", "HTMLtoPDF.pdf", True, 100 * 1000, New SizeF(612, 792), New PdfMargins(0, 0))
System.Diagnostics.Process.Start("HTMLtoPDF.pdf")
End Sub
End Module
请查看以下有效截图:
下面的示例将重点介绍将HTML字符串转换为PDF的新插件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
using System.IO;
using Spire.Pdf.HtmlConverter;
using System.Drawing;
namespace HTMLToPDFwithPlugins
{
class Program
{
static void Main(string[] args)
{
string input =@"<strong>This is a test for converting HTML string to PDF </strong>
<ul><li>Spire.PDF supports to convert HTML in URL into PDF</li>
<li>Spire.PDF supports to convert HTML string into PDF</li>
<li>With the new plugin</li></ul>";
string outputFile = "ToPDF.pdf";
Spire.Pdf.HtmlConverter.Qt.HtmlConverter.Convert(input,
outputFile,
//enable javascript
true,
//load timeout
10 * 1000,
//page size
new SizeF(612, 792),
//page margins
new Spire.Pdf.Graphics.PdfMargins(0),
//load from content type
LoadHtmlType.SourceCode
);
System.Diagnostics.Process.Start(outputFile);
}
}
}
有效截图:

QQ交谈
在线咨询

渝公网安备
50010702500608号

客服热线