use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class DataExtraction method main.
public static void main(String[] args) throws IOException, OpenXML4JException {
PrintStream out = System.out;
if (args.length == 0) {
out.println("Input file is required");
return;
}
FileInputStream is = new FileInputStream(args[0]);
XMLSlideShow ppt = new XMLSlideShow(is);
is.close();
// Get the document's embedded files.
for (PackagePart p : ppt.getAllEmbedds()) {
String type = p.getContentType();
// typically file name
String name = p.getPartName().getName();
out.println("Embedded file (" + type + "): " + name);
InputStream pIs = p.getInputStream();
// make sense of the part data
pIs.close();
}
// Get the document's embedded files.
for (XSLFPictureData data : ppt.getPictureData()) {
String type = data.getContentType();
String name = data.getFileName();
out.println("Picture (" + type + "): " + name);
InputStream pIs = data.getInputStream();
// make sense of the image data
pIs.close();
}
// size of the canvas in points
Dimension pageSize = ppt.getPageSize();
out.println("Pagesize: " + pageSize);
for (XSLFSlide slide : ppt.getSlides()) {
for (XSLFShape shape : slide) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape) shape;
out.println(txShape.getText());
} else if (shape instanceof XSLFPictureShape) {
XSLFPictureShape pShape = (XSLFPictureShape) shape;
XSLFPictureData pData = pShape.getPictureData();
out.println(pData.getFileName());
} else {
out.println("Process me: " + shape.getClass());
}
}
}
ppt.close();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFChart method commit.
@Override
protected void commit() throws IOException {
XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
xmlOptions.setSaveSyntheticDocumentElement(new QName(CTChartSpace.type.getName().getNamespaceURI(), "chartSpace", "c"));
PackagePart part = getPackagePart();
OutputStream out = part.getOutputStream();
chartSpace.save(out, xmlOptions);
out.close();
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFGroupShape method createPicture.
@Override
public XSLFPictureShape createPicture(PictureData pictureData) {
if (!(pictureData instanceof XSLFPictureData)) {
throw new IllegalArgumentException("pictureData needs to be of type XSLFPictureData");
}
XSLFPictureData xPictureData = (XSLFPictureData) pictureData;
PackagePart pic = xPictureData.getPackagePart();
PackageRelationship rel = getSheet().getPackagePart().addRelationship(pic.getPartName(), TargetMode.INTERNAL, XSLFRelation.IMAGES.getRelation());
XSLFPictureShape sh = getDrawing().createPicture(rel.getId());
new DrawPictureShape(sh).resize();
_shapes.add(sh);
sh.setParent(this);
return sh;
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFHyperlink method linkToSlide.
@Override
public void linkToSlide(Slide<XSLFShape, XSLFTextParagraph> slide) {
PackagePart thisPP = _sheet.getPackagePart();
PackagePartName otherPPN = ((XSLFSheet) slide).getPackagePart().getPartName();
if (_link.isSetId() && !_link.getId().isEmpty()) {
thisPP.removeRelationship(_link.getId());
}
PackageRelationship rel = thisPP.addRelationship(otherPPN, TargetMode.INTERNAL, XSLFRelation.SLIDE.getRelation());
_link.setId(rel.getId());
_link.setAction("ppaction://hlinksldjump");
}
use of org.apache.poi.openxml4j.opc.PackagePart in project poi by apache.
the class XSLFHyperlink method linkToRelativeSlide.
private void linkToRelativeSlide(String jump) {
PackagePart thisPP = _sheet.getPackagePart();
if (_link.isSetId() && !_link.getId().isEmpty()) {
thisPP.removeRelationship(_link.getId());
}
_link.setId("");
_link.setAction("ppaction://hlinkshowjump?jump=" + jump);
}
Aggregations