Java 응용 프로그램의 프레젠테이션 슬라이드에서 OLE 객체로 작업하는 방법
15192 단어 powerpointpdfolejava
개체로 프레젠테이션에 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;
}
}
}
}
}
}
산출:
읽어주셔서 감사합니다!
Reference
이 문제에 관하여(Java 응용 프로그램의 프레젠테이션 슬라이드에서 OLE 객체로 작업하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/eiceblue/how-to-working-with-ole-object-in-presentation-slides-in-java-applications-b06텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)