HTML JPG PDF XML DOCX
  Product Family
PDF

Recortar PDF no .NET SDK

API para trabalhar com redimensionamento de documentos PDF usando .NET.

Get Started

Como recortar PDF via Cloud .NET SDK

Para recortar documentos PDF, usaremos Aspose.PDF Cloud .NET SDK Este Cloud SDK permite que você construa facilmente aplicativos de criação, edição e conversão de PDF baseados em nuvem em C#, ASP.NET ou outras linguagens .NET para várias plataformas de nuvem. Abra NuGet gerenciador de pacotes, procure por Aspose.PDF Cloud e instale. Você também pode usar o seguinte comando no Console do Gerenciador de Pacotes.

Comando do Console do Gerenciador de Pacotes


    PM> Install-Package Aspose.Pdf-Cloud
     

Etapas para recortar PDF usando .NET SDK

Desenvolvedores Aspose.PDF Cloud podem facilmente carregar e recortar PDF em apenas algumas linhas de código.

  1. Carregue o Arquivo PDF na Nuvem.
  2. Obtenha as Informações da Página.
  3. Extraia a Página como uma Imagem.
  4. Crie um Novo Documento PDF Vazio.
  5. Insira a Imagem no Novo PDF.
  6. Baixe o PDF Final Recortado.
 

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_");
                    }
                }
            }
        }
    }