在PDF文件中更改页面尺寸

Contents
[ ]

实现细节

PdfPageEditor 类在 Aspose.Pdf.Facades namespace 中包含一个名为 PageSize 的属性,该属性可用于更改单个页面或多个页面的页面尺寸。Pages 属性可用于指定需要应用新页面尺寸的页面号码。PageSize 类包含一个不同页面尺寸的列表,作为其成员。该类的任何成员都可以分配给 PdfPageEditor 类的 PageSize 属性。您还可以使用 GetPageSize 方法并传递页面号码来获取任意页面的页面尺寸。

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

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

        // Change page size of the selected pages
        pdfPageEditor.ProcessPages = new[] { 1 };

        // Select a predefined page size (LETTER) and assign it
        pdfPageEditor.PageSize = Aspose.Pdf.PageSize.PageLetter;

        // Save the file with the updated page size
        pdfPageEditor.Save(dataDir + "ChangePageSizes_out.pdf");

        // Get and display the page size assigned
        pdfPageEditor.BindPdf(dataDir + "FilledForm.pdf");

        var pageSize = pdfPageEditor.GetPageSize(1);
        Console.WriteLine($"Width: {pageSize.Width}, Height: {pageSize.Height}");
    }
}