Add Pages to PDF using Go

Insert pages to PDF document programmatically using Aspose.PDF for Go via C++ Library

How to Add pages to PDF using Go

Do you need to add pages to PDF documents? To add pages, 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.

Insert Page to PDF using Go


You need Aspose.PDF for Go via C++ 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.

Insert 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()
    }