HTML JPG PDF XML DOCX
  Product Family
PDF

Resize PDF in Go SDK

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

Get Started

How to resize PDF via Cloud Go SDK

To resize 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 resize PDF via Go

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

  1. Uploads the PDF.
  2. Converts it to HTML (retaining structure/content).
  3. Converts the HTML back to a new PDF with the specified dimensions.
  4. Downloads the resized document.
 

Resize PDF using Cloud Go SDK


    package main

    import (
        "fmt"
        "path/filepath"

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

    func resizeAllPages(pdf_api *asposepdfcloud.PdfApiService, document_name string, htmlTempDoc string, width int, height int, outputDocument string, localFolder string, tempFolder string) {
        uploadFile(pdf_api, document_name)

        htmlTempPath := filepath.Join(tempFolder, htmlTempDoc)

        args := map[string]interface{}{
            "folder":       tempFolder,
            "documentType": string(asposepdfcloud.HtmlDocumentTypeXhtml),
            "outputFormat": string(asposepdfcloud.OutputFormatFolder),
        }

        _, response, err := pdf_api.PutPdfInStorageToHtml(document_name, htmlTempPath, args)

        if err != nil {
            fmt.Println(err.Error())
        } else if response.StatusCode < 200 || response.StatusCode > 299 {
            fmt.Println("resizePages(): Can't convert pdf to html!")
        } else {
            fmt.Println("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")
        }

        args2 := map[string]interface{}{
            "dstFolder":    tempFolder,
            "htmlFileName": htmlTempDoc,
            "height":       float64(height),
            "width":        float64(width),
        }

        _, response, err = pdf_api.PutHtmlInStorageToPdf(outputDocument, htmlTempPath, args2)
        if err != nil {
            fmt.Println(err.Error())
        } else if response.StatusCode < 200 || response.StatusCode > 299 {
            fmt.Println("resizePages(): Can't convert html to pdf!")
        } else {
            fmt.Println("resizePages(): Pages successfully resized.")
            downloadFile(pdf_api, outputDocument, "resized_doc_")
        }
    }
 

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.

  •