PDFの個々のページの編集

説明

PdfPageEditorクラスは、PdfFileEditorおよびPdfContentEditorクラスとは異なります。まず、違いを理解する必要があり、その後、PdfPageEditorクラスをよりよく理解できるようになります。PdfFileEditorクラスは、ページの追加、削除、結合など、ファイル内のすべてのページを操作することを可能にします。一方、PdfContentEditorクラスは、ページの内容、すなわちテキストやその他のオブジェクトを操作するのに役立ちます。対照的に、PdfPageEditorクラスは、ページの回転、ズーム、整列など、個々のページ自体のみを操作します。

このクラスが提供する機能は、トランジション、整列、表示の3つの主要なカテゴリに分けることができます。以下でこれらのカテゴリについて説明します。

トランジション

このクラスには、トランジションに関連する2つのプロパティ、すなわちTransitionTypeTransitionDurationがあります。TransitionTypeは、プレゼンテーション中に別のページからこのページに移動する際に使用されるトランジションスタイルを指定します。TransitionDurationは、ページの表示時間を指定します。

整列

PdfPageEditorクラスは、水平および垂直の整列の両方をサポートしています。この目的のために、AlignmentVerticalAlignmentの2つのプロパティを提供します。Alignmentプロパティは、内容を水平方向に整列させるために使用されます。Alignmentプロパティは、Center、Left、Rightの3つのオプションを含むAlignmentTypeの値を取ります。VerticalAlignmentプロパティは、Bottom、Center、Topの3つのオプションを含むVerticalAlignmentTypeの値を取ります。

表示

表示カテゴリには、PageSize、Rotation、Zoom、DisplayDurationなどのプロパティを含めることができます。PageSizeプロパティは、ファイル内の個々のページのサイズを指定します。このプロパティは、A0、A1、A2、A3、A4、A5、A6、B5、Letter、Ledger、P11x17などの事前定義されたページサイズをカプセル化するPageSizeオブジェクトを入力として取ります。Rotationプロパティは、個々のページの回転を設定するために使用されます。値は0、90、180、または270を取ることができます。Zoomプロパティは、ページのズーム係数を設定し、浮動小数点値を入力として取ります。このクラスは、ファイル内の個々のページのページサイズとページ回転を取得するためのメソッドも提供します。 上記のメソッドのサンプルは、以下のコードスニペットに示されています。

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

    // Create a new instance of PdfPageEditor class
    using (var pdfPageEditor = new Aspose.Pdf.Facades.PdfPageEditor())
    {
        // Bind PDF document
        pdfPageEditor.BindPdf(dataDir + "FilledForm.pdf");

        // Specify an array of pages which need to be manipulated (pages can be multiple, here we have specified only one page)
        pdfPageEditor.ProcessPages = new int[] { 1 };

        // Alignment related code
        pdfPageEditor.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;

        // Specify transition type for the pages
        pdfPageEditor.TransitionType = 2;
        // Specify transition duration
        pdfPageEditor.TransitionDuration = 5;

        // Display related code

        // Select a page size from the enumeration and assign to property
        pdfPageEditor.PageSize = Aspose.Pdf.PageSize.PageLedger;

        // Assign page rotation
        pdfPageEditor.Rotation = 90;

        // Specify zoom factor for the page
        pdfPageEditor.Zoom = 100;

        // Assign display duration for the page
        pdfPageEditor.DisplayDuration = 5;

        // Fetching methods

        // Methods provided by the class, page rotation specified already
        var rotation = pdfPageEditor.GetPageRotation(1);

        // Already specified page can be fetched
        var pageSize = pdfPageEditor.GetPageSize(1);

        // This method gets the page count
        var totalPages = pdfPageEditor.GetPages();

        // This method changes the origin from (0,0) to specified number
        pdfPageEditor.MovePosition(100, 100);

        // Save PDF document
        pdfPageEditor.Save(dataDir + "EditPdfPages_out.pdf");
    }
}