通常,开发人员必须以编程方式将 DOC 文件转换为 PPTM。通过使用文件自动化 Java 库 Aspose.Total for Java ,您可以通过几个简单的步骤来自动化渲染过程。您可以使用 Aspose.Words for Java 加载 DOC 文件并将其转换为 HTML。之后,通过使用强大的 PowerPoint 操作 Java API Aspose.Slides for Java ,您可以创建一个新的演示文稿,在其中写入 HTML 内容,并将其保存为 PPTM .
如何通过 Java 将 DOC 转换为 PPTM 或在线应用程序
- 使用 Document 类打开 DOC 文件
- 使用 [save]( https://reference.aspose.com/words/java/com.aspose.words/Document#save(java.lang.String,com.aspose.words.SaveOptions) 将 DOC 文件转换为 HTML)) 方法
- 始化一个新的 Presentation 对象
- 使用 BufferedReader 从 HTML 文件中提取内容并将内容写入您的演示文件
- 使用 save 方法将文档保存到 PPTM
// supports DOC, DOCX, DOT, DOTM, DOTX, FLATOPC, ODT, OTT, RTF, TXT, WORDML, DOCM input file formats | |
// load DOC file with an instance of Document | |
Document document = new Document("template.doc"); | |
// save the document in HTML file format | |
document.save("HtmlOutput.html",SaveFormat.HTML); | |
// create a new presentation | |
Presentation pres = new Presentation(); | |
// access the default first slide of presentation | |
ISlide slide = pres.getSlides().get_Item(0); | |
// add the AutoShape to accommodate the HTML content | |
IAutoShape ashape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 10, 10, | |
(float) pres.getSlideSize().getSize().getWidth(), | |
(float) pres.getSlideSize().getSize().getHeight()); | |
ashape.getFillFormat().setFillType(FillType.NoFill); | |
// add text frame to the shape | |
ashape.addTextFrame(""); | |
// clear all paragraphs in added text frame | |
ashape.getTextFrame().getParagraphs().clear(); | |
// initialize StringBuilder to read Html | |
StringBuilder contents = new StringBuilder(); | |
// load HTML file by using BufferedReader | |
BufferedReader reader = new BufferedReader(new FileReader(new File("HtmlOutput.html"))); | |
String text = null; | |
// repeat until all lines are read | |
while ((text = reader.readLine()) != null) { | |
contents.append(text).append(System.getProperty("line.separator")); | |
} | |
reader.close(); | |
// add HTML content in text frame | |
ashape.getTextFrame().getParagraphs().addFromHtml(content); | |
// supports POTM, POT, POTX, PPSM, PPS, PPSX, PPTM, PPT, PPTX, ODP output file formats. | |
// save presentation as Pptx | |
pres.save("output.pptx", com.aspose.slides.SaveFormat.Pptx); |
免费的 DOC 到 PPTM 在线转换器
转换要求
该 API 还允许您将受密码保护的 DOC 文档转换为 PPTM。如果您输入的 DOC 文档受密码保护,则您无法在不使用密码的情况下将其转换为 PPTM 格式。为了打开加密文档,您可以在 LoadOptions 对象中设置正确的密码并将其传递给 Document 构造函数。
// supports DOC, DOT, DOCX, DOCM, DOTX, and DOTM file formats | |
// load DOC file with an instance of Document | |
Document document = new Document("template.doc", new LoadOptions("MyPassword")); | |
// save the document in HTML file format | |
document.save("HtmlOutput.html",SaveFormat.HTML); | |
// create a new presentation | |
Presentation pres = new Presentation(); | |
// perform the conversion to PPT |
经常问的问题
- 如何在线将 DOC 转换为 PPTM?上面集成的在线应用程序允许您将 DOC 文件转换为 PPTM。要开始,只需在白色区域内拖放或单击即可导入 DOC 文件。上传文件后,单击“转换”按钮。 DOC 到 PPTM 的转换过程完成后,您只需单击一下即可下载转换后的文件。
- 转换 DOC 需要多长时间?此在线 DOC 转换器运行速度很快,但其速度主要取决于您要转换的 DOC 文件的大小。只需几秒钟即可将较小的 DOC 文件转换为 PPTM。如果您已将转换代码集成到您的 Java 应用程序中,则转换过程的速度将取决于您对应用程序的优化程度。
- 使用免费的 Aspose.Total 转换器将 DOC 转换为 PPTM 是否安全?当然!转换完成后,您的 PPTM 文件的下载链接将立即可用。您上传的文件将在 24 小时后被删除,下载链接将在该时间段后失效。您的文件是安全的,没有人可以访问它们。集成应用程序主要免费用于测试目的,因此您可以在集成代码之前验证结果。
- 我应该使用什么浏览器来转换 DOC?您可以使用任何现代浏览器(如 Google Chrome、Firefox、Opera 或 Safari)执行此在线转换。但是,如果您正在构建桌面应用程序,Aspose.Total DOC Conversion API 会提供流畅的体验。