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.
Unfortunately, activation email could not send to your email. Please try again.

Insert paragraphs in a bookmark

Thread ID:

Created:

Updated:

Platform:

Replies:

104314 Jul 10,2012 05:11 AM Jan 19,2014 10:39 AM ASP.NET Web Forms (Classic) 7
loading
Tags: DocIO
Acorah
Asked On July 10, 2012 05:11 AM

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


Ramkumar M [Syncfusion]
Replied On July 12, 2012 05:48 AM

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

Acorah
Replied On July 12, 2012 09:15 AM

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 :)

Ramkumar M [Syncfusion]
Replied On July 13, 2012 12:47 AM

Hi Acorah,

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

Regards,

Ramkumar 


Julien Charles
Replied On January 16, 2014 05:54 AM

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

Sathish K [Syncfusion]
Replied On January 17, 2014 07:08 AM

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

Julien Charles
Replied On January 17, 2014 08:23 AM

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

Sathish K [Syncfusion]
Replied On January 19, 2014 10:39 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;