ReplaceArgs.setReplacement("") is leaving blank line in document generation

@priyanka9 You should check whether the paragraph becomes empty after replacing placeholder and remove it in such case. Please try using the following code:

@Override
public int replacing(ReplacingArgs args) throws Exception {
    String arg = args.getMatch().group();
    arg= removeBrackets(arg);
    //assuming whatever the args are there in list are not satisfying condition and trying to remove them
    if(list.contains(arg)){
        Paragraph para = (Paragraph) args.getMatchNode().getParentNode();
        // Get paragraph text
        String paraText = para.toString(SaveFormat.TEXT).trim();
        paraText = paraText.replace(args.getMatch().group(), "");
        // Remove the paragraph with the matched text.
        if(paraText.equals("")) {
            para.remove();
            return ReplaceAction.SKIP;
        }
        else {
            args.setReplacement("");
            return ReplaceAction.REPLACE;
        }
    } else {
        args.setReplacement("ReplacemntValue is:"+arg);
        return ReplaceAction.REPLACE;
    }
}

Ok let me test with this.
Thank you.

1 Like

@alexey.noskov Yeah it worked thanks a lot.

1 Like