Java 응용 프로그램의 프레젠테이션 슬라이드에서 OLE 객체로 작업하는 방법

15192 단어 powerpointpdfolejava
슬라이드가 제품 시연에 사용될 때 일반적으로 다른 문서 파일(예: PDF, Excel 또는 Word)을 OLE 개체로 슬라이드에 추가하여 프레젠테이션에 대한 자세한 내용을 제공합니다. 이 기사에서는 Java용 Spire.Presentation을 사용하여 전체 PDF 파일을 프레젠테이션에 포함하고 Java 애플리케이션의 프레젠테이션에서 OLE 개체를 추출하는 방법을 보여줍니다.

개체로 프레젠테이션에 PDF 포함:

import com.spire.presentation.*;
import com.spire.presentation.drawing.IImageData;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;

public class embedPDFAsOLE  {
    public static void main(String[] args) throws Exception{

        Presentation ppt = new Presentation();
        //Load the image file
        File file =new File("PDFlogo.jpg");
        BufferedImage image = ImageIO.read(file);
        IImageData oleImage = ppt.getImages().append(image);
        Rectangle rec = new Rectangle(80, 60, image.getWidth(), image.getHeight());

        String input = "Sample.pdf";
        File oldFile=new File(input);
        FileInputStream inputStream = new FileInputStream(oldFile);
        byte[] data = new byte[(int)oldFile.length()];
        inputStream.read(data,0,data.length);

        //Insert an OLE object to presentation based on the PDF data
        com.spire.presentation.IOleObject oleObject=ppt.getSlides().get(0).getShapes().appendOleObject("pdf", data, rec);
        oleObject.getSubstituteImagePictureFillFormat().getPicture().setEmbedImage(oleImage);

        oleObject.setProgId("AcroExch.Document.11");
        //Save to file.
        ppt.saveToFile("output/embedPDFAsOLE.pptx", FileFormat.PPTX_2013);
    }


프레젠테이션 슬라이드에 개체로 PDF를 삽입한 후 효과적인 스크린샷:


프레젠테이션 슬라이드에서 OLE 개체를 추출합니다.

import com.spire.presentation.*;
import java.io.FileOutputStream;

public class extractOLEObject {
    public static void main(String[] args) throws Exception {

        //Create a PPT document
        Presentation presentation = new Presentation();

        //Load document from disk
        presentation.loadFromFile("output/embedPDFAsOLE.pptx");

        //Loop through the slides and shapes
        for (Object slideObj : presentation.getSlides()) {
            ISlide slide = (ISlide) slideObj;
            for (Object shapeObj : slide.getShapes()) {
                IShape shape = (IShape) shapeObj;
                if (shape instanceof IOleObject) {
                    //Find OLE object
                    IOleObject oleObject = (IOleObject) shape;

                    //Get its data and write to file
                    byte[] bytes = oleObject.getData();
                    switch (oleObject.getProgId()) {
                        case "Excel.Sheet.8":
                            String result1 = "output/extractOLEObject.xls";
                            FileOutputStream output1 = new FileOutputStream(result1);
                            output1.write(bytes);
                            output1.close();
                            break;
                        case "AcroExch.Document.11":
                            String result2 = "output/extractOLEObject.pdf";
                            FileOutputStream output2 = new FileOutputStream(result2);
                            output2.write(bytes);
                            output2.close();
                            break;
                        case "Word.Document.12":
                            String result4 = "output/extractOLEObject.docx";
                            FileOutputStream output4 = new FileOutputStream(result4);
                            output4.write(bytes);
                            output4.close();
                            break;
                        case "PowerPoint.Show.8":
                            String result5 = "output/extractOLEObject.ppt";
                            FileOutputStream output5 = new FileOutputStream(result5);
                            output5.write(bytes);
                            output5.close();
                            break;
                        case "PowerPoint.Show.12":
                            String result6 = "output/extractOLEObject.pptx";
                            FileOutputStream output6 = new FileOutputStream(result6);
                            output6.write(bytes);
                            output6.close();
                            break;
                    }
                }
            }
        }
    }
}


산출:


읽어주셔서 감사합니다!

좋은 웹페이지 즐겨찾기