翻譯|使用教程|編輯:胡濤|2022-03-16 16:46:09.450|閱讀 331 次
概述:本篇文章主要介紹了如何使用Spire.Doc 在 C# 中將 HTML 文件轉(zhuǎn)換為 PDF 和 XPS,歡迎查閱!
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
HTML 文件廣泛用于收集數(shù)據(jù),出于安全,我們需要將其轉(zhuǎn)換為 PDF 和 XPS 格式的可打印文檔。您可以使用Spire.PDF輕松地將 URL 中的 HTML 頁(yè)面轉(zhuǎn)換為高質(zhì)量的 PDF。本文將重點(diǎn)演示如何借助Spire.Doc將 HTML 文件轉(zhuǎn)換為 PDF 和 XPS 格式的可打印文檔。
首先,檢查將轉(zhuǎn)換為 PDF 和 XPS 的 html 文件。
其次,下載 Spire.Doc 并安裝在您的系統(tǒng)上。Spire.Doc 安裝干凈、專業(yè),并包含在 MSI 安裝程序中。
然后, 通過(guò)以下路徑在下載的 Bin 文件夾中添加 Spire.Doc.dll 作為參考:“..\Spire.Doc\Bin\NET4.0\ Spire.Doc.dll”。
	 
 
現(xiàn)在介紹如何將 HTML 轉(zhuǎn)換為 PDF 和 XPS 的步驟。
第 1 步:從文件加載 HTML 文件。
	
Document document = new Document();
document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None) ;
	
第 2 步:將 HTML 保存為 PDF 和 XPS 的文件格式。
	
//Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF);
//Save html to XPS.
document.SaveToFile("Sample.xps", FileFormat.XPS);
	
調(diào)試后,請(qǐng)檢查以下 PDF 和 XPS 文件作為結(jié)果。
	 
 
完整代碼:
	
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace HTML2PDFXPS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Document document = new Document();
document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None);
//Save html to PDF.
document.SaveToFile("Sample.pdf", FileFormat.PDF);
}
private void button2_Click(object sender, EventArgs e)
{
Document document = new Document();
document.LoadFromFile("Good.htm", FileFormat.Html, XHTMLValidationType.None);
//Save html to PDF.
document.SaveToFile("Sample.xps", FileFormat.XPS);
}
}
}
	
歡迎下載|體驗(yàn)更多E-iceblue產(chǎn)品
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn