Java Code Examples for org.apache.poi.hslf.usermodel.HSLFSlide#getTitle()

The following examples show how to use org.apache.poi.hslf.usermodel.HSLFSlide#getTitle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PPTSlideRenderPanel.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private HSLFShape getTitleShape(HSLFSlide slide) {
        String slideTitle = slide.getTitle();

        for (HSLFShape shape : slide.getShapes()) {
            if (shape instanceof AutoShape) {
                HSLFAutoShape autoShape = (HSLFAutoShape) shape;
                if (autoShape.getText() != null && autoShape.getText().equals(slideTitle)) {
                    int type = autoShape.getRunType();

                    if (type == TextHeaderAtom.CENTER_TITLE_TYPE || type == TextHeaderAtom.TITLE_TYPE) {
                        return shape;
                    }
                }
            }
        }

//  When you have a XSLFSlide object you can use .getShapes() to get all shapes in the slide. If the shape is a
// XSLFTextShape you can use .getTextType() to check if it's a title, .getTextParagraphs() to get the paragraphs and
// .getTextRuns() on the paragraphs to get the text runs with the text. That should give you

        return null;

        // can not work as we don't have a slide title for slides without a title element
//        // if we don't find a title shape than use the most topwards element as question
//        if(slide.getShapes().length ==0)
//            return null;
//
//        return Collections.max(Arrays.asList(slide.getShapes()), new Comparator<Shape>() {
//            @Override
//            public int compare(Shape o1, Shape o2) {
//                return o1.getAnchor().getCenterY() - o2.getAnchor().getCenterY() < 0 ? -1 : 1;
//            }
//        });
    }
 
Example 2
Source File: ConvertPPT2PNG.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
        FileInputStream is = new FileInputStream("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.ppt");
//        FileInputStream is = new FileInputStream("/Users/brandl/Dropbox/private/oc2/testdata/Presentation5.ppt");

        HSLFSlideShow ppt = new HSLFSlideShow(is);


        is.close();

        Dimension pgsize = ppt.getPageSize();

        java.util.List<HSLFSlide> slides = ppt.getSlides();

        for (int i = 0; i < slides.size(); i++) {

            BufferedImage img = new BufferedImage(pgsize.width, pgsize.height,
                    BufferedImage.TYPE_INT_RGB);
            Graphics2D graphics = img.createGraphics();
            //clear the drawing area
            graphics.setPaint(Color.white);
            graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height));

            //render
            HSLFSlide slide1 = slides.get(i);

            slide1.draw(graphics);

            //save the output
            FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + slide1.getTitle() + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }
    }
 
Example 3
Source File: ExtractSlidesFromPPT.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws IOException {
//        XMLSlideShow ppt = new XMLSlideShow();
//        FileInputStream is = new FileInputStream("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.ppt");
        FileInputStream is = new FileInputStream("testdata/testdata 1 reordered slides.ppt");
        HSLFSlideShow ppt = new HSLFSlideShow(is);

        for (HSLFSlide slide : ppt.getSlides()) {
            String slideTitle = slide.getTitle();

            System.err.println("-----------");
            System.err.println(slideTitle);


//            System.err.println("sheetid   : "+slide.getSlideRecord().getSheetId());
//            // does just reflect the slide number
//
//            System.err.println("refsheetid: "+ slide._getSheetRefId());
//
//            System.err.println("atomhah: "+ slide.getSlideRecord().getSlideAtom().toString());
//
//            System.err.println("ppdrawing: "+ slide.getSlideRecord().toString());

            System.err.println(slide.getSlideRecord().getPPDrawing());

            slide.getSlideRecord().getPPDrawing().toString();
            slide.getSlideRecord().getSlideAtom().hashCode();


//        XSLFSlide slide getTitle= ppt.getSlides()[0];0

//         new org.apache.poi.hslf.extractor.PowerPointExtractor("xslf-demo.pptx").getSlides
        }
    }
 
Example 4
Source File: PPTSerializer.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public FlashCardCollection readFlashcardsFromFile(CardFile cardFile) {
        Utils.log("extracting  flashcards from file '" + cardFile + "'...");

        FlashCardCollection fc = new FlashCardCollection();
        try {
            if (cardFile.getFileLocation().getName().endsWith(".ppt")) {

                FileInputStream is = new FileInputStream(cardFile.getFileLocation());
                HSLFSlideShow ppt = new HSLFSlideShow(is);

                for (HSLFSlide xslfSlide : ppt.getSlides()) {
                    String slideTitle = xslfSlide.getTitle();
                    if (slideTitle == null)
                        continue;

                    // old OC1.x approach to create a unique card-id
//                int cardID = Utils.getRandGen().nextInt(Integer.MAX_VALUE);

                    fc.add(new FlashCard(slideTitle.hashCode(), slideTitle, xslfSlide.getSlideNumber()));
                }


            } else if (cardFile.getFileLocation().getName().endsWith(".md")) {
                boolean useSelector = cardFile.getProperties().useMarkdownSelector();
                List<MarkdownFlashcard> flashcards = MarkdownParserKt.parseMD(cardFile.getFileLocation(), useSelector);

                for (int i = 0; i < flashcards.size(); i++) {
                    MarkdownFlashcard card = flashcards.get(i);
                    String question = card.getQuestion();
                    if (question.trim().isEmpty()) {
                        continue;
                    }

                    fc.add(new FlashCard(question.hashCode(), question, i + 1));

                }
            } else {
                throw new InvalidCardFileFormatException();
            }

        } catch (IOException e) {
            // rephrase IO problem into something more specific
            throw new InvalidCardFileFormatException();
        }

        return fc;
    }