Row bookmark is not getting

Hi,

in my document contains a table and inside table I will have bookmark for a column. And I am taking the bookmark is with row.getRange().getBookmarks(). But for one document, it has bokkmark inside the row but showing row bookmark count as 0. I am attaching the sample document test.docx (41.4 KB)
, can you please help me why I am not getting the row bookmarks.

Thank you

@Gptrnt Unfortunately, I cannot reproduce the problem on my side. I have used the following code for testing:

Document doc = new Document("C:\\Temp\\in.docx");

// Get the table
Table table = doc.getFirstSection().getBody().getTables().get(0);

// Print bookmarks per row
int rowIdx = 0;
for (Row row : table.getRows())
{
    System.out.println("Row " + rowIdx + " Contains " + row.getRange().getBookmarks().getCount() + " bookmarks:");
    for (Bookmark bk : row.getRange().getBookmarks())
        System.out.println("\t" + bk.getName());
    rowIdx++;
}

Output of the above code is the following:

Row 0 Contains 1 bookmarks:
	_agDetailTbl_bookmark#@@#@@##
Row 1 Contains 2 bookmarks:
	Agenda_Detail_Title1
	Page_number1
Row 2 Contains 2 bookmarks:
	Agenda_Detail_Title2
	Page_number2
Row 3 Contains 2 bookmarks:
	Agenda_Detail_Title3
	Page_number3
Row 4 Contains 2 bookmarks:
	Agenda_Detail_Title4
	Page_number4
Row 5 Contains 2 bookmarks:
	Agenda_Detail_Title5
	Page_number5
Row 6 Contains 2 bookmarks:
	Agenda_Detail_Title6
	Page_number6

I have used the latest 23.1 version of Aspose.Words for Java.

Hi,

I am creating word and pdf by altering and uploaded document. In the document I have creating Page with title in Heading_2 style. When I created pdf file with heading as bookmark, heading bookmark is coming but it pointing in a wrong page. Attaching the input filemt_test.docx (12.8 KB) and code

boolean flag = false;
builder.moveToDocumentEnd();
builder.writeln();
for (int i = 0; i < agendaDetail.getAgendaResource().size(); i++)
{
    Resource resource = agendaDetail.getAgendaResource().get(i);
    //Add the title on new page break as well as bookmark the same
    int actualParagraphAlignment = builder.getParagraphFormat().getAlignment();
    String attachmentTitle;
    attachmentTitle = ATTACHMENT + resource.getName().replaceAll(PDF_EXTENSION, EMPTY_STRING);
    //To make the unique bookmark name - have used UUID's random() method because in some cases bookmark name could
    //be same (if UUID's random method is not used)
    String bookmarkName = resource.getPath() + RUNTIME_BOOKMARKNAME_SEPERATOR + UUID.randomUUID().toString();
    builder.insertBreak(BreakType.PAGE_BREAK);
    if (flag)
    {
        flag = false;
        builder.startBookmark(emptyItemTitle);
        builder.endBookmark(emptyItemTitle);
    }
    builder.getFont().setName((String)tokenFontMap.get(NAME));
    builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
    builder.getParagraphFormat().getStyle().getFont().setUnderline(Underline.NONE);
    builder.getParagraphFormat().setLineSpacing(setCurrentLineSpace((double)(tokenFontMap.get(SIZE)) * 3, builder.getParagraphFormat()));
    String sepVariation = true;
    builder.getParagraphFormat().getStyle().getFont().setColor((Color)tokenFontMap.get(COLOR));
    builder.getFont().setSize(((double)tokenFontMap.get(SIZE)) * 3);
    builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
    // builder.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
    builder.writeln(attachmentTitle);
    // builder.writeln(" ");
    builder.startBookmark(bookmarkName);
    builder.endBookmark(bookmarkName);
    logger.error("Font size inside prototype build up :" + builder.getFont().getSize());

    // clear the formatting info
    // builder.getParagraphFormat().clearFormatting();
    // Get the file's page count from agenda Resource
    for (int pgCount = 0; pgCount < resource.getFilePageCount(); pgCount++)
    {
        builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.NORMAL);
        // removing blank page fo r skip empty case
        if (variationMap.containsKey(SEPARATOR_KEY) || (!isSkipEmpty || pgCount > 0))
        {
            builder.insertBreak(BreakType.PAGE_BREAK);
        }
        builder.write(" ");
        if (true && false && i == agendaDetail.getAgendaResource().size() - 1 && pgCount == resource.getFilePageCount() - 1)
        {
            builder.getParagraphFormat().setAlignment(ParagraphAlignment.JUSTIFY);
            builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);
            Section currentSection = builder.getCurrentSection();
            PageSetup pageSetup = currentSection.getPageSetup();
            pageSetup.setVerticalAlignment(pageVerticalAlignment);

            // Disable inheriting the first page header/footer from previous section.
            pageSetup.setDifferentFirstPageHeaderFooter(false);
            // Reset page borders.
            if (pageSetup.getBorderAppliesTo() == PageBorderAppliesTo.FIRST_PAGE)
                pageSetup.getBorders().clearFormatting();
            if (pageSetup.getBorderAppliesTo() == PageBorderAppliesTo.OTHER_PAGES)
                pageSetup.setBorderAppliesTo(PageBorderAppliesTo.ALL_PAGES);
        }

        if (flag && false)
        {
            flag = false;
            builder.startBookmark(emptyItemTitle);
            builder.endBookmark(emptyItemTitle);
        }
    }

Please help me

Thank you

@Gptrnt Unfortunately, I cannot reproduce the problem on my side. i have simplified your code like the following for testing:

Document doc = new Document("C:\\Temp\\mt_test.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

boolean flag = false;
builder.moveToDocumentEnd();
builder.writeln();

String attachmentTitle;
attachmentTitle = "Some Attachment Title";
String bookmarkName = "test_bookmark";
builder.insertBreak(BreakType.PAGE_BREAK);
builder.getFont().setName("Arial");
builder.getParagraphFormat().setStyleIdentifier(StyleIdentifier.HEADING_2);
builder.getParagraphFormat().getStyle().getFont().setUnderline(Underline.NONE);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);
builder.writeln(attachmentTitle);
builder.startBookmark(bookmarkName);
builder.endBookmark(bookmarkName);

doc.save("C:\\Temp\\out.docx");

PdfSaveOptions opt = new PdfSaveOptions();
opt.getOutlineOptions().setHeadingsOutlineLevels(3);
opt.getOutlineOptions().setDefaultBookmarksOutlineLevel(1);
doc.save("C:\\Temp\\out.pdf", opt);

As I can see both test_bookmark and Some Attachment Title points to the correct page in the output PDF document: out.pdf (51.4 KB)