HTML JPG PDF XML DOCX
  Product Family
PDF

Crop PDF in .NET SDK

API for working with resizing PDF documents using .NET.

Get Started

How to crop PDF via Cloud .NET SDK

To crop PDF documents, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Pdf-Cloud
     

Steps to crop PDF using .NET SDK

Aspose.PDF Cloud developers can easily load & crop PDF in just a few lines of code.

  1. Upload the PDF File to Cloud.
  2. Get Page Info.
  3. Extract the Page as an Image.
  4. Create a New Empty PDF Document.
  5. Insert the Image into the New PDF.
  6. Download the Final Cropped PDF.
 

Crop PDF using .NET Cloud SDK


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace ChangeLayout
    {
        public class CropDocumentPage
        {
            private ChangeLayoutHelper _helper;

            public CropDocumentPage(ChangeLayoutHelper helper)
            {
                _helper = helper;
            }

            public async Task MakeCropDocumentPage(string document, string outputDocument, int pageNumber, int llx, int lly, int width, int height)
            {
                await _helper.UploadFile(document);
                await _helper.GetPageInfo(document, pageNumber);
                string imageFile = await _helper.ExtractPdfPage(document, pageNumber, _helper.config.CROP_PAGE_WIDTH, _helper.config.CROP_PAGE_HEIGHT);
                DocumentResponse? newPdf = await _helper.CreatePdfDocument(outputDocument, width, height);
                if (newPdf == null)
                    Console.WriteLine("MakeCropDocumentPage(): Unexpected error - new document is NULL");
                else if (newPdf.Code != 200)
                    Console.WriteLine("MakeCropDocumentPage(): Failed to create new PDF document!");
                else
                {
                    AsposeResponse? response = await _helper.InsertPageAsImage(outputDocument, imageFile, llx, lly);
                    if (response == null)
                        Console.WriteLine("MakeCropDocumentPage(): Unexpected error - insert image return NULL");
                    else if (newPdf.Code != 200)
                        Console.WriteLine("MakeCropDocumentPage(): Failed to insert image to the new PDF document!");
                    else
                    {
                        Console.WriteLine("cropPage(): Page successfully cropped.");
                        await _helper.DownloadFile(outputDocument, "cropped_");
                    }
                }
            }
        }
    }