Hello,
we are generating documents by loading HTML to Aspose.Words Document, which we eventually save as PDF. There’s a Table of Contents, and per our measurement, parsing the Table of Contents takes almost 25 % of the total time. We were trying to find a solution with Aspose.PDF, but working with a ToC in Aspose.PDF seems even more problematic - replacing a ToC placeholder in HTML with a real ToC seems impossible during the HTML->PDF import.
Could you please advise us on how could this be optimized (in Words) or what would be the best way how to handle the ToC in Aspose.PDF when creating the document from HTML?
Thank you!
@KamilPavelka Could you please attach your problematic input and output documents along with code you are using for conversion? We will check your documents and code and provide you more information.
With Aspose.Words you can insert TOC field into the document, which will be updated automatically upon saving document to PDF. Probably this will give better performance than loading pre-built TOC from HTML.
I can’t give you the docs nor the code, would have to be cleared. Is there a possibility to enter a ToC in a specific place in the Document with Aspose.HTML or Aspose.PDF? Do these libraries have that feature? If so, could you point me in the direction of some code example how to do that? We’re looking at various options.
@KamilPavelka You should check with Aspose.HTML and Aspose.PDF in the appropriate support forums. Regarding Aspose.Words, you can put some placeholder in your HTML and then replace it with standard MS Word TOC field. For example you can use a bookmark as a placeholder:
<html>
<body>
<p><a name="TOC"></a></p>
<p>This is some paragraph after the toc.</p>
<h1>First level heading</h1>
<p>Some dummy text</p>
<h2>Second level heading</h2>
<p>Some dummy text</p>
<h3>Third level heading</h3>
<p>Some dummy text</p>
</body>
</html>
Then you can insert TOC field in bookmark:
Document doc = new Document("C:\\Temp\\in.html");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move to bookmark.
builder.moveToBookmark("TOC");
// Insert TOC
builder.insertTableOfContents("\\o \"1-3\" \\h \\z \\u");
builder.writeln();
builder.insertBreak(BreakType.PAGE_BREAK);
// Update fields in the document.
doc.updateFields();
// Save output to PDF.
doc.save("C:\\Temp\\out.pdf");
out.pdf (44.6 KB)
1 Like