Can not import picture bullets

Hi,
I used example of insert any document at any location. When I insert some portion of reference document which contains picture bullets, it does not copy picture bullets. Instead it marks bullets as plain character bullets.
Also I observed Aspose sets pictures (use in bullets) at the end of document.
e.g
Ref Doc:
Some text
[!StartHere!]
Some Picture Bullets
[!EndHere!]
Some Text
When I copy from starthere to endhere from another document, it does copy bullets but not pictures of those.
Please check.

Hi

Thanks for your request. Please, attach your document. I will investigate this problem and try to help you.

Best regards.

Reference Document is attached.

Hi
Thanks for additional information. I have tried to insert your document into another and it seems that all works fine on my side. I have used the following code.

Document doc = new Document(@"239_97121_isrc\in1.doc");
Document doc1 = new Document(@"239_97121_isrc\IsFeasibleTemplateRef.doc");
InsertDocument(doc.LastSection.Body.LastParagraph, doc1);
doc.Save(@"239_97121_isrc\out.doc");

The InsertDocument method you can find here
https://docs.aspose.com/words/net/insert-and-append-documents/
Best regards.

Here you have inserted whole document. I want to insert all paragraphs starting with [!INSERTTHIS!] upto [!/INSERTTHIS!].
When you loop through for each paragraph node and import in main document, pictures are not imported. This is because pictures are included in last paragraph (if you open ref. document with Aspose Document Explorer, you can see).
Hope you understood my concern.
My code is :

Private Sub InsertOther(ByRef doc As Aspose.Words.Document, ByRef nd As Node)
Dim docRef As Document = New Document("c:\IsFeasibleTemplateRef.doc")
Dim paraNodes As NodeList = docRef.SelectNodes("//Body/Paragraph | //Body/Table")
Dim nd1 As node
Dim arrList As New ArrayList
Dim bStart As Boolean = False
For Each nd1 In paraNodes
If (nd1.ToTxt().IndexOf("[!INSERTTHIS!]") > -1) Then
bStart = True
ElseIf (nd1.ToTxt().IndexOf("[!/INSERTTHIS!]") > -1) Then
Exit For
End If
If (bStart = True And nd1.ToTxt().IndexOf("[!INSERTTHIS!]") = -1) Then
arrList.Add(nd1.Clone(True))
End If
Next
Dim importer As NodeImporter = New NodeImporter(docRef, doc, ImportFormatMode.KeepSourceFormatting)
Dim i As Integer
Dim node As CompositeNode = nd.ParentNode 'Body
While (i < arrList.Count)
Try
nd1 = CType(arrList(i), Paragraph)
Catch ex As Exception
nd1 = CType(arrList(i), Table)
End Try
Dim newNode As node = importer.ImportNode(nd1, True)
node.InsertAfter(newNode, nd)
nd = newNode
i += 1
End While
End Sub

Hi
Thanks for additional information. You should copy content from the last paragraph of sourse document into the last paragraph of destination document. See the following code snippet.

foreach (Node child in docRef.LastSection.Body.LastParagraph.ChildNodes)
{
    doc.LastSection.Body.LastParagraph.AppendChild(importer.ImportNode(child, true));
}

Best regards.

OK. So this means for Picture Bullets there is always Last paragraph created. And If I want to copy these picture bullets from one document to another, then I need to copy this last paragraph.
However runtime how can I identify whether last paragraph is created for picture bullets or not. Supppose in one reference document. if no picture bullets are added, then by copying this last paragraph would produce undesired results.
Please explain.

Hi
Try to use the following code.

// if the destination document does not contain PictureBullets then copy it from sourse document
if (doc.Range.Bookmarks["_PictureBullets"] == null)
{
    NodeCollection bookmarks = docRef.GetChildNodes(NodeType.BookmarkStart, true);
    foreach (BookmarkStart start in bookmarks)
    {
        if (start.Name == "_PictureBullets")
        {
            Node bookmarkNode = start;
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.MoveToDocumentEnd();
            while (bookmarkNode.NodeType != NodeType.BookmarkEnd)
            {
                builder.InsertNode(importer.ImportNode(bookmarkNode, true));
                bookmarkNode = bookmarkNode.NextSibling;
            }
            builder.InsertNode(importer.ImportNode(bookmarkNode, true));
        }
    }
}
//else copy only pictures.
else
{
    NodeCollection bookmarks = doc.GetChildNodes(NodeType.BookmarkStart, true);
    foreach (BookmarkStart start in bookmarks)
    {
        if (start.Name == "_PictureBullets")
        {
            Node bookmarkNode = start.NextSibling;
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.MoveToBookmark("_PictureBullets", true, true);
            while (bookmarkNode.NodeType != NodeType.BookmarkEnd)
            {
                if (bookmarkNode.NodeType == NodeType.Shape)
                {
                    builder.InsertNode(importer.ImportNode(bookmarkNode, true));
                    bookmarkNode = bookmarkNode.NextSibling;
                }
            }
        }
    }
}

I hope that it will help you.
Best regards.

Thanks, it worked !
However one more query : If anyhow I need to insert the document again with bullets, same shapes will be copied two times un-necessarily. Is there any way to avoid this? Problem is that document size will grow un-necessarily.

Hi
You can get the array of hashcodes of Images in document. And then check if this array does not contain the hash code of inserting image then insert this image into the destination document. See the following code.

NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
// get HashCodes array
ArrayList list = new ArrayList();
foreach (Shape shape in shapes)
{
    list.Add(shape.ImageData.ImageBytes.GetHashCode());
}
………………………………
if (!list.Contains((bookmarkNode as Shape).ImageData.ImageBytes.GetHashCode()))
{
    builder.InsertNode(importer.ImportNode(bookmarkNode, true));
    bookmarkNode = bookmarkNode.NextSibling;
}

I hope that it will help you.
Best regards.