赞
踩
Aspose.PDF for Java让你追踪PDF转化为PPTX的进度。Aspose.Slides提供了创建并且操作PPT/PPTX展示,同时也提供了将PPT/PPTX转化为PDF的功能。在将PDF转化为PPT/PPTX过程中,PDF文件的每一页将会被转化为单独的幻灯片,文本会被渲染成可编辑的Text。主要使用到的类是PptxSaveOptions,它会以参数的形式传递给Document.save()方法。
具体代码如下:
package com.aspose.pdf.examples; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import com.aspose.pdf.*; public final class ConvertPDFtoPPTX { private ConvertPDFtoPPTX() { } private static Path _dataDir = Paths.get("/home/admin1/pdf-examples/Samples"); public static void main(String[] args) throws IOException { ConvertPDFtoPPTX_Simple(); ConvertPDFtoPPTX_SlideAsImages(); } public static void ConvertPDFtoPPTX_Simple() { String pdfDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX.pdf").toString(); String pptxDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX_out.pptx").toString(); // Load PDF document Document doc = new Document(pdfDocumentFileName); // Instantiate PptxSaveOptions instance PptxSaveOptions pptx_save = new PptxSaveOptions(); // Save the output in PPTX format doc.save(pptxDocumentFileName, pptx_save); } }
如果想要将可搜索的PDF转化为图片的PPTX,而不是可选择的文本,可通过Aspose.PDF.PptxSaveOptions类的。需要设置PptxSaveOptions的SlidesAsImages属性为true。
具体代码如下:
public static void ConvertPDFtoPPTX_SlideAsImages() { String pdfDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX.pdf").toString(); String pptxDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX_out.pptx").toString(); // Load PDF document Document doc = new Document(pdfDocumentFileName); // Instantiate PptxSaveOptions instance PptxSaveOptions pptx_save = new PptxSaveOptions(); // Save the output in PPTX format pptx_save.setSlidesAsImages(true); doc.save(pptxDocumentFileName, pptx_save); } public static void ConvertPDFtoPPTX_ProgresDetails() { String pdfDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX.pdf").toString(); String pptxDocumentFileName = Paths.get(_dataDir.toString(), "PDFToPPTX_out.pptx").toString(); // Load PDF document Document doc = new Document(pdfDocumentFileName); // Instantiate PptxSaveOptions instance PptxSaveOptions pptx_save = new PptxSaveOptions(); // Specify Custom Progress Handler pptx_save.setCustomProgressHandler(new ShowProgressOnConsole()); // Save the output in PPTX format doc.save(pptxDocumentFileName, pptx_save); }
具体代码如下:
package com.aspose.pdf.examples; import java.time.LocalDateTime; import com.aspose.pdf.ProgressEventType; import com.aspose.pdf.UnifiedSaveOptions.ConversionProgressEventHandler; import com.aspose.pdf.UnifiedSaveOptions.ProgressEventHandlerInfo; class ShowProgressOnConsole extends ConversionProgressEventHandler{ @Override public void invoke(ProgressEventHandlerInfo eventInfo) { switch (eventInfo.EventType) { case ProgressEventType.TotalProgress: System.out.println( String.format("%s - Conversion progress : %d %%.", LocalDateTime.now().toString(), eventInfo.Value)); break; case ProgressEventType.ResultPageCreated: System.out.println(String.format("%s - Result page's %s of %d layout created.", LocalDateTime.now().toString(), eventInfo.Value, eventInfo.MaxValue)); break; case ProgressEventType.ResultPageSaved: System.out.println(String.format("%s - Result page %d of %d exported.", LocalDateTime.now(), eventInfo.Value, eventInfo.MaxValue)); break; case ProgressEventType.SourcePageAnalysed: System.out.println(String.format("%s - Source page %d of %d analyzed.", LocalDateTime.now(), eventInfo.Value, eventInfo.MaxValue)); break; default: break; } }
Aspose.Pdf.PptxSaveOptions类提供了CustomProgressHandler属性,它可以追踪转化的详细进度。
具体代码如下:
package com.aspose.pdf.examples; import java.time.LocalDateTime; import com.aspose.pdf.ProgressEventType; import com.aspose.pdf.UnifiedSaveOptions.ConversionProgressEventHandler; import com.aspose.pdf.UnifiedSaveOptions.ProgressEventHandlerInfo; class ShowProgressOnConsole extends ConversionProgressEventHandler{ @Override public void invoke(ProgressEventHandlerInfo eventInfo) { switch (eventInfo.EventType) { case ProgressEventType.TotalProgress: System.out.println( String.format("%s - Conversion progress : %d %%.", LocalDateTime.now().toString(), eventInfo.Value)); break; case ProgressEventType.ResultPageCreated: System.out.println(String.format("%s - Result page's %s of %d layout created.", LocalDateTime.now().toString(), eventInfo.Value, eventInfo.MaxValue)); break; case ProgressEventType.ResultPageSaved: System.out.println(String.format("%s - Result page %d of %d exported.", LocalDateTime.now(), eventInfo.Value, eventInfo.MaxValue)); break; case ProgressEventType.SourcePageAnalysed: System.out.println(String.format("%s - Source page %d of %d analyzed.", LocalDateTime.now(), eventInfo.Value, eventInfo.MaxValue)); break; default: break; } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。