List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow XMLSlideShow
public XMLSlideShow(InputStream is) throws IOException
From source file:openslide.module.webserver.PPTX2SVG.java
License:Apache License
/** * parse file to svg document/*from w w w . j a v a 2 s .c o m*/ * @param file_name -required- {string} fullpath file * @return slide_list * @throws Exception */ public static ArrayList<String> parse(String file_name) throws Exception { String file = file_name; ArrayList<String> slide_list = new ArrayList<String>(); System.out.println("Processing " + file); // read the .pptx file XMLSlideShow ppt = new XMLSlideShow(OPCPackage.open(file)); Dimension pgsize = ppt.getPageSize(); // convert each slide into a .svg file XSLFSlide[] slide = ppt.getSlides(); for (int i = 0; i < slide.length; i++) { // Create initial SVG DOM DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation(); Document doc = domImpl.createDocument("http://www.w3.org/2000/svg", "svg", null); //Use Batik SVG Graphics2D driver SVGGraphics2D graphics = new SVGGraphics2D(doc); graphics.setRenderingHint(XSLFRenderingHint.IMAGE_RENDERER, new WMFImageRender()); graphics.setSVGCanvasSize(pgsize); String title = slide[i].getTitle(); System.out.println("Rendering slide " + (i + 1) + (title == null ? "" : ": " + title)); // draw stuff. All the heavy-lifting happens here slide[i].draw(graphics); // save the result. int sep = file.lastIndexOf("."); String fname = file.substring(0, sep == -1 ? file.length() : sep) + "-" + (i + 1) + ".svg"; slide_list.add(fname); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(fname), "UTF-8"); DOMSource domSource = new DOMSource(graphics.getRoot()); StreamResult streamResult = new StreamResult(out); TransformerFactory tf = TransformerFactory.newInstance(); Transformer serializer = tf.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.transform(domSource, streamResult); out.flush(); out.close(); } System.out.println("Done"); return slide_list; }
From source file:org.joeffice.presentation.SlidesTopComponent.java
License:Apache License
@Override public Object loadDocument(File pptxFile) throws Exception { try (FileInputStream fis = new FileInputStream(pptxFile)) { XMLSlideShow presentation = new XMLSlideShow(fis); return presentation; } catch (IOException ex) { throw ex; }/* www . j av a 2 s . c o m*/ }
From source file:org.joeffice.tools.PptxShapeNotDrawn.java
License:Apache License
public static void main(String[] args) throws IOException { if (args.length == 0) { System.err.println("Please profile a file path to open"); System.exit(-1);/*from w w w . j a v a 2 s . c o m*/ } JPanel mainPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); XMLSlideShow presentation = new XMLSlideShow(new FileInputStream(args[0])); XSLFSlide[] slides = presentation.getSlides(); for (XSLFSlide slide : slides) { XSLFShape[] shapes = slide.getShapes(); for (XSLFShape shape : shapes) { BufferedImage img = new BufferedImage((int) shape.getAnchor().getWidth(), (int) shape.getAnchor().getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = img.createGraphics(); graphics.translate(-shape.getAnchor().getX(), -shape.getAnchor().getY()); shape.draw(graphics); graphics.dispose(); JLabel shapeLabel = new JLabel(new ImageIcon(img)); shapeLabel.setBorder(BorderFactory.createLineBorder(Color.RED)); mainPanel.add(shapeLabel); } } showDemo(new JScrollPane(mainPanel), "Shape not displayed"); }
From source file:org.olat.search.service.document.file.PowerPointOOXMLDocument.java
License:Apache License
@Override public String readContent(final VFSLeaf leaf) throws IOException, DocumentException { BufferedInputStream bis = null; final StringBuilder buffy = new StringBuilder(); try {//from w w w . j a v a 2 s . co m bis = new BufferedInputStream(leaf.getInputStream()); final POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis); final POIXMLDocument document = extractor.getDocument(); if (document instanceof XSLFSlideShow) { final XSLFSlideShow slideShow = (XSLFSlideShow) document; final XMLSlideShow xmlSlideShow = new XMLSlideShow(slideShow); extractContent(buffy, xmlSlideShow); } return buffy.toString(); } catch (final Exception e) { throw new DocumentException(e.getMessage()); } finally { if (bis != null) { bis.close(); } } }
From source file:org.quelea.data.powerpoint.PPTXPresentation.java
License:Open Source License
/** * Create a new XML presentation./*from w w w.j ava 2 s . c om*/ * * @param file the file containing the presentation. */ public PPTXPresentation(String file) throws IOException { slideshow = new XMLSlideShow(new FileInputStream(new File(file))); slides = makeSlides(); }
From source file:org.sleuthkit.autopsy.imageExtractor.ImageExtractor.java
private List<ExtractedImage> extractImagesFromPptx(AbstractFile af) { List<ExtractedImage> listOfExtractedImages = new ArrayList<ExtractedImage>(); String parentFileName = getUniqueName(af); XMLSlideShow pptx;//from w w w . j a v a 2s .co m try { pptx = new XMLSlideShow(new ReadContentInputStream(af)); } catch (IOException ex) { logger.log(Level.WARNING, "SlideShow container could not be instantiated while reading " + af.getName(), ex); return null; } List<XSLFPictureData> listOfAllPictures = pptx.getAllPictures(); // if no images are extracted from the ppt, return null, else initialize // the output folder for image extraction. String outputFolderPath; if (listOfAllPictures.isEmpty()) { return null; } else { outputFolderPath = getOutputFolderPath(parentFileName); } if (outputFolderPath == null) { logger.log(Level.WARNING, "Could not get path for image extraction from AbstractFile: {0}", af.getName()); return null; } for (XSLFPictureData xslsPicture : listOfAllPictures) { // get image file name, write it to the module outputFolder, and add // it to the listOfExtractedImages. String fileName = xslsPicture.getFileName(); FileOutputStream fos = null; try { fos = new FileOutputStream(outputFolderPath + File.separator + fileName); } catch (FileNotFoundException ex) { logger.log(Level.WARNING, "Invalid path provided for image extraction", ex); continue; } try { fos.write(xslsPicture.getData()); fos.close(); } catch (IOException ex) { logger.log(Level.WARNING, "Could not write to the provided location", ex); continue; } String fileRelativePath = File.separator + moduleDirRelative + File.separator + parentFileName + File.separator + fileName; long size = xslsPicture.getData().length; ExtractedImage extractedimage = new ExtractedImage(fileName, fileRelativePath, size, af); listOfExtractedImages.add(extractedimage); } return listOfExtractedImages; }
From source file:org.sleuthkit.autopsy.modules.embeddedfileextractor.ImageExtractor.java
License:Open Source License
/** * Extract images from pptx format files. * * @param af the file from which images are to be extracted. * * @return list of extracted images. Returns null in case no images were * extracted./*w ww. j a v a 2 s .c o m*/ */ private List<ExtractedImage> extractImagesFromPptx(AbstractFile af) { List<ExtractedImage> listOfExtractedImages; XMLSlideShow pptx; try { pptx = new XMLSlideShow(new ReadContentInputStream(af)); } catch (Throwable ex) { // instantiating POI containers throw RuntimeExceptions logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(), "EmbeddedFileExtractorIngestModule.ImageExtractor.pptxContainer.init.err", af.getName()), ex); //NON-NLS return null; } List<XSLFPictureData> listOfAllPictures = null; try { listOfAllPictures = pptx.getAllPictures(); } catch (Exception ex) { // log internal Java and Apache errors as WARNING logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(), "EmbeddedFileExtractorIngestModule.ImageExtractor.processing.err", af.getName()), ex); //NON-NLS return null; } // if no images are extracted from the PPT, return null, else initialize // the output folder for image extraction. String outputFolderPath; if (listOfAllPictures.isEmpty()) { return null; } else { outputFolderPath = getOutputFolderPath(this.parentFileName); } if (outputFolderPath == null) { logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(), "EmbeddedFileExtractorIngestModule.ImageExtractor.extractImageFrom.outputPath.exception.msg", af.getName())); //NON-NLS return null; } listOfExtractedImages = new ArrayList<>(); byte[] data = null; for (XSLFPictureData xslsPicture : listOfAllPictures) { // get image file name, write it to the module outputFolder, and add // it to the listOfExtractedImageAbstractFiles. String fileName = xslsPicture.getFileName(); try { data = xslsPicture.getData(); } catch (Exception ex) { // log internal Java and Apache errors as WARNING logger.log(Level.WARNING, NbBundle.getMessage(this.getClass(), "EmbeddedFileExtractorIngestModule.ImageExtractor.processing.err", af.getName()), ex); //NON-NLS return null; } writeExtractedImage(Paths.get(outputFolderPath, fileName).toString(), data); listOfExtractedImages.add( new ExtractedImage(fileName, getFileRelativePath(fileName), xslsPicture.getData().length, af)); } return listOfExtractedImages; }
From source file:org.terrier.indexing.POIDocument.java
License:Mozilla Public License
protected POITextExtractor getExtractor(String filename, InputStream docStream) throws IOException { //Word .doc: if (filename.endsWith(".doc")) { return new WordExtractor(docStream); }// w w w . j a va 2 s . c o m //Word .docx: if (filename.endsWith(".docx")) { return new XWPFWordExtractor(new XWPFDocument(docStream)); } //Powertpoint .ppt: if (filename.endsWith(".ppt")) { return new PowerPointExtractor(docStream); } //Powertpoint .pptx: if (filename.endsWith(".pptx")) { return new XSLFPowerPointExtractor(new XMLSlideShow(docStream)); } //Publisher .pub: if (filename.endsWith(".pub")) { return new PublisherTextExtractor(docStream); } //Excel: .xls: if (filename.endsWith(".xls")) { return new ExcelExtractor(new POIFSFileSystem(docStream)); } //Excel: .xlsx: if (filename.endsWith(".xlsx")) { return new org.apache.poi.xssf.extractor.XSSFExcelExtractor(new XSSFWorkbook(docStream)); } //Visio: .vsd: if (filename.endsWith(".vsd")) { return new VisioTextExtractor(docStream); } return null; }
From source file:org.wso2.carbon.apimgt.impl.indexing.indexer.DocumentIndexer.java
License:Open Source License
/** * Write document content to document artifact as its raw content * * @param registry/*from w w w .j ava 2 s . c o m*/ * @param documentResource * @return * @throws RegistryException * @throws IOException * @throws APIManagementException */ private String fetchDocumentContent(Registry registry, Resource documentResource) throws RegistryException, IOException, APIManagementException { GenericArtifactManager docArtifactManager = APIUtil.getArtifactManager(registry, APIConstants.DOCUMENTATION_KEY); GenericArtifact documentArtifact = docArtifactManager.getGenericArtifact(documentResource.getUUID()); String sourceType = documentArtifact.getAttribute(APIConstants.DOC_SOURCE_TYPE); String contentString = null; if (Documentation.DocumentSourceType.FILE.name().equals(sourceType)) { Association fileAssociations[] = registry.getAssociations(documentResource.getPath(), APIConstants.DOCUMENTATION_FILE_ASSOCIATION); Association fileAssociation; if (fileAssociations.length < 1) { String error = "No document associated to API"; log.error(error); throw new APIManagementException(error); } //a file document can have one file association fileAssociation = fileAssociations[0]; String contentPath = fileAssociation.getDestinationPath(); if (!registry.resourceExists(contentPath)) { String error = "API not found at " + contentPath; log.error(error); throw new APIManagementException(error); } Resource contentResource = registry.get(contentPath); String fileName = ((ResourceImpl) contentResource).getName(); String extension = FilenameUtils.getExtension(fileName); InputStream inputStream = null; try { inputStream = contentResource.getContentStream(); switch (extension) { case APIConstants.PDF_EXTENSION: PDFParser pdfParser = new PDFParser(inputStream); pdfParser.parse(); COSDocument cosDocument = pdfParser.getDocument(); PDFTextStripper stripper = new PDFTextStripper(); contentString = stripper.getText(new PDDocument(cosDocument)); break; case APIConstants.DOC_EXTENSION: { POIFSFileSystem pfs = new POIFSFileSystem(inputStream); WordExtractor msWord2003Extractor = new WordExtractor(pfs); contentString = msWord2003Extractor.getText(); break; } case APIConstants.DOCX_EXTENSION: XWPFDocument doc = new XWPFDocument(inputStream); XWPFWordExtractor msWord2007Extractor = new XWPFWordExtractor(doc); contentString = msWord2007Extractor.getText(); break; case APIConstants.XLS_EXTENSION: { POIFSFileSystem pfs = new POIFSFileSystem(inputStream); ExcelExtractor extractor = new ExcelExtractor(pfs); contentString = extractor.getText(); break; } case APIConstants.XLSX_EXTENSION: XSSFWorkbook xssfSheets = new XSSFWorkbook(inputStream); XSSFExcelExtractor xssfExcelExtractor = new XSSFExcelExtractor(xssfSheets); contentString = xssfExcelExtractor.getText(); break; case APIConstants.PPT_EXTENSION: { POIFSFileSystem fs = new POIFSFileSystem(inputStream); PowerPointExtractor extractor = new PowerPointExtractor(fs); contentString = extractor.getText(); break; } case APIConstants.PPTX_EXTENSION: XMLSlideShow xmlSlideShow = new XMLSlideShow(inputStream); XSLFPowerPointExtractor xslfPowerPointExtractor = new XSLFPowerPointExtractor(xmlSlideShow); contentString = xslfPowerPointExtractor.getText(); break; case APIConstants.TXT_EXTENSION: case APIConstants.WSDL_EXTENSION: case APIConstants.XML_DOC_EXTENSION: BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; StringBuilder contentBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { contentBuilder.append(line); } contentString = contentBuilder.toString(); break; } } finally { IOUtils.closeQuietly(inputStream); } } else if (Documentation.DocumentSourceType.INLINE.name().equals(sourceType)) { Association contentAssociations[] = registry.getAssociations(documentResource.getPath(), APIConstants.DOCUMENTATION_CONTENT_ASSOCIATION); Association contentAssociation; //an inline document can have one or no content associations if (contentAssociations.length == 1) { contentAssociation = contentAssociations[0]; String contentPath = contentAssociation.getDestinationPath(); if (registry.resourceExists(contentPath)) { Resource contentResource = registry.get(contentPath); InputStream instream = null; BufferedReader reader = null; String line; try { instream = contentResource.getContentStream(); reader = new BufferedReader(new InputStreamReader(instream)); StringBuilder contentBuilder = new StringBuilder(); while ((line = reader.readLine()) != null) { contentBuilder.append(line); } contentString = contentBuilder.toString(); } finally { if (reader != null) { IOUtils.closeQuietly(reader); } } } } } return contentString; }
From source file:poi.xslf.usermodel.DataExtraction.java
License:Apache License
public static void main(String args[]) throws Exception { if (args.length == 0) { System.out.println("Input file is required"); return;//from w w w .j ava 2 s . co m } FileInputStream is = new FileInputStream(args[0]); XMLSlideShow ppt = new XMLSlideShow(is); is.close(); // Get the document's embedded files. List<PackagePart> embeds = ppt.getAllEmbedds(); for (PackagePart p : embeds) { String type = p.getContentType(); String name = p.getPartName().getName(); //typically file name InputStream pIs = p.getInputStream(); // make sense of the part data pIs.close(); } // Get the document's embedded files. List<XSLFPictureData> images = ppt.getAllPictures(); for (XSLFPictureData data : images) { PackagePart p = data.getPackagePart(); String type = p.getContentType(); String name = data.getFileName(); InputStream pIs = p.getInputStream(); // make sense of the image data pIs.close(); } Dimension pageSize = ppt.getPageSize(); // size of the canvas in points for (XSLFSlide slide : ppt.getSlides()) { for (XSLFShape shape : slide) { Rectangle2D anchor = shape.getAnchor(); // position on the canvas if (shape instanceof XSLFTextShape) { XSLFTextShape txShape = (XSLFTextShape) shape; System.out.println(txShape.getText()); } else if (shape instanceof XSLFPictureShape) { XSLFPictureShape pShape = (XSLFPictureShape) shape; XSLFPictureData pData = pShape.getPictureData(); System.out.println(pData.getFileName()); } else { System.out.println("Process me: " + shape.getClass()); } } } }