We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Insert paragraphs in a bookmark

Hello,

 

I'm using Syncfusion Essential v10.2.0.75 to generate word document and I have some trouble inserting paragraphs in bookmarks. I'm totally new to Syncfusion so maybe I misunderstood something...

 

I've created a dotx template which contains some text and bookmarks. The section where I want to insert paragraph is as follow :

[template hard coded text]

bookmark

[template hard coded text]

 

So the bookmark is on a new line, just between two lines of text (no other character on the line with the bookmark).

To create my document (based on my template) I use the following code :

Stream templateStream = templateFile.OpenBinaryStream();

WordDocument document = newWordDocument();

document.Open(templateStream, Syncfusion.DocIO.FormatType.Word2010Dotx);

 

And to insert my paragraphs :

BookmarksNavigator bk = newBookmarksNavigator(document);

bk.MoveToBookmark("[Bookmark name]");

List<string> skills = GetSkills();foreach(string str in skills)

{

IWParagraph paragraph = document.CreateParagraph();

       paragraph.ListFormat.ApplyDefBulletStyle();

       paragraph.ListFormat.ListLevelNumber = 0;

       IWTextRange textRange = paragraph.AppendText(str);

       bk.InsertParagraph(paragraph);

}

 

My problem is that a new line is added before the first paragraph and an other one after the last paragraph.

So instead of having (as i expected) :

[template hard coded text]

skill1

skill2

[template hard coded test]

 

I have the following result :

[template hard coded text]

 

skill1

skill2

 

[template hard coded text]

 

If I insert text using bk.InsertText() method there is no extra line break, but as far as i understand I need to insert paragraphs to display a bullet list.

Am I missing something ?

Thanks for your help


7 Replies

RM Ramkumar M Syncfusion Team July 12, 2012 09:48 AM UTC

Hi Acorah

Thank you for your interest in Syncfusion product s

As per behavior of DocIO object model, it is not possible to insert a paragraph into another paragraph, so in InsertParagraph function we have split BookmarkStart and BookmarkEnd into two paragraphs and then insert the new paragraph in between those two paragraphs. That is the reason for new line before and after the inserted paragraphs.

However we have created the sample to meet your requirement by handling in object level. Please do find the sample from the attachment. Try running the sample and let us know if this helps you.

Please let us know if you have any other questions.

Regards,
Ramkumar



Sample_133ab8.zip


AC Acorah July 12, 2012 01:15 PM UTC

Hi Ramkumar,
 
Thanks for your reply, I tested your code and it works like a charm. It even solved my second problem I had not seen when I posted my first message. My paragraphs were inserted in the wrong order, and appeared from last to first in my bulleted list. So I had something like the following as result :
    Item 2.2
    Item 2.1
Item 2
    Item 1.1
Item 1
 
But with your code evrything is good, thanks for saving my day :)


RM Ramkumar M Syncfusion Team July 13, 2012 04:47 AM UTC

Hi Acorah,

You're welcome. Please let us know if you have any other questions.

Regards,

Ramkumar 



JC Julien Charles January 16, 2014 10:54 AM UTC

Hi
I am really interested in your solution you provide because I have the same problem. But I can't download the zip file with the code (Access denied). Is it possible to have the access again or to view the sample code ?

Thanks for your help


SK Sathish K Syncfusion Team January 17, 2014 12:08 PM UTC

Hi Julien,

 

Thank you for your interest in Syncfusion products.

 

You can remove the empty paragraph which is preserved after the replaced content by finding out that paragraph manually (which contains the BookmarkStart and BookmarkEnd items).

 

Alternatively you can replace the bookmark by a text body item which contains the item to be replaced like paragraph, picture, etc., we have prepared a sample to illustrate both of the scenarios. Please find the attached sample and let us know if this helps you.

 

Please let us know if you need any further assistance.

 

Regards,

Sathish



Sample_1255828c.zip


JC Julien Charles January 17, 2014 01:23 PM UTC

 It works great and my problem is solved.
Thank you for your reactivity and your answer !


SK Sathish K Syncfusion Team January 19, 2014 03:39 PM UTC

Hi Julien,

 

Thank you for your update.

 

Please let us know if you need any further assistance. We will be happy to assist you as always.

 

Regards,

Sathish


Loader.
Live Chat Icon For mobile
Up arrow icon