Hi Martin,Thank you for contacting Syncfusion support.We have analyzed your requirement “Create TOC more than one page when merging PDF documents”. We have created the sample to achieve your requirement and please find the download link from below,Sample: https://www.syncfusion.com/downloads/support/forum/155121/ze/CreateTOC_When_PDFMerging1986293780KG documentation link: https://www.syncfusion.com/kb/10291/how-to-create-toc-when-merging-pdf-documents-using-c-and-vb-netPlease try the above sample in your end and let us know the result.Regards,Sowmiya Loganathan
|
PdfDocument document = new PdfDocument();
//Add page to the document
PdfPage page = document.Pages.Add();
PdfGraphics graphics = page.Graphics;
//Create a text element with the text and font
PdfTextElement textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
//Draw the text in the first column
PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
textElement = new PdfTextElement(text2, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom+10, page.GetClientSize().Width, page.GetClientSize().Height));
|
|
SizeF size = font.MeasureString(text); |
|
//Create a text element with the text and font
PdfTextElement textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
//Draw the text in the first column
PdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
textElement = new PdfTextElement(text2, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));
result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom+10, page.GetClientSize().Width, page.GetClientSize().Height));
|
Hi Martin,Thank you for your patience.We have analyzed your code snippet and found that you are trying to add a table of contents on the same page. So we need to check whether the table of contents is exceeded the page height or not. So we can achieve this by calculating the text height and get the PdfLayoutResult while drawing the text element. Please refer the below code snippet for your reference,Calculating the text size based on the font:
SizeF size = font.MeasureString(text);Getting the layout result while drawing the text element:
//Create a text element with the text and fontPdfTextElement textElement = new PdfTextElement(text, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));//Draw the text in the first columnPdfLayoutResult result = textElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));textElement = new PdfTextElement(text2, new PdfStandardFont(PdfFontFamily.TimesRoman, 14));result = textElement.Draw(result.Page, new RectangleF(0, result.Bounds.Bottom+10, page.GetClientSize().Width, page.GetClientSize().Height));So based on the above calculation, we can able to add the TOC in pagination. If the contents exceed the first page, you can add the upcoming TOC on the resultant page of existing content. We have created the sample to illustrate this and please find the download link from below,Sample: https://www.syncfusion.com/downloads/support/forum/155121/ze/CreateTOC_When_PDFMerging1064762475Please check the above sample and let us know if you have any concerns about this.Regards,Sowmiya Loganathan
|
//Add the event
document.Pages.PageAdded += new PageAddedEventHandler(Pages_PageAdded);
//Event handler for PageAdded event
static void Pages_PageAdded(object sender, PageAddedEventArgs args)
{
pageCount++;
} |
Hi Martin,
We have analyzed your requirement and this can be achieved by using the event handler PageAddedEventArgs. While adding a new page to PDF document (while pagination), this event triggers. So in this event, we can increase the page count (based on the TOC) and assign to TOC content. Please refer the below code snippet for more details,
//Add the eventdocument.Pages.PageAdded += new PageAddedEventHandler(Pages_PageAdded);//Event handler for PageAdded eventstatic void Pages_PageAdded(object sender, PageAddedEventArgs args){pageCount++;}
Documentataion link : https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PageAddedEventArgs.html
Please try the above solution in your end and let us know the result.
Regards,Sowmiya Loganathan
Hi Martin,To draw the page number of the destination page in the TOC page (if it is paginated), we need to add the TOC contents before all functionalities (adding of bookmarks, document link annotation, page number) to get the pagination details. So based on these details, we can achieve your requirement and please refer the below sample which illustrates the same,Please the above sample in your end and let us know the result.Regards,Sowmiya Loganathan