HTML JPG PDF XML DOCX
  Product Family
PDF

Recortar PDF en .NET SDK

API para trabajar con la redimensión de documentos PDF utilizando .NET.

Get Started

Cómo recortar PDF a través de Cloud .NET SDK

Para recortar documentos PDF, usaremos Aspose.PDF Cloud .NET SDK Este SDK en la nube le permite crear fácilmente aplicaciones de creación, edición y conversión de PDF basadas en la nube en C#, ASP.NET u otros lenguajes .NET para varias plataformas en la nube. Abra NuGet gestor de paquetes, busque Aspose.PDF Cloud e instale. También puede usar el siguiente comando desde la Consola del Administrador de Paquetes.

Comando de la Consola del Administrador de Paquetes


    PM> Install-Package Aspose.Pdf-Cloud
     

Pasos para recortar PDF usando .NET SDK

Los desarrolladores de Aspose.PDF Cloud pueden cargar y recortar fácilmente PDF en solo unas pocas líneas de código.

  1. Cargue el archivo PDF en la nube.
  2. Obtenga información de la página.
  3. Extraiga la página como una imagen.
  4. Cree un nuevo documento PDF vacío.
  5. Inserte la imagen en el nuevo PDF.
  6. Descargue el PDF recortado final.
 

Recortar PDF usando .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_");
                    }
                }
            }
        }
    }