We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Incomplete extraction of a bookmark

Hi,
The bookmark contained in the attached file is not completely extracted using the method ExtractContent content in your example.

Regards,
Christophe Mari

Hi,
The bookmark contained in the attached file is not completely extracted using the method ExtractContent content in your example.

Regards,
Christophe Mari

Hi Christophe,

Thanks
for your inquiry. Please use the following code example to achieve you requirements. Hope this helps you. Please let us
know if you have any more queries.

Document doc = new Document(MyDir + "10+lignes.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Bookmark bookmark = doc.Range.Bookmarks["table"];
BookmarkStart bookmarkStart = bookmark.BookmarkStart;
BookmarkEnd bookmarkEnd = bookmark.BookmarkEnd;
Node currentNode = bookmarkStart;
// Insert bookmark before table node
Cell cell = (Cell)bookmarkStart.GetAncestor(NodeType.Cell);
if (cell != null && cell.IsFirstCell)
{
    currentNode = cell.ParentRow.ParentTable.PreviousPreOrder(doc);
    // Check if table is the first Node of body
    if (currentNode.NodeType == NodeType.Body)
    {
        doc.FirstSection.Body.InsertBefore(new Paragraph(doc), doc.FirstSection.Body.FirstChild);
        builder.MoveToDocumentStart();
    }
    else
        builder.MoveTo(currentNode);
    bookmarkStart = builder.StartBookmark("bookmark");
    builder.EndBookmark("bookmark");
}
// Extract contents between bookmarkstart of 'bookmark' and bookmark end of 'table'
ArrayList extractedNodesInclusive = ExtractContent(bookmarkStart, bookmarkEnd, false);
Document docFinal = GenerateDocument(doc, extractedNodesInclusive);
// Remvoe the first empty paragraph of document
if (docFinal.FirstSection.Body.FirstParagraph.ToString(SaveFormat.Text).Trim() == String.Empty)
    docFinal.FirstSection.Body.FirstParagraph.Remove();
docFinal.Save(MyDir + "Out.docx");