تغيير أحجام الصفحات في ملف PDF

تفاصيل التنفيذ

PdfPageEditor class in Aspose.Pdf.Facades namespace contains a property named PageSize which can be used to change the page size of an individual page or multiple pages at once. The Pages property can be used to assign the numbers of the pages on which the new page size needs to be applied. PageSize class contains a list of different page sizes as its members. Any of the members of this class can be assigned to PageSize property of the PdfPageEditor class. You can also get page size of any page using GetPageSize method and passing the page number.

–> يمكن ترجمة الفقرة أعلاه إلى العربية كالتالي:

فئة PdfPageEditor في فضاء الأسماء Aspose.Pdf.Facades تحتوي على خاصية باسم PageSize والتي يمكن استخدامها لتغيير حجم صفحة فردية أو عدة صفحات دفعة واحدة. يمكن استخدام خاصية Pages لتعيين أرقام الصفحات التي سيتم تطبيق الحجم الجديد عليها. تحتوي فئة PageSize على قائمة بأحجام الصفحات المختلفة كأعضائها. يمكن تعيين أي من أعضاء هذه الفئة إلى خاصية PageSize لفئة PdfPageEditor. يمكنك أيضاً الحصول على حجم أي صفحة باستخدام طريقة 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}");
    }
}