Add HTML Hyperlink to PDF Table With Datatable as Datasource

My Code Like this

My Code:

Dim PageTableData As New PdfPage


Dim settings As New WebKitConverterSettings()

settings.EnableJavaScript = True

settings.PdfPageSize = PdfPageSize.A4

settings.Orientation = PdfPageOrientation.Portrait

settings.EnableHyperLink = True

settings.WebKitPath = Server.MapPath("~/bin/QtBinaries")

'

'Assign WebKit settings to HTML converter

htmlConverter.ConverterSettings = settings

'

'Convert Table to PDF

Dim document As New PdfDocument

'

Dim MyFormat As New PdfStringFormat

MyFormat.TextDirection = PdfTextDirection.RightToLeft

MyFormat.Alignment = PdfTextAlignment.Center

'

Dim MyHeaderFont As PdfTrueTypeFont = New PdfTrueTypeFont(New System.Drawing.Font("Arial", 16, FontStyle.Bold), True)

Dim HeaderStyle As New PdfCellStyle

HeaderStyle.Font = MyHeaderFont

HeaderStyle.StringFormat = MyFormat

'

Dim MyFont As PdfTrueTypeFont = New PdfTrueTypeFont(New System.Drawing.Font("Arial", 14, FontStyle.Regular), True)

Dim Style As New PdfCellStyle

Style.Font = MyFont

Style.StringFormat = MyFormat


PageTableData = document.Pages.Add()

PageTableData.Section.PageSettings.Margins.All = 50

header = AddHeader(page, "قائمة الاخبار الملحقة بملف التحليل", "")

'Draw the header in the first page of PDF document

PageTableData.Graphics.DrawPdfTemplate(header, New PointF())

'

MyNewDataTable.Columns(0).Caption = "مصدر الخبر"

MyNewDataTable.Columns(1).Caption = "تاريخ النشر"

MyNewDataTable.Columns(2).Caption = "عنوان الخبر"

'

Dim tableMain As New PdfLightTable()

tableMain.ColumnProportionalSizing = True

tableMain.DataSource = MyNewDataTable

tableMain.Style.ShowHeader = True

tableMain.Style.HeaderStyle = HeaderStyle

tableMain.Style.DefaultStyle = Style

'

tableMain.Columns(2).Width = 75

AddHandler tableMain.BeginRowLayout, AddressOf table_BeginRowLayout

AddHandler tableMain.BeginCellLayout, AddressOf table_BeginCellLayout

tableMain.Draw(PageTableData, New PointF(1, 70))


'

Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As BeginCellLayoutEventArgs)

If args.RowIndex >= 0 AndAlso args.CellIndex = 3 Then

Dim textLink As New PdfTextWebLink

textLink.Text = args.RowIndex

textLink.Url = args.RowIndex

Dim MyPoint As New PointF

MyPoint.X = args.Bounds.X + 5

MyPoint.Y = args.Bounds.Y + 3

textLink.DrawTextWebLink(PageTableData, MyPoint) ---> Error (Object reference not set to an instance of an object.) -- Can any one help plz

 End If

End Sub


The sample I got the idea from:

https://www.syncfusion.com/kb/11169/how-to-insert-hyperlink-in-table-of-a-pdf-document



9 Replies 1 reply marked as answer

GK Gowthamraj Kumar Syncfusion Team August 12, 2021 01:00 PM UTC

Hi Bassem, 
 
Thank you for contacting Syncfusion support.

 
We were able to reproduce the reported exception with provided details on our end. Currently, we are validating on this and we will update the further details on August 16th 2021. 
   
Regards, 
Gowthamraj K 



BY Bassem Yehia August 12, 2021 01:24 PM UTC

Thanks for your help



GK Gowthamraj Kumar Syncfusion Team August 16, 2021 12:32 PM UTC

Hi Bassem, 
 
Thank you for your patience.

 
On our further analysis, we can able to overcome this issue in sample level to setting the Font, while creating PdfTextWebLink. Please refer the below code snippet, 
 
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As BeginCellLayoutEventArgs) 
 
        If args.RowIndex = 1 AndAlso args.CellIndex = 1 Then 
 
            Dim textLink As New PdfTextWebLink 
 
            Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 10.0F) 
 
            textLink.Font = font 
 
            textLink.Text = args.RowIndex 
 
            textLink.Url = args.RowIndex 
 
            Dim MyPoint As New PointF 
 
            MyPoint.X = args.Bounds.X + 5 
 
            MyPoint.Y = args.Bounds.Y + 3 
 
            textLink.DrawTextWebLink(PageTableData, MyPoint) 
 
        End If 
 
 
    End Sub 
 
We have modified the sample with this solution. Please find the download link below, 
 
Kindly try the above solution in your end and let us know the result. 
 
Regards, 
Gowthamraj K 



BY Bassem Yehia August 16, 2021 05:46 PM UTC

Hi, Sir, I try this and solve my problem thanks for your time



============================================

now I have a big issue and need your help with

the file included is the result for the code

Dim MyPoint As New PointF

MyPoint.X = args.Bounds.Location.X + 60

MyPoint.Y = args.Bounds.Location.Y

'

textLink.DrawTextWebLink(PageTableData, MyPoint)


the Y from  args.Bounds.Location.Y list

100

213.7184

295.2315

344.5394

377.7447

427.0526

460.2578

525.6683

558.8736

608.1815

641.3867

30

63.20525

96.41051

145.7184

195.0263

244.3341

293.642

326.8473

360.0526

393.2578

490.8736

540.1815

605.592

638.7972

30

60

109.3079

158.6158

207.9236

241.1289

290.4368

339.7447

389.0526

422.2578

487.6683

536.9762

586.2841

651.6946

30

60

109.3079

158.6158


and not see the other pages in PDF can you please tell me how to handle this


Attachment: الملف_التحليلي_معالي_المستشار_تركي_آل_الشيخ_16_أغسطس_2021_ab3b264c.zip



GK Gowthamraj Kumar Syncfusion Team August 17, 2021 12:04 PM UTC

Hi Bassem, 
 
Thank you for your update.

 
We have analyzed the provided input document on our end, the hyperlink overlink issue may occurs due to the current page not updated properly when paginate. For this, we need to update the current page for every pagination by using BeginPageLayout Event handler. We have attached the modified sample with output document for your reference.  Please try the below sample in your end and let us know the result. 
 
Private Sub table_BeginPageLayout(sender As Object, ByVal args As BeginPageLayoutEventArgs) 
        PageTableData = args.Page 
End Sub 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Marked as answer

BY Bassem Yehia August 17, 2021 08:37 PM UTC

Thanks this is really helpful for me



GK Gowthamraj Kumar Syncfusion Team August 18, 2021 04:42 AM UTC

Hi Bassem, 
 
Thank you for your update. We are glad to know that your problem has been solved. 

Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 



BY Bassem Yehia August 18, 2021 08:47 PM UTC

Hi Sir


Can I put a PNG image or icon instead of text in 

Dim textLink As New PdfTextWebLink 

textLink.Text= (Image location or image in Base64)


image in Base64 I try this and not worked for me



GK Gowthamraj Kumar Syncfusion Team August 19, 2021 10:00 AM UTC

Hi Bassem, 
 
Thank you for your update.

No. We do not have support for drawing image with PdfTextWebLink annotation in the PDF document. As a workaround, we can achieve this requirement by using PdfUriAnnotation. Please try the below code snippet on your end let us know the result.

 
Private Sub table_BeginCellLayout(ByVal sender As Object, ByVal args As BeginCellLayoutEventArgs) 
 
        If args.CellIndex = 3 Then 
            If args.Value <> "ID4" Then 
 
 
                Dim image As New PdfBitmap("E://Logo.png") 
 
                'Draw the image 
 
                PageTableData.Graphics.DrawImage(image, args.Bounds) 
 
                Dim rect As New RectangleF(args.Bounds.X, args.Bounds.Y, args.Bounds.Width, args.Bounds.Height) 
 
                Dim url2 As PdfUriAnnotation = New PdfUriAnnotation(rect) 
 
                'Add the link 
                url2.Uri = "E://Logo.png" 
                'Border 
                url2.Border = New PdfAnnotationBorder(0, 0, 0) 
                'Add the color 
                url2.Color = New PdfColor(Color.White) 
                'Add the annotation 
                PageTableData.Annotations.Add(url2) 
 
            End If 
 
        End If 
    End Sub 
 
We have attached the output document for your reference. Please find the document from below, 
 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon