原創(chuàng)|其它|編輯:郝浩|2012-09-21 16:51:58.000|閱讀 1624 次
概述:當我們將HTML頁面轉(zhuǎn)化為PDF文件時,往往會因為HTML文件里含有太多的超鏈接而感到煩惱。下面,我們就來了解一下如何用Aspose.Pdf for .NET刪除這些超鏈接的。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
當我們將HTML頁面轉(zhuǎn)化為PDF文件時,往往會因為HTML文件里含有太多的超鏈接而感到煩惱。下面,我們就來了解一下如何用Aspose.Pdf for .NET刪除這些超鏈接含有超鏈接的。
HTML網(wǎng)頁如下:
運行如下代碼:
HTML
<html>
<head>
</head>
<body>
<h1><a href="//fc6vip.cn"> Hyperlink to Aspose website.</a></h1>
<p> <u> Underline text without hyperlink </u></p>
</body>
</html>
C#
// Path information of source HTML file
string file = @"d:/pdftest/Sample.html";
// create an object of Pdf class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// Bind the source HTML file with Pdf object
pdf.BindHTML(File.ReadAllText(file));
// get traverse through each segment inside text paragraph
foreach (Aspose.Pdf.Generator.Segment seg in (pdf.Sections[0].Paragraphs[0] as Aspose.Pdf.Generator.Text).Segments)
{
// Verify that the segment URL value is not null
if (seg.Hyperlink.Url != null)
{
// specify the LinkType of Segment object as none
seg.Hyperlink.LinkType = Aspose.Pdf.Generator.HyperlinkType.None;
// set the value of URL for segment object as blank
seg.Hyperlink.Url = "";
// remove the Underline from segment
seg.TextInfo.IsUnderline = false;
// change font color to black instread of default Blue for Hyperlinks
// you may also comment the following line to display in blue
seg.TextInfo.Color = new Aspose.Pdf.Generator.Color("Black");
}
}
// save the resultant PDF
pdf.Save(@"d:\pdftest\Sample_1.pdf");
VB.NET
' Path information of source HTML file
Dim file As String = "d:/pdftest/TestHTMLFile.html"
' create an object of Pdf class
Dim Pdf As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
' Bind the source HTML file with Pdf object
Pdf.BindHTML(System.IO.File.ReadAllText(file))
'Dim seg As Segment
' get traverse through each segment inside text paragraph
For Each seg As Aspose.Pdf.Generator.Segment In TryCast(Pdf.Sections(0).Paragraphs(0), Aspose.Pdf.Generator.Text).Segments
' Verify that the segment URL value is not null
If (seg.Hyperlink.Url <> Nothing) Then
' specify the LinkType of Segment object as none
seg.Hyperlink.LinkType = Aspose.Pdf.Generator.HyperlinkType.None
' set the value of URL for segment object as blank
seg.Hyperlink.Url = ""
' remove the Underline from segment
seg.TextInfo.IsUnderline = False
' change font color to black instread of default Blue for Hyperlinks
' you may also comment the following line to display in blue
seg.TextInfo.Color = New Aspose.Pdf.Generator.Color("Black")
End If
Next
' save the resultant PDF
Pdf.Save("d:\pdftest\TestHTMLFile_12.pdf")
刪除超鏈接后生成的PDF文件如下:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務必注明出處、不得修改原文相關鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)