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

Free Support Forum - aspose.com

Richtext bookmark is lost

I have a rich text:

  • [line1
  • line2
  • line3
line4
line5]

When I use the insertDocument in aspose it shows like this:
[//one extra empty line is added by default
  • line1
  • line2
  • line3
line4
line5]

and I have a bookmark between “[” “]” I need that bookmark, once I use builder.currentparagraph.remove() to delete the empty line the bookmark will be gone.
How can I maintain the bookmark?

Hi Rabih,

Thanks for your inquiry. Please note that DocumentBuilder.InsertDocument method mimics the MS Word behavior, as if CTRL+‘A’ (select all content) was pressed, then CTRL+‘C’ (copy selected into the buffer) inside one document and then CTRL+‘V’ (insert content from the buffer) inside another document.

It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word documents.
  • Please

    create a standalone/runnable simple application (for example a Console
    Application Project
    ) that demonstrates the code (Aspose.Words code) you used to generate
    your output document

  • Please attach the output Word file that shows the undesired behavior.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated
    like.

Unfortunately,
it is difficult to say what the problem is without the Document(s) and
simplified application. We need your Document(s) and simple project to
reproduce the problem. As soon as you get these pieces of information to
us we’ll start our investigation into your issue.
Thank you

I attach the project,
you can see the documents folder that contain the input, the template, the output of the project and the desiredoutput
please check the code and let me know what to do to remove the starting extra line and maintain the bookmark 'bookmark1'
I have aspose version 14.6.0.0

Rabih Zaylaa

Thanks

Hi Rabih,

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


Module Module1<o:p></o:p>

Public docReport As Document

Public InputDoc As Document

Public Builder As DocumentBuilder

Public BuilderInputDoc As DocumentBuilder

Sub Main()

Dim lic = New License()

lic.SetLicense("Aspose.Total.lic")

Dim path = IO.Path.Combine(IO.Path.GetDirectoryName(Application.ExecutablePath), "..\..\documents")

docReport = New Document(path & "\template1.docx")

InputDoc = New Document(path & "\input.docx")

Builder = New DocumentBuilder(docReport)

BuilderInputDoc = New DocumentBuilder(InputDoc)

BuilderInputDoc.MoveToDocumentEnd()

BuilderInputDoc.StartBookmark("bm_end")

BuilderInputDoc.EndBookmark("bm_end")

Dim bmk = docReport.Range.Bookmarks("bookmark1")

Builder.MoveTo(bmk.BookmarkStart)

Builder.InsertDocument(InputDoc, ImportFormatMode.KeepSourceFormatting)

Builder.MoveToBookmark("bm_end")

If Not Builder.CurrentParagraph.NextSibling Is Nothing And Builder.CurrentParagraph.NextSibling.ToString(SaveFormat.Text).Trim() = "" Then

Builder.CurrentParagraph.NextSibling.Remove()

End If

docReport.Save(path & "\output.docx")

End Sub

End Module

it works, thank you.


I don’t have the method InsertDocument of documentbuilder in my version, I used the sub insertdocument. can I know please for which version is added.

Hi Rabih,

Thanks for your inquiry. The DocumentBuilder.InsertDocument method was introduced in Aspose.Words v15.3.0. Please check the public API changes from following link.

Public API Changes in Aspose.Words 15.3.0

We suggest you please upgrade to the latest version of Aspose.Words for .NET 15.10.0 and let us know if you have any more queries.

Thank you. I will try to update to the latest version. I also found that adding new editable ranges is now supported with that version which is good.

I have a question. does aspose have an editor I mean word processing editor. so we can open the document using aspose and edit the editable range.

Hi Rabih,

Thanks for your inquiry. Aspose.Words for .NET is a class library that enables your applications to perform a great range of document processing tasks. So, it does not offer any UI or web control for performing these document processing tasks on web page.

Our sister company GroupDocs.com offers a viewer app which you may consider including in your application to view the various file formats. With GroupDocs apps, you can also have limited editing functionalities. For more information, we suggest you please contact GroupDocs support through live chat or support forums of GroupDocs.

Please let us know if you have any more queries.

Thank you tahir for you assistance.

I looked into GroupdDocs, I will try this product and check if it suits our needs.

regards.