在 JavaScript 中從 PDF 或 HTML 匯入簡報
Contents
[
Hide
]
介紹
使用 Aspose.Slides for Node.js via Java,您可以從其他格式的檔案匯入簡報。Aspose.Slides 提供了 SlideCollection 類別,讓您能夠從 PDF、HTML 文件等匯入簡報。
從 PDF 匯入 PowerPoint
在此情況下,您可以將 PDF 轉換為 PowerPoint 簡報。

- 建立 Presentation 類別的實例。
- 呼叫 addFromPdf() 方法並傳入 PDF 檔案。
- 使用 save() 方法以 PowerPoint 格式儲存檔案。
以下 JavaScript 程式碼示範 PDF 轉 PowerPoint 的操作:
var pres = new aspose.slides.Presentation();
try {
pres.getSlides().addFromPdf("InputPDF.pdf");
pres.save("OutputPresentation.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Tip
您可能想看看 Aspose free PDF to PowerPoint 網路應用程式,因為它提供了此處所述流程的即時實作。從 HTML 匯入 PowerPoint
在此情況下,您可以將 HTML 文件轉換為 PowerPoint 簡報。
- 建立 Presentation 類別的實例。
- 呼叫 addFromHtml() 方法並傳入 PDF 檔案。
- 使用 save() 方法以 PowerPoint 格式儲存檔案。
以下 JavaScript 程式碼示範 HTML 轉 PowerPoint 的操作:
var presentation = new aspose.slides.Presentation();
try {
var htmlStream = java.newInstanceSync("java.io.FileInputStream", "page.html");
try {
presentation.getSlides().addFromHtml(htmlStream);
} finally {
if (htmlStream != null) {
htmlStream.close();
}
}
presentation.save("MyPresentation.pptx", aspose.slides.SaveFormat.Pptx);
} catch (e) {
console.log(e);
} finally {
if (presentation != null) {
presentation.dispose();
}
}
常見問題
在匯入 PDF 時,表格會被保留嗎?是否可以改進其偵測?
在匯入過程中可以偵測表格;PdfImportOptions 包含一個 setDetectTables 方法,可啟用表格辨識。其效能取決於 PDF 的結構。