Skip to content

Commit

Permalink
Copy alignment of placeholder when inserting image (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonOellerer authored Jan 8, 2025
1 parent b593fad commit 2746511
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group 'com.docutools'
version = '8.0.0'
version = '8.1.0'

java {
toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.poi.xwpf.usermodel.IBody;
import org.apache.poi.xwpf.usermodel.IBodyElement;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

public class ImagePlaceholderData extends CustomWordPlaceholderData {
private static final Logger logger = LogManager.getLogger();
Expand Down Expand Up @@ -70,6 +71,9 @@ protected void transform(IBodyElement placeholder, IBody part, Locale locale, Ge
Path path = applyOptions(options);
try {
var paragraph = part.insertNewParagraph(WordUtilities.openCursor(placeholder).orElseThrow());
if (placeholder instanceof XWPFParagraph placeholderParagraph) {
paragraph.setAlignment(placeholderParagraph.getAlignment());
}
WordImageUtils.insertImage(paragraph, path, options.imageStrategy());
WordUtilities.removeIfExists(placeholder);
} catch (IllegalArgumentException e) {
Expand Down

0 comments on commit 2746511

Please sign in to comment.