翻譯|使用教程|編輯:李顯亮|2020-01-02 10:09:06.477|閱讀 1848 次
概述:在將各種文檔轉(zhuǎn)換為PDF格式的過(guò)程中,PPT到PDF的轉(zhuǎn)換是一種流行的用例,如果您希望在Java中通過(guò)編程的方式將PPT或PPTX轉(zhuǎn)換為PDF,那么你可以認(rèn)真閱讀本文的教程,將演示如何使用 Aspose.Slides for Java API提供的各種選項(xiàng)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
PDF已成為最廣泛和最常用的數(shù)字文檔格式。由于PDF格式具有固定的布局,因此大多數(shù)文檔在共享之前都已轉(zhuǎn)換為PDF。
在將各種文檔轉(zhuǎn)換為PDF格式的過(guò)程中,PPT到PDF的轉(zhuǎn)換是一種流行的用例,且非常的方便省時(shí),特別是當(dāng)必須將大量PowerPoint演示文稿轉(zhuǎn)換為PDF時(shí)。如果您希望在Java中通過(guò)編程的方式將PPT或PPTX轉(zhuǎn)換為PDF,那么你可以認(rèn)真閱讀本文的教程,將演示如何使用 Aspose.Slides for Java API提供的各種選項(xiàng)。
如果您還未使用過(guò)Java版Aspose.Slides,可點(diǎn)擊此處下載最新版體驗(yàn)。
在本文中,我們將介紹使用Aspose.Slides for Java的以下轉(zhuǎn)換方案:
以下是使用Aspose.Slides for Java提供的默認(rèn)選項(xiàng)將PowerPoint演示文稿轉(zhuǎn)換為PDF的簡(jiǎn)單步驟。
以下代碼示例顯示如何使用默認(rèn)選項(xiàng)將Java中的PPTX轉(zhuǎn)換為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類(lèi),可自定義PowerPoint到PDF的轉(zhuǎn)換。PdfOptions類(lèi)使您可以指定JPEG質(zhì)量,定義圖元文件的行為,設(shè)置文本壓縮級(jí)別,PDF遵從級(jí)別以及其他選項(xiàng)。以下是使用自定義選項(xiàng)將PPT / PPTX轉(zhuǎn)換為PDF的步驟。
下面的代碼示例演示如何使用自定義選項(xiàng)將PowerPoint PPTX轉(zhuǎn)換為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演示文稿包含隱藏的幻燈片時(shí),可能會(huì)出現(xiàn)這種情況。在默認(rèn)的PowerPoint到PDF轉(zhuǎn)換中,Aspose.Slides for Java將忽略隱藏的幻燈片。但是,如果要在轉(zhuǎn)換后的PDF中包含隱藏的幻燈片,則可以使用PdfOptions.setShowHiddenSlides(true)選項(xiàng)。
下面的代碼示例演示如何將PowerPoint PPTX轉(zhuǎn)換為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文檔中的幻燈片。可以創(chuàng)建一個(gè)數(shù)組以指定要包含在PPTX到PDF轉(zhuǎn)換中的幻燈片編號(hào),并將其傳遞給save()方法。
下面的代碼示例演示如何在Java中將PowerPoint PPTX的特定幻燈片轉(zhuǎn)換為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演示文稿轉(zhuǎn)換為受密碼保護(hù)的PDF,以保護(hù)文檔。可以使用 PdfOptions.setPassword(“ password”)設(shè)置密碼 ,并將PdfOptions對(duì)象傳遞給save()方法。
下面的代碼示例演示如何將PowerPoint PPTX轉(zhuǎn)換為Java中受密碼保護(hù)的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格式允許您指定不同的訪(fǎng)問(wèn)權(quán)限,例如打印權(quán)限,添加或修改文本注釋或表單字段的權(quán)限等。根據(jù)此功能,Aspose.Slides for Java提供了為從PowerPoint演示文稿轉(zhuǎn)換而來(lái)的PDF文檔設(shè)置權(quán)限的功能。該P(yáng)dfAccessPermissions類(lèi)包含你可以在PowerPoint演示文稿應(yīng)用到PDF轉(zhuǎn)換不同的權(quán)限類(lèi)型的標(biāo)志集合。
下面的Java代碼示例演示如何將具有訪(fǎng)問(wèn)權(quán)限的PowerPoint演示文稿轉(zhuǎn)換為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(); }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn