Html to Word break pages

Hi

I need your help.

I can implement page break from html to pdf whit this...

        string PageBreakA => "<p style='page-break-after: always;'></p>";

        string PageBreakB => "<p style='page-break-before: always;'></p>";

but in Word not works, please help!



3 Replies

LB Lokesh Baskar Syncfusion Team January 24, 2022 06:11 PM UTC

Hi Jose,

To append page break in the word document we suggest you to refer to the below modified html string.
 
WordDocument document = new WordDocument(); 
document.EnsureMinimal(); 
WParagraph paragraph = document.Sections[0].Body.LastParagraph as WParagraph; 
paragraph.AppendHTML("<br style=\'page-break-after: always;\'></br><br style=\'page-break-before: always;\'></br>"); 
document.Save(@"sample_using breaktag.docx"); 
document.Close(); 
 
Kindly try this solution at your end and confirm us whether it satisfies your end requirement.

Regards,
 
Lokesh B 



JL jose luis barajas April 29, 2022 05:34 PM UTC

Hi

I need to place page breaks in the places where they were set in the html code, how can i implement it when converting it to word, since i don't know the paragraph and the place where the user has placed the page breaks

Please help me, 



SB Suriya Balamurugan Syncfusion Team May 2, 2022 01:46 PM UTC

Hi Jose,

From the given details, we have suspected that your requirement is to add page break where the HTML code inserted. To achieve this, we have suggested you to add a page break before or after the HTML code inserted into the paragraph. Please refer the below highlighted code snippets to achieve your requirement.

WordDocument document = new WordDocument();

document.EnsureMinimal();

WParagraph paragraph = document.Sections[0].Body.LastParagraph as WParagraph;

//Adds page break before the HTML code inserted into the paragraph.

paragraph.AppendBreak(BreakType.PageBreak);

paragraph.AppendHTML("<p>This text is inserted as HTML string.</p>");

//Adds page break after the HTML code inserted into the paragraph.

paragraph.AppendBreak(BreakType.PageBreak);

document.Save(@"sample.docx");

document.Close();


Please refer our UG documentation link to know about how to add page break to the paragraph,
https://help.syncfusion.com/file-formats/docio/working-with-paragraph#appending-breaks

If we misunderstood any of your requirements, then kindly provide us complete end requirement along with input template, and screenshot/output document of the expected result which will helpful to provide you the appropriate solution at the earliest.

Regards,
Suriya Balamurugan.


Loader.
Up arrow icon