This is a migrated thread and some comments may be shown as answers.

Page break in exporting HTML to DOCX - solution found

0 Answers 24 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Marcin
Top achievements
Rank 1
Marcin asked on 30 Nov 2016, 12:04 PM

Hi, everyone,

As far as I know, RadEditor doesn't have a page break functionality when HTML is exporting to DOCX. I've found a solution for this:

 

DocxFormatProvider provider = new DocxFormatProvider();
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();

List<string> result = this.PrepareStringToExport(htmlPage); //result is a list with divided "pages"
RadFlowDocument newDoc = new RadFlowDocument();
RadFlowDocumentEditor newEditor = new RadFlowDocumentEditor(newDoc);
RadFlowDocument document;
foreach(string element in result)
{
document = new RadFlowDocument();
document = htmlProvider.Import(element);
newEditor.InsertDocument(document);
newEditor.InsertBreak(BreakType.PageBreak);
}
byte[] byteArray = provider.Export(newEditor.Document);
string fileName = "filename.docx";
Utils.SendBytesAsFileToClientWithAjax(Response, fileName, byteArray);

 

If there is a cleaner solution, let me know

 

Best regards

Marcin

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Marcin
Top achievements
Rank 1
Share this question
or