What is the correct way of getting the line width of a simple textbox with apache poi 5.0.0 from a pptx-file? I create a small project with maven apache poi, poi-ooxml and poi-scratchpad.
When i create a pptx named test.pptx
with three textboxes with
- no border (has width 0.0)
- default border (has width 0.75)
- border with width 2.0
then the following code outputs
FileInputStream fis = new FileInputStream("test.pptx");
XMLSlideShow ppt = new XMLSlideShow(fis);
fis.close();
for (XSLFSlide slide : ppt.getSlides()) {
for (XSLFShape shape : slide.getShapes()) {
if (shape instanceof XSLFTextBox) {
XSLFTextBox textBox = (XSLFTextBox) shape;
String text = textBox.getText();
System.out.println(text);
double borderWidth = textBox.getLineWidth();
System.out.println("line: "+borderWidth+", "+textBox.getLineColor());
}
}
}
- no border:
line: 0.0, null
- default:
line: 0.0, java.awt.Color[r=91,g=155,b=213]
- border 2.0:
line: 2.0, java.awt.Color[r=91,g=155,b=213]
In the documentation is said that width 0.0
is no border. But how can i differentiate no border and default border, when both return 0.0
. This should not be null from color.
If a
PowerPoint
shape has line setting using default line width, then the width is not set. Only the line itself is set having color settings. In shape'sXML
this looks like:But a line also may have gradient color, then this looks like:
Then no explicit line color is set and
XSLFSimpleShape.getLineColor
will returnnull
.So to check whether a line color is set will not always get whether there is a line or not.
The correct way would be to check whether there is a line set in shape properties or not. But there is no such method in high level
apache poi
classes. So that only is possible using the underlying low levelorg.openxmlformats.schemas.presentationml.x2006.main.*
classes.Example for a method to check whether a shape has a line set: