Find and replace the text and change DOCX and PDF into two column using Java

Hi Team,

As per the requirement , I have input “tokenized document” that will be processed and give me the “expected output document”. Input document contains tokens (written in between pipe “|”) that will be processed by my sample code and all tokens will get replaced with actual content in two columns page setup as in “expected output document”. Can you please help me !!

PFA sample code and docs.

Please do let me know if you need any further info.

Thank you…

SampleCode_1.zip (2.1 KB)
Expected_output_document.zip (12.4 KB)
input_tokenize_document.zip (11.2 KB)

@Pintutrnt

You have implemented the IReplacingCallback interface in your code. You need to insert the column break after replacing the “|allDetailsBold_item1|” in FindAndInsertHtml method. You may also create your template document with two columns and replace the content. We suggest you please read the following article.
Use DocumentBuilder to Insert Document Elements

Hope this helps you.

Hi Tahir,

I tried implementing the logic that you mentioned in sample code. but its giving the expected output document. Can you please help?

Thank you…

SampleCode_1 (2).zip (2.2 KB)

@Pintutrnt

We suggest you please read the members of TextColumn and TextColumnCollection classes. Please set the number of columns as shown below using TextColumnCollection.SetCount method. Hope this helps you.

switch (tokenName) {
    case "allDetailsBold_item1":
        TextColumnCollection columns = builder.getPageSetup().getTextColumns() ;
        columns.setCount(2);
        builder.getFont().setBold(true);
        builder.writeln("Item 1 : This is Item1 content and it should always come in column 1 if this content is not reached to end of this page. Else it will come in 2nd column.");

        builder.insertBreak(BreakType.COLUMN_BREAK);
        break;