原創|其它|編輯:郝浩|2012-11-12 16:56:42.000|閱讀 2029 次
概述: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@fc6vip.cn
文章轉載自:慧都控件網