彩票走势图

Aspose.Pdf将HTML转换为PDF时如何删除超链接

原创|其它|编辑:郝浩|2012-09-21 16:51:58.000|阅读 1599 次

概述:当我们将HTML页面转化为PDF文件时,往往会因为HTML文件里含有太多的超链接而感到烦恼。下面,我们就来了解一下如何用Aspose.Pdf for .NET删除这些超链接的。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

当我们将HTML页面转化为PDF文件时,往往会因为HTML文件里含有太多的超链接而感到烦恼。下面,我们就来了解一下如何用Aspose.Pdf for .NET删除这些超链接含有超链接的。

HTML网页如下:

Aspose.Pdf .NET将HTML转换为PDF时如何删除超链接

运行如下代码:

HTML

 <html>
 <head>
 </head>

 <body>
   <h1><a href="//pclwef.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文件如下:

Aspose.Pdf .NET将HTML转换为PDF时如何删除超链接


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP