How to merge PDF with Table of Contents?

Hi,


I have a bunch of PDF files that I want to merge into a single one, but at the same time I want to create ToC - one heading per document. Is it possible?

Thank you,
Mariusz

Hi Mariusz,


Thanks for your inquiry. You can easily achieve your requirement by creating TOC of your merged PDF. First you should merge your source files into a single PDF document and during merger process also keep track of your source PDF files and their total page numbers (fileName, totalPages) in some collection object. Later can create TOC entries for each document, specify TOC entry title and destination page on the basis of collection data. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi Mariusz,

Adding more to Tilal’s comments, in case have not found the information for concatenating PDF files, please follow the instructions specified over Concatenate PDF Files

Thank you. It seems to work, just partially.


I used the code below, but no matter what font size I set(I tried 20 and 120) the “Table of Contents” headers is almost not visible, it’s so small that it looks like a line. Plus I’d like the ToC to look more like the real ToC, I’d like page numbers on the right and dots between the headers and the page number. Plus some margins for different heading levels, right now all are aligned to the left without any margin. Check the attached results.


final com.aspose.pdf.Page tocPage = pdfDocument.getPages().insert(1);
final com.aspose.pdf.TocInfo tocInfo = new com.aspose.pdf.TocInfo();
final com.aspose.pdf.TextFragment title = new com.aspose.pdf.TextFragment(“Table Of Contents”);
title.getTextState().setFontSize(120);
title.getTextState().setFontSize(com.aspose.pdf.FontStyles.Bold);

// Set the title for TOC
tocInfo.setTitle(title);
tocPage.setTocInfo(tocInfo);

for (final ToCItem head : headings) {
// Add heading to page containing TOC
// Create Heading object
final com.aspose.pdf.Heading heading2 = new com.aspose.pdf.Heading(head.getLevel());

final com.aspose.pdf.TextSegment segment2 = new com.aspose.pdf.TextSegment();
heading2.setTocPage(tocPage);
heading2.getSegments().add(segment2);

// Specify the destination page for heading object
heading2.setDestinationPage(pdfDocument.getPages().get_Item(head.getPage() + 2));

// Destination page,
heading2.setTop(pdfDocument.getPages().get_Item(head.getPage() + 2).getRect().getHeight());

// Destination coordinate
segment2.setText(head.getLabel());

// Add heading to page containing TOC
tocPage.getParagraphs().add(heading2);
}


Thanks in advance for your help,
Mariusz

Hi Mariusz,


Thanks for your inquiry. We are looking into your issue and will get back to you soon.

Best Regards,

I can see that class (com/groupdocs/viewer/handlers/etc/IViewerHandlerBase) is references in CommonApi.class in groupdocs-annotation-1.8.0 but it doesn’t exist. Was that release tested?

It looks like an obfuscation issue. It would be much better for us if you wouldn’t obfuscate the code. We use many commercial libraries and Aspose/GroupdDocs code is the only one obfuscated. That makes it hard to read and investigate.

Hi Mariusz,


We are sorry for the inconvenience. I have tested the scenario using Aspose.Pdf for Java 9.7.0 and noticed that TOC Title font is being honored properly but TOC have formatting issues( page number, margin). We have linked your issue with ticket PDFNEWJAVA-34197, logged for TOC formatting issue in our issue tracking system. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

Hi Mariusz

It seems you want to post above queries at GroupDocs support forum. Please contact GroupDocs support for the resolution.

We are sorry for the inconvenience caused.

Best Regards,

Ah, yes, wrong forum:) Concerning the ToC, the ToC header size is not respected as in the attached sample. Margins are OK when I define them for each ToC level but there is no corresponding line number and dots between the heading and the line number.

Hi Mariusz,


Thanks for your feedback. For TOC title please update your code for FontStyle as following it will resolve the FontSize issue. However we have already noticed that Page number and dotted line of TOC entries are missing. We will notify you as soon as it is resolved.

title.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);

We are sorry for the inconvenience caused.

Best Regards,

OK, great, thank you! I have one additional question, right now to get the correct margins, I need to use the code below. Can you make some default setting here, so all the headings can have the correct margin set based on the level?


final LevelFormat[] formatArray = new LevelFormat[] { new LevelFormat(), new LevelFormat(), new LevelFormat() };
tocInfo.setFormatArray(formatArray);
for (int i = 0; i < tocInfo.getFormatArrayLength(); i++) {
tocInfo.getFormatArray()[i].setMargin(new MarginInfo());
tocInfo.getFormatArray()[i].getMargin().setLeft(i * 20);
}

Thank you,
Mariusz

Hi Mariusz,


Thanks for your inquiry. Please note currently default margin value for all levels is 0 until we set it manually for a level explicitly. Do you meant by your requirement that you need default margin property public to set once margin for all levels e.g setting margin to 20 instead of 0? We will appreciate it if you please share some more details regarding your margin requirements, so we will proceed accordingly.

Best Regards,

I mean that besides the missing dotted line and page number, the margin by default should be set to some value based on level, e.g. level * 20. Right now it’s zero for all. I can’t imaging generating a ToC without those margins and the code mentioned above is quite complicated:) It should be rather something like tocInfo.setLevelIndententation(20);


Thanks,
Mariusz

Hi Mariusz,


Thanks for providing additional information. We have logged an enhancement ticket as PDFNEWJAVA-34680 for your requirements in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress within this forum thread.

Best Regards,

Hi,


any update on PDFNEWJAVA-34197? Do you know when it’s going to be fixed? It prevents us from creating ToC.

Thanks,
Mariusz

Hi Mariusz,

Thanks for your inquiry. We have good news for you, you above reported both issues have been fixed in upcoming Aspose.Pdf for Java version, i.e. 10.0.0. Hopefully it will be published in couple of weeks. However we will notify you as soon as it is released and gets available for download.

Thanks for your patience and cooperation.

Best Regards,

That’s great, thank you!

The issues you have found earlier (filed as PDFNEWJAVA-34680;PDFNEWJAVA-34197) have been fixed in Aspose.Pdf for Java 10.0.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
(3)