HTML JPG PDF XML DOCX
  Product Family
PDF

Crop PDF in Go SDK

API for working with cropping PDF documents using Aspose.PDF Cloud Go SDK

Get Started

How to crop PDF via Cloud Go SDK

To crop PDF documents, we’ll use Aspose.PDF Cloud Go SDK This Cloud Go SDK assists Go programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Go programming language via Aspose.PDF REST API. Use the following command from the Package Manager Console.

Package Manager Console Command


     
    go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25
     
     

Steps to crop PDF via Go

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

  1. Define the cropDocumentPage Function.
  2. Upload the PDF to Cloud Storage.
  3. Get Info About the Target Page.
  4. Extract the Page as an Image.
  5. Insert Extracted Image into the New PDF.
  6. Check Insertion Response and Download the Result.
 

Crop PDF using Cloud Go SDK


    package main

    import (
        "fmt"

        asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
    )

    func cropDocumentPage(pdf_api *asposepdfcloud.PdfApiService, document_name string, pageNumber int, llx int, lly int, width int, height int, outputDocument string, localFolder string, tempFolder string) {
        uploadFile(pdf_api, document_name)

        getPageInfo(pdf_api, document_name, pageNumber, tempFolder)

        imageFile := extractPdfPage(pdf_api, document_name, pageNumber, int(CROP_PAGE_WIDTH), int(CROP_PAGE_HEIGHT), localFolder, tempFolder)
        newPdf := createPdfDocument(pdf_api, outputDocument, width, height, tempFolder)
        if newPdf.Code != 200 {
            fmt.Println("cropPage(): Failed to create new PDF document!")
        } else {
            response := insertPageAsImage(pdf_api, outputDocument, imageFile, llx, lly, tempFolder)
            if response.Code == 200 {
                fmt.Println("cropPage(): Page successfully cropped.")
                downloadFile(pdf_api, outputDocument, "cropped_")
            } else {
                fmt.Println("cropPage(): Can't crop pdf document page!")
            }
        }
    }
 

With our Go SDK you can

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to test the functionality.

  •