Free Support Forum - aspose.com

Line break cuts off link

Dear Aspose support,

I have a very long link inside a TextFragment, which I want to be recognised as a link and be redirected to it upon click.

PDF readers, like for example Adobe Acrobat Reader, recognise links that are just normal text like for example “https://forum.aspose.com” and redirect upon click to the referenced website.

However, if you have a very long link, so that it does not fit into one line, a line break is added, which cuts off the link.
LinkCutOff.jpg (37.1 KB)

Removing the line break by for example putting the text inside a table with the row.setWordWrapped(false) results in the text going beyond the right page margin and not being readable.

Is it possible, to have a very long text without having line breaks added to the text, but having the text still “breaking” when reaching the right page margin?

Word for example can export a PDF where long texts that break upon reaching the right page margin don’t have a line break that would cut off a link.
image.png (10.6 KB)

I cannot simply use textFragment.setHyperlink, because the textFragment might contain text other than the link, or even multiple links.

I use Java aspose-pdf 19.3 .

Thank you for your help.

Kind regards,
Andreas Staudacher

@andreas.staudacher,

Can you please share sample project along with source file so that we may further investigate to help you out.

Thank you for the quick response.

Here is a sample project:
Examples.zip (55.4 KB)

Here is the relevant source code:

    DocumentFactory documentFactory = new DocumentFactory();
    Document document = documentFactory.createDocument();

    Page page = document.getPages().add();

    String text = "Text that might come before a link "
            + "https://this-is-a-very-long-link.com/10101000000100101001/ABCDEFGHIJKLMNOPQURST/FilenameAfterAVeryLongUrl.pdf"
            + " Some more Text https://forum.aspose.com/\n";
    TextFragment textFragment = new TextFragment(text);


    page.getParagraphs().add(textFragment);

    document.save("testFile.pdf");

@andreas.staudacher,

I have observed your comments. Can you please visit Add Hyperlink article. This will help you to achieve your requirements. Please share feedback with us if there is still an issue.

@Adnan.Ahmad

Thank you for your help, sadly this does not help me in my case.

I need links in text to be recognised automatically, since I don’t know the text preemptively and with that don’t know if the text contains any links at all or multiple.

Is there a way, to make links in text, without specifying GoToURIActions for every link where you would need to know the URI the link should go to (and with that would need to parse the text for links contained in it)?

@andreas.staudacher,

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-47871 in our issue tracking system to investigate and resolve this issue as soon possible.