Table cell containing long URL has hyperlink truncated after save as PDF

We’re using the ‘Aspose.Words’ library version 23.2, to build a PDF Document, using the DocumentBuilder class.

No settings have been overwritten as per the below reference, normal save method is used to save the document as PDF.

https://reference.aspose.com/words/net/aspose.words.saving/

[Relevant Properties]

Explicitly set code to not wrap text.

builder.CellFormat.WrapText = false

Once our Table of Cells is constructed, ensure that columns are fixed width (which we inject for each cell explicitly)

table.AutoFit(AutoFitBehavior.FixedColumnWidths);

The issue is that the PDF only detects the first line of the Url as the hyperlink, rather than to the remainder of the full Url

Image below, where the Url is being truncated at the end of the first line.

(Hovering mouse over first line interprets as hyperlink, but not for the remainder of the link)

Note: Selecting all of the Text within the Cell, copying and pasting into a browser does navigate correctly to the intended link/site.

@service.desk sorry I cant reproduce your issue, if you share the code that you are using we can review it. I’m attaching a simple example created by me:

Document doc = new Document();
List list = doc.Lists.Add(ListTemplate.NumberUppercaseLetterDot);
DocumentBuilder builder = new DocumentBuilder(doc);

builder.StartTable();
builder.InsertCell();
builder.ListFormat.List = list;
builder.Writeln("Link 1");
builder.ListFormat.RemoveNumbers();
builder.InsertCell();
// Specify font formatting for the hyperlink.
builder.Font.Color = Color.Blue;
builder.Font.Underline = Underline.Single;
// Insert the link.
builder.InsertHyperlink("Aspose Website", "https://www.aspose.com", false);
// Revert to default formatting.
builder.Font.ClearFormatting();
builder.EndRow();

builder.InsertCell();
builder.ListFormat.List = list;
builder.Writeln("Link 2");
builder.ListFormat.RemoveNumbers();
builder.InsertCell();
// Specify font formatting for the hyperlink.
builder.Font.Color = Color.Blue;
builder.Font.Underline = Underline.Single;
// Insert the link.
builder.InsertHyperlink("https://docs.aspose.com/words/net/insert-hyperlink/", "https://docs.aspose.com/words/net/insert-hyperlink/", false);
// Revert to default formatting.
builder.Font.ClearFormatting();
builder.EndRow();

builder.InsertCell();
builder.ListFormat.List = list;
builder.Writeln("Link 3");
builder.ListFormat.RemoveNumbers();
builder.InsertCell();
// Specify font formatting for the hyperlink.
builder.Font.Color = Color.Blue;
builder.Font.Underline = Underline.Single;
// Insert the link.
builder.InsertHyperlink("Table code example: https://github.com/aspose-words/Aspose.Words-for-.NET/blob/master/Examples/ApiExamples/ApiExamples/ExTable.cs", "https://github.com/aspose-words/Aspose.Words-for-.NET/blob/master/Examples/ApiExamples/ApiExamples/ExTable.cs", false);
// Revert to default formatting.
builder.Font.ClearFormatting();
builder.EndRow();
builder.EndTable();

doc.Save("C:\\Temp\\output.pdf", SaveFormat.Pdf);

output.pdf (32.5 KB)

Eduardo, thanks for your reply and example.

I missed an important detail in that the URL is simply added to the cell as text, not specifically as a hyperlink via the InsertHyperLlink API.

It correctly determines that the text contains a URL but is truncating the URL at the end of the first line it encounters.

@service.desk always use the InsertHyperLlink function to add a hyperlink to the document, that way you will add the link to the document’s encoding; otherwise it will be up to the reader to spot the links.

It comes from a free text data field that we’ve had some users add URLs to and expect to be able to click on them as hyperlinks from within the PDF. It works but only up to the end of the first line that wraps.

Is there some sort of detection for URLs within a body of text that maybe isn’t aware of the wrapping within a cell?

@service.desk that depends on the reader you use, for example if you use Edge to view PDFs it will detect the text formatted as a link and add hyperlink behavior to it.

I see, so Aspose Words is not attempting to detect URLs in the text and add hyperlinks to the PDF document during save, it’s just the viewer? I’ve tried viewing in multiple browsers and dedicated PDF viewers and all behave the same way, truncating the URL at the end of the first line.

@service.desk If the source document has hyperlinks as a simple blue text, in the output PDF document links are not created neither by MS Word nor Aspose.Words. The link is created by the PDF viewer, based on the analysis of the document text. Therefore, incorrect detection of the beginning and end of the URL is not a bug of Aspose.Words, but a bug of PDF viewer.

FYI @eduardo.canal

2 Likes

@service.desk exactly, Aspose.Words don’t transform your document to add links, that is a feature of the Pdf viewer that you are using.

1 Like

Thanks for confirming.

1 Like