Search in sources :

Example 1 with PackagePart

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();
}
Also used : PrintStream(java.io.PrintStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Dimension(java.awt.Dimension) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) FileInputStream(java.io.FileInputStream)

Example 2 with PackagePart

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();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 3 with PackagePart

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;
}
Also used : PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) DrawPictureShape(org.apache.poi.sl.draw.DrawPictureShape)

Example 4 with PackagePart

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");
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Example 5 with PackagePart

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);
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart)

Aggregations

PackagePart (org.apache.poi.openxml4j.opc.PackagePart)118 OutputStream (java.io.OutputStream)38 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)27 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)24 PackageRelationshipCollection (org.apache.poi.openxml4j.opc.PackageRelationshipCollection)23 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)19 QName (javax.xml.namespace.QName)18 IOException (java.io.IOException)17 XmlOptions (org.apache.xmlbeans.XmlOptions)17 InputStream (java.io.InputStream)11 Test (org.junit.Test)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 POIXMLException (org.apache.poi.POIXMLException)8 XmlException (org.apache.xmlbeans.XmlException)8 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)7 ArrayList (java.util.ArrayList)6 TikaException (org.apache.tika.exception.TikaException)6 URI (java.net.URI)5 SAXException (org.xml.sax.SAXException)5