PowerPoint 到 PDF C++

許多組織在會議或其他小組討論場景中使用 PowerPoint 演示文稿。在某些情況下,您可能需要與其他人共享相同的信息。在這種情況下,您可以選擇 PPTXPDF 格式。如果文件僅用於演示,則可以使用 PPTX 文件格式。但是,如果出於信息目的共享文件,那麼 PDF 格式是更好且用戶友好的選擇。在本文中,您將學習如何使用 C++ 將 PowerPoint 幻燈片轉換為 PDF 格式。

用於 PowerPoint 到 PDF 轉換的 C++ API

Aspose.Slides for C++ 是一個 C++ 庫,用於在不使用 Microsoft PowerPoint 的情況下創建和閱讀 PowerPoint 文檔。此外,它還支持將 PowerPoint 文件轉換為 PDF 格式。您可以通過 NuGet 安裝 API 或直接從 下載 部分下載。

PM> Install-Package Aspose.Slides.Cpp

使用 C++ 將 PowerPoint 轉換為 PDF

以下是將 PowerPoint 演示文稿轉換為 PDF 格式的步驟。

以下是使用 C++ 將 PowerPoint 演示文稿轉換為 PDF 的示例代碼。

// 源文件和輸出文件的路徑。
const String sourceFilePath = u"SourceDirectory\\SampleSlides.pptx";
const String outputFilePath = u"OutputDirectory\\ConvertToPDF_out.pdf";

// 實例化表示 PPTX 文件的 Presentation 類
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);

// 將演示文稿另存為 PDF
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pdf);

使用其他選項將 PowerPoint 轉換為 PDF

Aspose.Slides for C++提供了PdfOptions類來自定義PowerPoint演示文稿到PDF格式的轉換。以下是 PdfOptions 類提供的一些選項。

以下是使用其他選項將 PowerPoint 演示文稿轉換為 PDF 格式的步驟。

以下是使用其他選項將 PowerPoint 轉換為 PDF 的示例代碼。

// 源文件和輸出文件的路徑。
const String sourceFilePath = u"SourceDirectory\\SampleSlides.pptx";
const String outputFilePath = u"OutputDirectory\\ConvertToPDFWithAdditionalOptions_out.pdf";

// 實例化表示 PPTX 文件的 Presentation 類
SharedPtr<Presentation> presentation = MakeObject<Presentation>(sourceFilePath);

// 實例化 PdfOptions 類
SharedPtr<Aspose::Slides::Export::PdfOptions> pdfOptions = MakeObject <Aspose::Slides::Export::PdfOptions>();

// 在 PDF 中顯示隱藏的幻燈片
pdfOptions->set_ShowHiddenSlides(true);

// 設置 JPEG 質量
pdfOptions->set_JpegQuality(90);

// 設置文本壓縮級別
pdfOptions->set_TextCompression(PdfTextCompression::Flate);

// 定義 PDF 標準
pdfOptions->set_Compliance(PdfCompliance::Pdf15);

// 將演示文稿另存為 PDF
presentation->Save(outputFilePath, Aspose::Slides::Export::SaveFormat::Pdf, pdfOptions);

獲得免費許可證

您可以通過申請 免費的臨時許可證 來試用沒有評估限制的 API。

結論

在本文中,您學習瞭如何使用 C++ 以編程方式將 PowerPoint 演示文稿轉換為 PDF 格式。此外,您還學習瞭如何使用 Aspose.Slides for C++ API 自定義 PowerPoint 到 PDF 文件的轉換。 API 提供了許多附加功能,您可以使用 官方文檔 詳細探索這些功能。如果您有任何疑問,請隨時在論壇上與我們聯繫。

也可以看看

提示:由 Aspose.Slides 提供支持的 PowerPoint 到 PDF 的轉換過程已在 Aspose 的免費在線 PowerPoint 到 PDF 轉換器 中實現。