Inserting html into document not taking builder font

Hi,

I am trying to insert html text (which is itself has some font) into document. My use-case is to use/apply the font of the document (builder) to the inserted content through builder.insertHtml.

When i use the insertHtml api , it is not taking the builder font.

Please help.

@saurabh.arora,

Thanks for your inquiry. Please use DocumentBuilder.InsertHtml method (String html, Boolean useBuilderFormatting) to insert an HTML string into the document. Please use the value of useBuilderFormatting parameter as true to get the desired output.

If you still face problem, please ZIP and attach your input Word document and HTML here for testing. We will investigate the issue and provide you more information on this.

Hi Tahir,

Can you suggest me how to use split word document into single page documents. Like if i have a 10 page document , i want to split them into 10 single page documents.

I used the following code -

LayoutCollector layoutCollector = new LayoutCollector(document);

DocumentPageSplitter splitter = new DocumentPageSplitter(layoutCollector);

int pageIndex = 0;

    for (int i = 0; i < document.getPageCount(); i++) {
        pageIndex = i + 1;
        Document newDoc = splitter.getDocumentOfPage(pageIndex);
        newDoc.getRange().replace(AdminTemplateConstants.TAG_IDENTIFIER_PATTERN, new 
        newDoc.save(folder + "/" + pageIndex + AdminTemplateConstants.DOC_EXTENSION);
    }
} 

But it is giving a problem in output. For some pages , instead of one page it is splitting into 2.

@saurabh.arora

Thanks for your inquiry. Please use the following modified code snippet to get the correct output. If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

for (int i = 1; i <= pageCount; i++) {
	Document newDoc = splitter.getDocumentOfPage(pageIndex);
        newDoc.getRange().replace(AdminTemplateConstants.TAG_IDENTIFIER_PATTERN, new 
        newDoc.save(folder + "/" + pageIndex + AdminTemplateConstants.DOC_EXTENSION);
}

Thanks for the reply. I tried with your code , but the problem still persist.

Test_Clause123.docx.zip (6.7 KB)

Please help.

@saurabh.arora

Thanks for sharing the detail. You are facing this issue due to line break at the start of document. Please use following code example to get the correct output. Hope this helps you.

Document doc = new Document(MyDir + "Test_Clause123.docx");
LayoutCollector collector = new LayoutCollector(doc);
DocumentPageSplitter splitter = new DocumentPageSplitter(collector);

for (int i = 1; i <= doc.getPageCount(); i++) {
    Document newDoc = splitter.GetDocumentOfPage(i);

    if(newDoc.getFirstSection().getBody().getFirstChild().getNodeType() == NodeType.PARAGRAPH
            && newDoc.getFirstSection().getBody().getFirstParagraph().getRuns().getCount() > 0)
        newDoc.getFirstSection().getBody().getFirstParagraph().getRuns().get(0).getRange().replace(ControlChar.LINE_BREAK, "", new FindReplaceOptions());
    newDoc.save(MyDir + "output"+i+".docx");
}

HI Tahir,

I still get the same output. 3 new documents are created instead of 2. Attaching the created documents.

Download.zip (18.6 KB)

Is there any problem with the DocumentPageSplitter cod. Please help , as i am stuck at this.

I have created the document by inserting html content through builder.insertHtml() api.

Please help.

Thanks

@saurabh.arora,

Thanks for your inquiry. Your input document has three pages. Please see the attached image for detail. input.png (37.3 KB)

Please share the simplified code example that you are using to create the Word document. We will then provide you more information about your query.