I have an existing application that uses that Aspose.Pdf.Generator class to convert xml to pdf. I would like to modify my xml template to include a hyperlink in the resulting pdf document. If possible, I do not want to make any changes to the C# code. What is the xml format for specifying a hyperlink?
For example, if I have this xml document:
<?xml version="1.0" encoding="utf-8" ?>
<Pdf xmlns="Aspose.Pdf" DestinationType="FitPage" >
<Section ID="section1" PageMarginLeft="2cm" PageMarginRight="2cm"
PageMarginTop="2cm" PageMarginBottom="3.5cm"
PageSize="Letter" FontName="Arial" FontSize ="11">
<Table ColumnWidths="510" DefaultCellPaddingTop="5" BackgroundColor="#F3F2F1" DefaultCellPaddingLeft="2" DefaultCellPaddingRight="2" DefaultCellPaddingBottom="5">
<Row>
<Cell BackgroundColor="white" ></Cell>
</Row>
<Row >
<Cell BackgroundColor="#B0008E">
<Text MarginTop="0inch" Alignment="Center" >
<Segment FontSize="12" color="white" IsTrueTypeFontBold = "True"> HELLO WORLD </Segment>
</Text>
</Cell>
</Row>
<Row>
<Cell>
<Text>
<Segment FontSize="11">
Link goes here (something like <a href="http://www.google.com">Click here to go to Google</a> )
</Segment>
</Text>
</Cell>
</Row>
</Table>
</Section>
</Pdf>
How should the “Link goes here” line be formatted to get a hyperlink in the pdf document?
Thank you!
@kgkayak
Thank you for contacting support.
I have observed the xml document shared by you and have noticed that you are using an older version of Aspose.Pdf API. We recommend using latest version of Aspose.Pdf for .NET because it contains more features and bug fixes. Also, the support is provided on basis of latest available version i.e Aspose.Pdf for .NET 17.11. So, please upgrade to the latest version.
However, using latest version of Aspose.Pdf, a sample line for including a hyperlink in resulting PDF document is, as under:
<HtmlFragment>
<![CDATA[
Link goes here (something like <a href="http://www.google.com">Click here to go to Google</a> )
]]>
</HtmlFragment>
I hope this information will be helpful. Please let us know if you need any further assistance.
Hi Farhan,
I agree that when this applications gets upgraded, the upgrade should include a migration to the latest version of Aspose. However, I don’t have the option of making changes to the application at this point. Right now I need to support the existing application, and the existing application needs to have a hyperlink added to a pdf document generated by the xml to pdf conversion process.
I can understand not wanting to offer free support for an old version of your product, but I am disappointed that the online documentation for this version is no longer available on your website. This is something I will have to consider when choosing a tool to use for converting documents in the future.
@kgkayak
I would like to share with you that, in the latest version of the API, the old Aspose.Pdf.Generator approach has been deprecated and in order to work with new recommended Document Object Model (DOM) approach, you can find .xsd file in Aspose.Pdf API folder. This xsd file shows sample XML Schema which needs to be followed by each XML file in order to work with latest version. I have updated my previous response in accordance with this XML Schema where you can use <HtmlFragment> to display HTML content as per your requirements.
Please note, HTML contains tags similar to XML, so when you write HTML inside any XML tag, the parser treats it as XML markups and they simply cannot be recognized as HTML tags. The issue can be overcome by using “CDATA” Section in XML. The CDATA Section contains text which is not parsed by the parser or in other words, it is not treated as XML markups.
However, if you still want to work with an older version of the API then you may update the text tag for second row with:
<Text IsHtmlTagSupported="true">
<Segment FontSize="11">
<![CDATA[
Link goes here (something like <a href="http://www.google.com">Click here to go to Google</a> )
]]>
</Segment>
</Text>
Updated xml file, to work with older version, has been attached for your kind reference. Hyperlink.zip
XML_Schema_DOM.zip
I hope this will be helpful. Please let us know if you need any further assistance.