Work with Pages in PDF using Go

Manage PDF pages in document programmaticaly using Aspose.PDF for Go via C++ Library

Aspose.PDF for Go via C++ Logo

Most popular action with Pages in Go

How to Insert pages to PDF Document using Go

In order to add page in PDF file, we’ll use Aspose.PDF API which is a feature-rich, powerful and easy to use document manipulation API for go-cpp platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Add Page to PDF using Go


You need Aspose.PDF library to try the code in your environment.

  1. Create a Document object with the input PDF file.

  2. Call the PageCollection collection’s Insert method with specified index.

  3. Save the output PDF using the Save method.

Add New Page to PDF


    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)
        }
        // PageAdd() adds new page in PDF-document
        err = pdf.PageAdd()
        if err != nil {
            log.Fatal(err)
        }
        // Save() saves previously opened PDF-document
        err = pdf.Save()
        if err != nil {
            log.Fatal(err)
        }
        // Close() releases allocated resources for PDF-document
        defer pdf.Close()
    }