org.apache.poi.hslf.usermodel.HSLFSlideShow Java Examples

The following examples show how to use org.apache.poi.hslf.usermodel.HSLFSlideShow. 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: PPTUtil.java    From SpringMVC-Project with MIT License 6 votes vote down vote up
/**
 * 转换2003版(.ppt)格式的PPT文件为图片
 */
private static List<String> convertPPT2003ToImages(String pptFilePath, String imageFolderPath) throws IOException {
    List<String> imagePathList = Lists.newArrayList();

    FileInputStream fis = new FileInputStream(pptFilePath);
    HSLFSlideShow ppt = new HSLFSlideShow(fis);
    fis.close();

    Dimension dimension = ppt.getPageSize();
    List<HSLFSlide> slideList = ppt.getSlides();
    int index = 0;
    for (HSLFSlide slide : slideList) {

        logger.info("正在转换PPT第" + (++index) + "页");

        File imageFile = new File(imageFolderPath + "/" + (index) + ".png");

        convertSlideToImage(slide, dimension, imageFile);

        imagePathList.add(imageFile.getAbsolutePath());
    }

    return imagePathList;
}
 
Example #2
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean showCardQuestion(Item item) {
    if (!doOptionalSync(item))
        return false;

    int cardIndex = item.getFlashCard().getCardIndex();
    ReversePolicy cardRevPolicy = item.getFlashCard().getTodaysRevPolicy();

    // note:
    // The random-reverse mode is encoded directly in the flashcard in order to make its policy temporary
    // persistent during the todaysltm-sessions
    Slide curSlide = ((HSLFSlideShow) slideShow).getSlides().get(cardIndex - 1);

    switch (cardRevPolicy) {
        case NORMAL:
            showCardQuestion(curSlide);
            break;
        case REVERSE:
            showCardContent(curSlide);
            break;
        default:
            throw new RuntimeException("unsupported reverse policy");
    }

    return true;
}
 
Example #3
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Test if item is in sync with given slide-show instance
 */
private boolean isItemOutOfSync(Item item, SlideShow slideShow) {
    final List<? extends Slide> allSlides = ((HSLFSlideShow) slideShow).getSlides();

    final int itemCardIndex = item.getFlashCard().getCardIndex();

    return itemCardIndex < 0 || (allSlides.size() < itemCardIndex - 1)
            || allSlides.get(itemCardIndex - 1).getTitle() == null
            || allSlides.get(itemCardIndex - 1).getTitle().hashCode() != item.getFlashCard().getCardID();
}
 
Example #4
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 #5
Source File: ExtractSlidesFromPPTX.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");
        HSLFSlideShow ppt = new HSLFSlideShow(is);

        for (HSLFSlide xslfSlide : ppt.getSlides()) {
            System.out.println(xslfSlide.getTitle());
        }

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

//         new org.apache.poi.hslf.extractor.PowerPointExtractor("xslf-demo.pptx").getSlides
    }
 
Example #6
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 #7
Source File: ConvertPPTX2PNG.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void main(String[] args) throws IOException, InvalidFormatException {
        FileInputStream is = new FileInputStream("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.pptx");

        XMLSlideShow ppt2 = new XMLSlideShow(OPCPackage.open("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.pptx"));
        XSLFSlide slide1 = ppt2.getSlides().get(0);
//        slide1.get

        HSLFSlideShow ppt = new HSLFSlideShow(is);
//
        HSLFSlide slide2 = ppt.getSlides().get(1);


        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
            slides.get(i).draw(graphics);

            //save the output
            FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png");
            javax.imageio.ImageIO.write(img, "png", out);
            out.close();
        }
    }
 
Example #8
Source File: CardFile.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static SlideShow getSlideShow(CardFile cardFile) {
    try {
        FileInputStream is = new FileInputStream(cardFile.getFileLocation());
        return new HSLFSlideShow(is);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}
 
Example #9
Source File: PPTSlideManager.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean showCompleteCard(Item item) {
    Slide curSlide = ((HSLFSlideShow) slideShow).getSlides().get(item.getFlashCard().getCardIndex() - 1);
    getSlidePanel().configure(curSlide, true, true);

    return true;
}
 
Example #10
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;
    }
 
Example #11
Source File: ImportManager.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ImportManager(final Frame owner) {
        final String DEFAULT_DIR = "import.defdir";
        File defDir = new File(Utils.getPrefs().get(DEFAULT_DIR, System.getProperty("user.home")));
        JFileChooser importChooser = new JFileChooser(defDir);

        ImpSeparatorPanel sepPanel = new ImpSeparatorPanel(importChooser);

        importChooser.setDialogTitle(Utils.getRB().getString("cardimport.filechoose.title"));
        importChooser.setMultiSelectionEnabled(false);

        FileFilter csvFilter = new FileFilter() {

            public boolean accept(File f) {
                String fileName = f.getName();
                return (fileName.endsWith(".csv") || fileName.endsWith(".txt")) || f.isDirectory();
            }


            public String getDescription() {
                return "Text (*.csv, *.txt)";
            }
        };

        importChooser.setFileFilter(csvFilter);
        int status = importChooser.showOpenDialog(null);
        if (status != JFileChooser.APPROVE_OPTION) {
            return;
        }

        File selectedFile = importChooser.getSelectedFile();
        FileFilter selectedFilter = importChooser.getFileFilter();

        Utils.getPrefs().put(DEFAULT_DIR, selectedFile.getParentFile().getAbsolutePath());

        HSLFSlideShow slideShow = new HSLFSlideShow();

        if (selectedFilter == csvFilter) {
            Map<String, String> title2contents = readCsvFile(selectedFile, sepPanel.getCurSeparator());

            for (String slideTitle : title2contents.keySet()) {
                HSLFSlide slide = slideShow.createSlide();

                // create question shape
                HSLFTextBox title = slide.addTitle();
                title.setText(slideTitle);

                // create answer shape
                HSLFShape titleShape = slide.getShapes().get(0);

                HSLFTextBox txt = new HSLFTextBox();
                txt.setText(title2contents.get(slideTitle));
                Rectangle titleAnchor = titleShape.getAnchor().getBounds();
                txt.setAnchor(new Rectangle((int) titleAnchor.getX(), (int) titleAnchor.getY() + 200, (int) titleAnchor.getWidth(), (int) titleAnchor.getHeight()));

//use RichTextRun to work with the text format
//                HSLFTextShape titleFormat = ((AutoShape) titleShape).getStrokeStyle().getRichTextRuns()[0];
//                HSLFTextShape questionFormat = txt.getShapeType();
//                questionFormat.setFontSize(titleFormat.getFontSize());
//                slide.getShapes()[0];
//                questionFormat.setFontName(titleFormat.getFontName());
//                questionFormat.setAlignment(TextBox.AlignCenter);

                slide.addShape(txt);
            }

        }

        // show the FAQ if nothing was imported. But do this only once to avoid users to become annoyed
        String SHOWN_IMPORT_HELP_BEFORE = "hasShownImportHelp";
        if (slideShow.getSlides().size() < 2 && !Utils.getPrefs().getBoolean(SHOWN_IMPORT_HELP_BEFORE, false)) {
            Utils.getPrefs().putBoolean(SHOWN_IMPORT_HELP_BEFORE, true);
            new URLAction("nocardsimported", AboutDialog.OC_WEBSITE + "help").actionPerformed(null);
        } else {

            // save the sldeshow into a ppt
            final JFileChooser fc = new JFileChooser();
            fc.setSelectedFile(new File(selectedFile.getAbsolutePath() + ".ppt"));
            fc.setDialogTitle("Save imported flashcards as ");
            fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
            fc.setMultiSelectionEnabled(false);
            if (fc.showSaveDialog(owner) == JFileChooser.APPROVE_OPTION) {
                File saveFile = fc.getSelectedFile();

                try {
                    FileOutputStream out = new FileOutputStream(saveFile);
                    slideShow.write(out);
                    out.close();
                } catch (IOException e) {
                    System.err.println(e);
                }
            }

        }
    }
 
Example #12
Source File: PPTPresentation.java    From Quelea with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create a presentation from a file.
 *
 * @param file the file containing the presentation.
 */
public PPTPresentation(String file) throws IOException {
    slideshow = new HSLFSlideShow(new FileInputStream(new File(file)));
    slides = makeSlides();
}