Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Aug 29, 2014 2:33 pm

Hello,
When we open a document with loadfromstream. How can i access programaticaly to the text being loaded ?
The idea is that the text contains words like "Break" and i want to insert break page when i found this word. How can i achieve this please ?

thank you.

tarikzaid
 
Posts: 29
Joined: Wed Aug 06, 2014 7:16 am

Mon Sep 01, 2014 3:20 am

Dear tarikzaid,

Thanks for your inquiry.

For your requirement, please refer to the following code:
Code: Select all
Document doc = new Document("Starbound.doc", FileFormat.Doc);
//Find word "Break"
TextSelection[] selections = doc.FindAllString("Break", true, true);
//Insert break page
foreach (TextSelection ts in selections)
{
    TextRange range = ts.GetAsOneRange();
    Paragraph paragraph = range.OwnerParagraph;
    int index = paragraph.ChildObjects.IndexOf(range);
    Break stun = new Break(doc, BreakType.PageBreak);
    paragraph.ChildObjects.Insert(++index, stun);
}
doc.SaveToFile("Break.doc", FileFormat.Doc);
Process.Start("Break.doc");

Please feel free to contact us if you have any problems.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Sep 01, 2014 7:39 am

Thank you for your solution.

This works fine in case of doc files., but i try it on html files and it does not work. maybe because the pagebreak does not work with html ?
The code is the same, only the document is an html file instead of doc or docx.

Thank you

tarikzaid
 
Posts: 29
Joined: Wed Aug 06, 2014 7:16 am

Mon Sep 01, 2014 9:20 am

Dear tarikzaid,

Thanks for your inquiry.

I'm sorry that I don't understand your question:Did this happen when you convert a html file to a doc/docx file, or load a doc/docx file and convert it to a html file?

If it is the former, please send us your html file to help us resolve your problem.
If it is the latter, that is a cross-browser compatibility problem. I have tried IE8(or older) and Firefox to test and it worded well, but not working in Chrome.

Please feel free to contact us if you have any problems.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Mon Sep 01, 2014 10:19 am

I try to load html file , do the page breaks and and save it after to docx.

Here is the code :
Document document = new Document();
document.LoadFromFile(filename, FileFormat.Html, XHTMLValidationType.None);
//add page break
TextSelection[] selections = document.FindAllString("SAUTDEPAGE", false, true);
if (selections != null)
{
foreach (TextSelection ts in selections)
{
TextRange range = ts.GetAsOneRange();
Paragraph paragraph = range.OwnerParagraph;
int index = paragraph.ChildObjects.IndexOf(range);
Break stun = new Break(document, BreakType.PageBreak);
paragraph.ChildObjects.Insert(++index, stun);
}
document.Replace("SAUTDEPAGE", string.Empty, true, true);
}

//save file
SaveDocument(destfilename, document, FileFormat.Docx);

When the file saved, i open it and i have not the pagebreak instead of SAUTDEPAGE bookmark.

The html file is attached.

Thank you.

tarikzaid
 
Posts: 29
Joined: Wed Aug 06, 2014 7:16 am

Tue Sep 02, 2014 6:12 am

Dear tarikzaid,

Thanks for your inquiry.

I found out the key word "SAUTDEPAGE" was inside a table and that makes page break invalid in the table.
Therefore, I recommend you to use other tags like <p> to contain the text which would be available.

Please feel free to contact us if you have any problems.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Sep 05, 2014 9:36 am

Dear tarikzaid,

Have your problem been resolved?
If not, please send us more information about your problem.

Best regards,
Burning
E-iceblue Support Team
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Fri Sep 05, 2014 1:15 pm

Hello,

Yes it has been solved.

Thanks.

tarikzaid
 
Posts: 29
Joined: Wed Aug 06, 2014 7:16 am

Mon Sep 08, 2014 7:33 am

Hello,

Thanks for your response. Glad to hear that.
If there are any questions, welcome to get it back to us.
Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc