翻譯|使用教程|編輯:李顯亮|2020-01-02 10:09:06.477|閱讀 1848 次
概述:在將各種文檔轉換為PDF格式的過程中,PPT到PDF的轉換是一種流行的用例,如果您希望在Java中通過編程的方式將PPT或PPTX轉換為PDF,那么你可以認真閱讀本文的教程,將演示如何使用 Aspose.Slides for Java API提供的各種選項。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
PDF已成為最廣泛和最常用的數字文檔格式。由于PDF格式具有固定的布局,因此大多數文檔在共享之前都已轉換為PDF。
在將各種文檔轉換為PDF格式的過程中,PPT到PDF的轉換是一種流行的用例,且非常的方便省時,特別是當必須將大量PowerPoint演示文稿轉換為PDF時。如果您希望在Java中通過編程的方式將PPT或PPTX轉換為PDF,那么你可以認真閱讀本文的教程,將演示如何使用 Aspose.Slides for Java API提供的各種選項。
如果您還未使用過Java版Aspose.Slides,可點擊此處下載最新版體驗。
在本文中,我們將介紹使用Aspose.Slides for Java的以下轉換方案:
以下是使用Aspose.Slides for Java提供的默認選項將PowerPoint演示文稿轉換為PDF的簡單步驟。
以下代碼示例顯示如何使用默認選項將Java中的PPTX轉換為PDF。
// Instantiate a Presentation object that represents a presentation file Presentation pres = new Presentation("presentation.pptx"); // Save the presentation to PDF with default options pres.save("output.pdf", SaveFormat.Pdf);
Aspose.Slides for Java提供了PdfOptions類,可自定義PowerPoint到PDF的轉換。PdfOptions類使您可以指定JPEG質量,定義圖元文件的行為,設置文本壓縮級別,PDF遵從級別以及其他選項。以下是使用自定義選項將PPT / PPTX轉換為PDF的步驟。
下面的代碼示例演示如何使用自定義選項將PowerPoint PPTX轉換為Java中的PDF。
// Instantiate a Presentation object that represents a presentation file Presentation pres = new Presentation("presentation.pptx"); // Instantiate the PdfOptions class PdfOptions opts = new PdfOptions(); // Set JPEG Quality opts.setJpegQuality((byte) 90); // Define behavior for Metafiles opts.setSaveMetafilesAsPng(true); // Set Text Compression level opts.setTextCompression(PdfTextCompression.Flate); // Define the PDF standard opts.setCompliance(PdfCompliance.Pdf15); INotesCommentsLayoutingOptions options = opts.getNotesCommentsLayouting(); options.setNotesPosition(NotesPositions.BottomFull); // Save the presentation to PDF with specified options pres.save("output.pdf", SaveFormat.Pdf, opts);
PowerPoint演示文稿包含隱藏的幻燈片時,可能會出現這種情況。在默認的PowerPoint到PDF轉換中,Aspose.Slides for Java將忽略隱藏的幻燈片。但是,如果要在轉換后的PDF中包含隱藏的幻燈片,則可以使用PdfOptions.setShowHiddenSlides(true)選項。
下面的代碼示例演示如何將PowerPoint PPTX轉換為PDF,包括Java中的隱藏幻燈片。
Presentation pres = new Presentation("presentation.pptx"); try { // Instantiate the PdfOptions class PdfOptions pdfOptions = new PdfOptions(); // Specify that the generated document should include hidden slides pdfOptions.setShowHiddenSlides(true); // Save the presentation to PDF with specified options pres.save("output.pdf", SaveFormat.Pdf, pdfOptions); } finally { if (pres != null) pres.dispose(); }
Aspose.Slides for Java還允許選擇要包含在生成的PDF文檔中的幻燈片。可以創建一個數組以指定要包含在PPTX到PDF轉換中的幻燈片編號,并將其傳遞給save()方法。
下面的代碼示例演示如何在Java中將PowerPoint PPTX的特定幻燈片轉換為PDF。
// Instantiate a Presentation object that represents a presentation file Presentation pres = new Presentation("presentation.pptx"); // Setting array of slides positions int[] slides = new int[] { 2, 3, 5 }; // Save the presentation to PDF pres.save("output.pdf", slides, SaveFormat.Pdf);
將PowerPoint演示文稿轉換為受密碼保護的PDF,以保護文檔。可以使用 PdfOptions.setPassword(“ password”)設置密碼 ,并將PdfOptions對象傳遞給save()方法。
下面的代碼示例演示如何將PowerPoint PPTX轉換為Java中受密碼保護的PDF。
// Instantiate a Presentation object that represents a presentation file Presentation pres = new Presentation("demo.pptx"); // Instantiate the PdfOptions class PdfOptions opts = new PdfOptions(); // Setting PDF password opts.setPassword("password"); // Save the presentation to password protected PDF pres.save("output.pdf", SaveFormat.Pdf, opts);
PDF格式允許您指定不同的訪問權限,例如打印權限,添加或修改文本注釋或表單字段的權限等。根據此功能,Aspose.Slides for Java提供了為從PowerPoint演示文稿轉換而來的PDF文檔設置權限的功能。該PdfAccessPermissions類包含你可以在PowerPoint演示文稿應用到PDF轉換不同的權限類型的標志集合。
下面的Java代碼示例演示如何將具有訪問權限的PowerPoint演示文稿轉換為PDF。
// Create PDF options PdfOptions pdfOptions = new PdfOptions(); // Set password pdfOptions.setPassword("my_password"); // Set access permissions pdfOptions.setAccessPermissions(PdfAccessPermissions.PrintDocument| PdfAccessPermissions.HighQualityPrint); // Load PowerPoint presentation Presentation presentation = new Presentation("Presentation.pptx"); try { presentation.save("output.pdf", SaveFormat.Pdf, pdfOptions); } finally { if (presentation != null) presentation.dispose(); }
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn