彩票走势图

使用Aspose.Pdf在HTML到PDF的转换过程中删除超链接

原创|其它|编辑:郝浩|2012-11-12 16:56:42.000|阅读 1995 次

概述:Aspose.Pdf对于HTML转换为PDF效果是很好的,支持所有不同的HTML对象。包括图像、文本、链接和表单字段在内的所有被容都可以很容易被渲染成合成PDF和可以有场景。

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

Aspose.Pdf对于HTML转换为PDF效果是很好的,支持所有不同的HTML对象。包括图像、文本、链接和表单字段在内的所有被容都可以很容易被渲染成合成PDF和可以有场景。若果需要把一个包含超链接的HTML页面添加为PDF中的纯文本(删除链接信息),需要用到HyperlinkType枚举设置LinkType为None,并指定URL值为空。

HTML

<html>
 <head>
 </head>

 <body>
   <h1><a href="//www.aspose.com"> 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")

标签:

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

文章转载自:慧都控件网

为你推荐

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


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP