提问者:小点点

POI不复制ppt幻灯片笔记


当我尝试将ppt幻灯片复制到新的ppt文档时。幻灯片演示部分已复制,但幻灯片注释未复制。

我从POI例子中尝试了MergePresentations.java。它也不复制笔记。

我明确地从源幻灯片中获取注释,然后将其设置为目标幻灯片。它仍然不起作用。

XSLFNotes sreNotes = srcSlide.getNotes();

XMLSlideShow ppt = new XMLSlideShow();
XSLFSlide targetSlide = ppt.createSlide();
targetSlide.importContent(slide);
targetSlide.setNotes(sreNotes);
FileOutputStream out = new FileOutputStream(getNextFileName(RESULT_DIR, charName));
ppt.write(out);
out.close();

如何复制带有注释的ppt幻灯片?感谢您的帮助。


共1个答案

匿名用户

我找到了从源幻灯片中获取注释的方法,然后将其设置为新幻灯片。当然,文本格式会丢失。

//Get note from a slide
private static String getNotesText(XSLFSlide slide) {

    XSLFNotes mynotes = slide.getNotes();
    for (XSLFShape shape : mynotes) {
        if (shape instanceof XSLFTextShape) {
            XSLFTextShape txShape = (XSLFTextShape) shape;
            for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {

                resultBuffer.append(xslfParagraph.getText())
                .append("\n");
            }
        }
    }

    return resultBuffer.toString();
}

private static void createNewPpt(XSLFSlide slide, Dimension pageSize) throws IOException {

    try (XMLSlideShow ppt = new XMLSlideShow()) {

        ppt.setPageSize(pageSize);

        XSLFSlide targetSlide = ppt.createSlide();
        targetSlide.importContent(slide);

        XSLFNotes targetNotes = ppt.getNotesSlide(targetSlide);
        for (XSLFTextShape targetShape : targetNotes.getPlaceholders()) {

            if (targetShape.getTextType() == Placeholder.BODY) {

                targetShape.setText(getNotesText(slide));
                break;
            }
        }


        FileOutputStream out = new FileOutputStream(getNextFileName(RESULT_DIR, charName));
        ppt.write(out);
        out.close();
    }
}