Compress PDF using Go

PDF compression programmatically using Aspose.PDF for Go via C++

Optimize PDF with Go

Do you need to compress the PDF? Programmatic modification of PDF documents is an essential part of modern digital workflows. Go libraries like Aspose.PDF – are stand-alone solutions that don’t rely on other software and are ready for commercial use. To compress PDF files, we’ll use Aspose.PDF for Go via C++, which is an easy and secure toolkit used to work with PDF. To install and use Aspose.PDF for Go via C++, click on Download Aspose.PDF for Go.

How to Compress PDF using Go


You need Aspose.PDF for Go via C++ to try the code in your environment.

  1. Open a PDF document using Document object.
  2. Call the method for optimization on the document object, which removes unnecessary objects and compresses images in the PDF file
  3. Save the optimized document to the new path using the Save() method.

If you want to make it easier and faster to share or store a PDF file, compressing it can help. With this powerful Aspose.PDF Go via C++ library, you can reduce the size of your PDF while keeping its quality and important details intact. This professional tool uses Go to compress PDF effectively. The following example demonstrates how to modify a PDF document in Go:

Compress PDF Files - Go

This sample code shows how to Optimize PDF Document for the Web - Go

Input file:

File not added

Output format:

PDF

Output file:


    package main

    import "github.com/aspose-pdf/aspose-pdf-go-cpp"
    import "log"

    func main() {
      // Open(filename string) opens a PDF-document with filename
      pdf, err := asposepdf.Open("sample.pdf")
      if err != nil {
        log.Fatal(err)
      }
      // Optimize() optimizes PDF-document content
      err = pdf.Optimize()
      if err != nil {
        log.Fatal(err)
      }
      // SaveAs(filename string) saves previously opened PDF-document with new filename
      err = pdf.SaveAs("sample_Optimize.pdf")
      if err != nil {
        log.Fatal(err)
      }
      // Close() releases allocated resources for PDF-document
      defer pdf.Close()
    }

About Aspose.PDF for Go via C++ API

The Aspose.PDF for Go via C++ is a powerful toolkit that allows developers to manipulate PDF files directly and helps do various tasks for PDF. Contains unique features for converting PDF to other formats.

You can find more information about Aspose.PDF for Go via C++ API on Documentation and examples on how to use tool.