Free Support Forum - aspose.com

Hyperlinks Rendering Performance

<!–[if gte mso 10]> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Hi Aspose team!


Recently I did a lot of performance testing of Aspose.Pdf 5.2 and found a serious bottleneck related to hyperlinks.


So the generated document is based on 6k data records which are rendered to approximately 2000 pages (40-70MB), also is contains ToC, Index and embedded hyperlinks which provide just another way to navigate the content.


After numerous tests, it appears that Aspose.Pdf is not able to handle huge amounts of hyperlinks, e.g.: index consists of approx. 100 pages and contains 6k+ hyperlinks linked to different paragraphs. The code which creates PDF DOM runs pretty fast, but delay happens during Pdf.Save(memoryStream) method. Here are details:


6k data set, no hyperlinks

  • Data access and DOM generation – 1min
  • Aspose.Pdf save to stream – 1min

Same but index hyperlinks on

  • Data access and DOM generation – 1min
  • Aspose.Pdf save to stream – 10min (+9min with ToC/embedded hyperlinks on)

Here is the way I add hyperlinks
to text segments:


private void AddIndexItem(Section section, string titleText, Rect frame, IEnumerable<SectionLink> sectionLinks)

{

const string indexSep = ", ";

var root = section.GetRoot();

var itemStyle = new TextInfo

{

FontName = “Arial”,

FontSize =10,

Color = new Color("Black"),

IsUnicode = true,

};

// Assemble and measure segments: title, indexes and elipsis

var titleWidth = TextMeasure.GetStringWidth(titleText, itemStyle);

var indexesText = string.Join(indexSep,

sectionLinks.Select(sl => sl.Index.ToString()));

var indexesWidth = TextMeasure.GetStringWidth(indexesText, itemStyle);

var ellipsisWidth = TextMeasure.GetStringWidth(ChartDocument.Elipsis, itemStyle);

var ellipsisCount = (int)Math.Truncate((frame.Width - titleWidth - indexesWidth) / ellipsisWidth);

var ellipsisText = ellipsisCount > 0

? new string(ChartDocument.Elipsis[0], ellipsisCount) : "";


// Add title with a link to first index item

var firstLink = new Hyperlink

{

LinkType = HyperlinkType.Local,

TargetID = sectionLinks.First().SectionId,

};

var firstIndexItem = new Text(section)

{

Segments =

{

new Segment(titleText)

{

IsSymbolReplaceable = false,

Hyperlink = firstLink,

},

new Segment(ellipsisText)

{

Hyperlink = firstLink

},

},

PositioningType = PositioningType.ParagraphRelative,

ReferenceParagraphID = root.ID,

Left = frame.Left.ToFloat(),

Top = frame.Top.ToFloat() + 1,

TextInfo = itemStyle,

WrapLines = 1,

};

section.Paragraphs.Add(firstIndexItem);

// Add indexes with the corresponding links

var indexItems = new Text(section)

{

PositioningType = PositioningType.ParagraphRelative,

ReferenceParagraphID = root.ID,

Left = (frame.Right - indexesWidth).ToFloat(),

Top = frame.Top.ToFloat() + 1,

TextInfo = itemStyle,

WrapLines = 1,

};

sectionLinks.ToList()

.ForEach(sl =>

{

indexItems.Segments.Add(); // walkaround 1

indexItems.Segments.Add(

new Segment(

sl.Index == sectionLinks.Last().Index

? sl.Index.ToString()

: string.Concat(sl.Index, indexSep))

{

TextInfo = { FontName = “Arial” }, // walkaround 2

Hyperlink =

{

LinkType = HyperlinkType.Local,

TargetID = sl.SectionId,

}

});

});

section.Paragraphs.Add(indexItems);

}


private struct SectionLink

{

public int Index;

public string SectionId;

}


Any suggestions or ideas how to avoid the performance degradation? Ideally I wish hyperlinks overhead to be 30 sec max instead of 9 min. The issue is urgent, because product going to release in a few months


Thanks in advance,

Alex

Hello Alex,

Thanks for using our products and sorry for replying you late.

We are working over this query and will get back to you soon. We apologize for your inconvenience.

Hello Nayyer,

Any updates on the case?

Alex

Hello Alex,

Sorry for replying you late. I am still trying to replicate this problem over my end. Soon you will be updated with the status of correction. Once again, please accept our humble apologies for this inconvenience.

Hello Alex,

Thanks for your patience.

I have tested the scenario in details and I am able to notice that when large number of Hyperlinks are added to TOC, the document generation time is drastically increasing. For the sake of correction, I have logged this problem as PDFNET-27284 in our issue tracking system. We will further look into the details of this problem and will keep you updated on the status of correction. Please be patient and spare us little time. We apologize for your inconvenience.

Thanks a lot, Nayyer,

Here are the test application I used to test hyperlinks performance and the metrics (attached). As far as I understand, performance depends on number of hyperlinks, number of pages and sections - which IMHO is natural. DOM generation time mostly stays the same.

Hope this will help,
Alex

Hello Alex,

Thanks for sharing the resource files.

I have tested the project that you have shared and as per my observations over Windows7 64Bit Professional where my system is Intel Core i5 2.80GHz with 8GB RAM, following are the results.

DOM generated in : 26.6240692 sec
PDF generated in : 358.0625772 sec
Total : 384.6866464 sec

Anyways, we will definitely consider the information that you have shared during the resolution of this problem and as soon as we have some updates, we will let you know. Please be patient and spare us little time.

The issues you have found earlier (filed as 27284 ) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan