Unable to add TextFragment with Hyperlink

Hello,

It seems, that I can add new text on PDF file page. But I cannot made this text clickable. Could you please look at my code snippet below and tell me any advice?

Mikhael

Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
’ add watermark

Dim sPDFFile = "C:\in\Demo.pdf"
Dim sFontFile = "C:\in\bgothm.ttf"

Dim nFontSize = 20
Dim sMessage = "Trial version"

Dim sOutPDF = "C:\Out\watermark.pdf"


Using pdfDocument = New Document(sPDFFile)
    Using fontStream = File.OpenRead(sFontFile)

        For Each pg In pdfDocument.Pages
            Dim pgRest = pg.Rect

            Dim tf = New TextFragment(sMessage) With {
                .Position = New Position(0, 0)
            }

            tf.TextState.FontSize = nFontSize
            'tf.TextState.Font = FontRepository.OpenFont(fontStream, FontTypes.TTF)
            tf.TextState.Font = FontRepository.FindFont("Arial")
            tf.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Transparent)
            tf.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.DeepSkyBlue)

            tf.TextState.Rotation = 90
            tf.Position = New Position(pgRest.Width, pgRest.Height - tf.Rectangle.Width - nFontSize / 2)
            tf.Hyperlink = New WebHyperlink("https:\\www.google.com")

            Dim tb = New TextBuilder(pg)
            tb.AppendText(tf)
        Next

    End Using
    pdfDocument.Save(sOutPDF)
End Using

End Sub

@Mikhael

We tested using below simple code snippet (C#) and could not replicate the issue that you are mentioning. Can you please try using below code with the latest version of the API and let us know in case you still face any issues:

Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = new TextFragment("ClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClickClick");
text.TextState.ForegroundColor = Color.Blue;
text.TextState.Underline = true;
text.Hyperlink = new WebHyperlink("https://aspose.com");
page.Paragraphs.Add(text);
doc.Save(dataDir + "output.pdf");

output.pdf (2.0 KB)

Hello @asad.ali ,

Thank you for this code snippet. Unfortunately, it seems, that clickable are is not rotated in case if I try rotate text string I put on the page. Please look at my code below.

Mikhael

Using doc = New Document()
    Dim pg = doc.Pages.Add()

    Dim tf = New TextFragment("Trial version")
    tf.TextState.ForegroundColor = Color.Blue
    tf.Hyperlink = New WebHyperlink("https://www.google.com")

    tf.TextState.Rotation = 90 ' clicable are is not rotated!

    pg.Paragraphs.Add(tf)
    doc.Save("C:\Out\output.pdf")
End Using

@Mikhael

Can you please also share the generated output PDF for our reference as well?

@asad.ali ,

Yes, here is the output file.

Mikhael
output.pdf (85.8 KB)

@Mikhael

We are checking it and will get back to you shortly.