PDFをPowerPointに変換する .NET

概要

この記事では、C#を使用してPDFをPowerPointに変換する方法を説明します。以下のトピックをカバーしています。

形式: PPTX

形式: PowerPoint

以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。

C# PDFからPowerPointおよびPPTXへの変換

Aspose.PDF for .NETを使用すると、PDFからPPTXへの変換の進捗を追跡できます。

私たちには、PPT/PPTXプレゼンテーションを作成および操作する機能を提供するAPIであるAspose.Slidesがあります。このAPIは、PPT/PPTXファイルをPDF形式に変換する機能も提供します。最近、多くの顧客からPDFをPPTX形式に変換する機能をサポートする要求を受けました。Aspose.PDF for .NETのリリース10.3.0から、PDFドキュメントをPPTX形式に変換する機能を導入しました。この変換中に、PDFファイルの各ページがPPTXファイルの個別のスライドに変換されます。

PDFからPPTXへの変換中に、テキストは選択/更新可能なテキストとしてレンダリングされます。PDFファイルをPPTX形式に変換するには、Aspose.PDFがPptxSaveOptionsというクラスを提供しています。PptxSaveOptionsクラスのオブジェクトは、Document.Save(..) methodの第2引数として渡されます。以下のコードスニペットは、PDFファイルをPPTX形式に変換するプロセスを示しています。

C#とAspose.PDF .NETを使用したPDFからPowerPointへの簡単な変換

PDFをPPTXに変換するには、Aspose.PDF for .NETは以下のコードステップを使用することをお勧めします。

手順: C#でPDFをPowerPointに変換する | 手順: C#でPDFをPPTXに変換する

  1. Documentクラスのインスタンスを作成します。
  2. PptxSaveOptionsクラスのインスタンスを作成します。
  3. DocumentオブジェクトのSaveメソッドを使用して、PDFをPPTXとして保存します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToPPTX()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
    {
        // Instantiate PptxSaveOptions object
        var saveOptions = new Aspose.Pdf.PptxSaveOptions();

        // Save the file in PPTX format
        document.Save(dataDir + "PDFToPPT_out.pptx", saveOptions);
    }
}

スライドを画像として持つPDFからPPTXへの変換

検索可能なPDFを選択可能なテキストの代わりに画像としてPPTXに変換する必要がある場合、Aspose.PDFはその機能をAspose.Pdf.PptxSaveOptionsクラスを介して提供します。これを実現するには、PptxSaveOptionsクラスのプロパティSlidesAsImagesを’true’に設定します。以下のコードサンプルに示すように。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToPPTWithSlidesAsImages()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
    {
        // Instantiate PptxSaveOptions object
        var saveOptions = new Aspose.Pdf.PptxSaveOptions
        {
            SlidesAsImages = true
        };

        // Save the file in PPTX format with slides as images
        document.Save(dataDir + "PDFToPPT_out.pptx", saveOptions);
    }
}

PPTX変換の進捗詳細

Aspose.PDF for .NETは、PDFからPPTXへの変換の進捗を追跡できます。Aspose.Pdf.PptxSaveOptionsクラスは、変換の進捗を追跡するためにカスタムメソッドを指定できるCustomProgressHandlerプロパティを提供します。以下のコードサンプルに示すように。

 // For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ConvertPDFToPPTWithCustomProgressHandler()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "input.pdf"))
    {

        // Instantiate PptxSaveOptions object
        var saveOptions = new Aspose.Pdf.PptxSaveOptions();

        // Specify custom progress handler
        saveOptions.CustomProgressHandler = ShowProgressOnConsole;

        // Save the file in PPTX format with progress tracking
        document.Save(dataDir + "PDFToPPTWithProgressTracking_out.pptx", saveOptions);
    }
}

 // Define the method to handle progress events and display them on the console
private static void ShowProgressOnConsole(Aspose.Pdf.UnifiedSaveOptions.ProgressEventHandlerInfo eventInfo)
{
    switch (eventInfo.EventType)
    {
        case Aspose.Pdf.ProgressEventType.TotalProgress:
            // Display overall progress of the conversion
            Console.WriteLine($"{DateTime.Now.TimeOfDay}  - Conversion progress: {eventInfo.Value}%.");
            break;

        case Aspose.Pdf.ProgressEventType.ResultPageCreated:
            // Display progress of the page layout creation
            Console.WriteLine($"{DateTime.Now.TimeOfDay}  - Result page {eventInfo.Value} of {eventInfo.MaxValue} layout created.");
            break;

        case Aspose.Pdf.ProgressEventType.ResultPageSaved:
            // Display progress of the page being exported
            Console.WriteLine($"{DateTime.Now.TimeOfDay}  - Result page {eventInfo.Value} of {eventInfo.MaxValue} exported.");
            break;

        case Aspose.Pdf.ProgressEventType.SourcePageAnalysed:
            // Display progress of the source page analysis
            Console.WriteLine($"{DateTime.Now.TimeOfDay}  - Source page {eventInfo.Value} of {eventInfo.MaxValue} analyzed.");
            break;

        default:
            break;
    }
}

参照

この記事では、以下のトピックもカバーしています。コードは上記と同じです。

形式: PowerPoint

形式: PPTX