Set BackgroundPatternColor to transparent color

I have a docx document with paragraphs which have a background color as ‘gray’ (docx attached). I would like to remove background color for paragraphs at all.
I’ve tried this code:

for (Paragraph p: doc.getFirstSection().getBody().getParagraphs()) { 
    p.getParagraphFormat().getShading().setBackgroundPatternColor(Color.WHITE);
}

But the background color sets to white, not transparent.

Hi there,

Thanks for your inquiry. Please use clearFormatting() to remove background color. Hopefully it will help you to accomplish the task.

for (Paragraph p : doc.getFirstSection().getBody().getParagraphs()) {
    p.getParagraphFormat().clearFormatting();
    // p.getParagraphFormat().getShading().setBackgroundPatternColor(Color.WHITE);
}

Best Regards,

Thank you for your reply, but clearFormatting() method removes alignment property (see updated docx in attachment). I need to remove background color only, but don’t touch another properties.

Hi there,

Thanks for sharing additional information. Please try clearFormatting() property of Shading, it will help you to accomplish the task.

p.getParagraphFormat().getShading().clearFormatting();

Best Regards,

A post was split to a new topic: Setting BackgroundPatternColor to transparent color