이 기사는 주로 PPT를 그림으로 변환하는 Apache POI에 대한 관련 컨텐츠를 공유합니다. Apache POI를 간단히 소개하고 특정 컨텐츠는 다음과 같습니다.
1. Apache Poi 소개
Apache Poi는 Java로 작성된 무료 및 오픈 소스 크로스 플랫폼 Java API입니다. Apache Poi는 Microsoft Office Format Archives를 읽고 작성하는 Java 프로그램의 기능을 제공합니다.
공식 문서 Apache POI 공식 웹 사이트를 볼 수 있습니다.
Apache POI를 사용하여 PPT 문서를 운영하는 두 가지 방법이 있습니다.
1. POII-HSLF에 해당하는 PowerPoint '97 (-2007)의 파일 형식 접미사는 .ppt입니다.
2. powi-xslf에 해당하는 PowerPoint 2007 OOXML의 파일 형식 접미사는 .pptx입니다.
2. JAR 패키지
POI Offorine의 POI 작업은 JAR 패키지가 필요합니다.
poi-3.12.jar poi-ooxml-3.12.jar poi-ooxml-schemas-3.12.jar poi-scratchpad-3.12.jar xmlbeans-2.6.0.jar
Maven 방법 도입 :
Maven 방법은 다른 여러 사람에게 의존하기 때문에 두 개만 소개하면됩니다.
<pectionency> <groupid> org.apache.poi </groupid> <artifactid> poi-ooxml </artifactid> <버전> 3.12 </version> </dependency> <prectionency> <groupid> org.apache.poi </groupid> <artifactid> poi-scratchpad </artifactid> 3.12 </version> 3.12 </version> 3.12
3. POI-HSLF 방법
POI-HSLF 메소드는 ppt의 .ppt 접미사로 끝나는 문서를 처리합니다.
/** * ppt2003 문서의 변환 접미사는 .ppt * @ppl * @pple imgfile 이미지가 저장 될 디렉토리 (파일이 아님) */public static boolean doppt2003toimage (파일 pptfile, 파일 imgfile, list) {file {file ppepstrem is = new is = new) fileInputStream (pptFile); 슬라이드 쇼 ppt = 새로운 슬라이드 쇼 (is); // 입력 스트림을 시간에 닫습니다. "page."); textrun [] truns = slide [i] .getTextruns (); for (int k = 0; k <truns.length; k ++) {richtextrun [] rtruns = truns [k] .getRichtextruns (int l = 0; l <rtruns.length; l ++) {// 원래 font 및 font and ont and font and ont and on+). rtruns [l] .getFontIngex (); String name = rtruns [l] .getfontname (); log.info ( "원래 글꼴 인덱스 및 글꼴 이름 :"+index+" -"+name); // 글꼴 인덱스와 글꼴 이름을 재설정하여 생성 된 이미지를 방지합니다. rtruns [l] .setfontindex (1); rtruns [l] .setfontname ( "宋体");}} // 슬라이드 BufferedImage img = new bufferedimage (pgsize.width, pgsize.height, buffered_rgb)의 크기에 따라 이미지를 생성합니다. img.creategraphics (); Graphics.setPaint (color.white); Graphics.fill (new emptangle2d.float (0, 0, pgsize.width, pgsize.height)); 슬라이드 [i] .Draw (그래픽); // apbostepath = imgfile.getabsolutepathath () + " +" + " +" + " +" + " +" + " +") ".jpeg"; 파일 jpegfile = 새 파일 (AbsolutePath); // 이미지 경로는 list.add ((i + 1) + ".jpeg")에 저장됩니다. // 이미지가 존재하면 생성 된 if (jpegfile.exists ()) {여기서 이미지의 스토리지 경로 (Jpeg, png, bmp)). 생성 파일 파일 파일 OutStream out = 새 FileOutputStream (jpegfile); imageio.write (img, "jpeg", out); out.close ();} log.error ( "ppt가 이미지로 성공적으로 변환 됨!");} catch (예외 e) {log.error ( "이미지로 변환 될 때 예외!};4. poi-xslf 방법
POI-XSLF 메소드는 ppt 파일의 .pptx 접미사로 끝나는 문서를 처리합니다.
/** * ppt2007 문서의 변환 접미사는 .pptx * @pptx * @ppram pptfile ppt 파일 * @param imgfile 이미지가 저장 될 경로 디렉토리 (파일 아님) * @param 파일 이름 */public static boolean doppt2007toimage (파일 pptfile, list <stram). is = null; try {is = new = new fileInputStream (pptfile); xmlSlidShow XMLSLIDSHOW = new XmlSlidShow (is); is.close (); // 크기 치수 가져 오기 pgsize = xmlslideshow.getPagesize (); slide xslfslidrid get xslfslidue = xmlslideshow.getSlides (); for (int i = 0; i <slides.length; i ++) {// bread 블 문제 해결 xslfshape [] shapes = slides [i] .getshapes (); for (xslfshape shapes) {if (shape instansof xslftextshape) {xslftedshape) (xslftextshape) 모양; list <xslftextparagraphs = sh.getTextParagraphs (); for (xslftextParagraph xslftextParaphph : textParagraphs) {list <xslftextrun> textruns = xslftextparagraph.getTextruns (); xslftextrun : textruns) {xslftextrun.setfontfamily ( "安");}}} // 슬라이드 bufferedimage img = 크기에 따라 이미지 생성 이미지 생성 = new bufferedimage (pgsize.width, pgsize.height, bufferedimage.type _int_int_int_int_int_int_int_int_int _int_int_int_int_int_int_int. img.creategraphics (); Graphics.setPaint (color.white); Graphics.fill (new eartangle2d.float (0, 0, pgsize.width, pgsize.height)); // 가장 핵심 코드 슬라이드 [i]. draw (draw); (i + 1) + ".jpeg"; file jpegfile = new File (AbsolutePath); // 이미지 경로는 list.add ((i + 1) + ".jpeg")에 저장되어 있습니다. // 이미지가 존재하면 (jpegfile.exists ()) {계속; PATH FILEOUTPUTSTREAM out = 새 FILEOUTPUTESTREAM (JPEGFILE); // 이미지에 imageio.write (img, "jpeg", out)에 이미지에 쓰기 거짓;}5. 가능한 오류
org.apache.poi.poifs.filesystem.officexmlfileException : 제공된 데이터는 Office 2007+ XML에있는 것으로 보입니다. OLE2 사무실 문서를 다루는 POI의 일부를 호출하고 있습니다. 이 데이터를 처리하려면 POI의 다른 부분을 호출해야합니다 (예 : HSSF 대신 XSSF).
위의 오류는 발생하며, 이는 서신에 사용되지 않으며 두 번째 방법을 사용하여 ppt를 변환해야합니다.
POI가 잘 수행되지 않고 그림이 쉽게 왜곡되기 때문에 핵심 변환이 쉽게 변경 될 때 문제가 발생합니다.
// 가장 핵심 코드 슬라이드 [i] .Draw (그래픽);
요약
위의 모든 것은 PPT를 이미지 인스턴스 코드로 변환하는 Apache POI에 관한 것입니다. 모든 사람에게 도움이되기를 바랍니다. 관심있는 친구는이 사이트의 다른 관련 주제를 계속 참조 할 수 있습니다. 단점이 있으면 메시지를 남겨 두십시오. 이 사이트를 지원해 주신 친구들에게 감사드립니다!