Set the background color for PDF with Go via C++

Contents
[ ]
  1. The provided code snippet demonstrates how to set a background color for a PDF file using the Aspose.PDF library in Go.
  2. The Open method loads the specified PDF file into memory, allowing further manipulations, such as modifying its appearance or content.
  3. The SetBackground method applies a new background color to the PDF document. The RGB values allow users to customize the document’s visual style.
  4. The SaveAs method saves the updated PDF under a new name.

This code is ideal for applications that need to automate PDF customizations, such as creating branded reports, adding watermarks, or enhancing visual consistency across multiple documents.


    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)
      }
      // SetBackground(r, g, b int32) sets PDF-document background color
      err = pdf.SetBackground(200, 100, 101)
      if err != nil {
        log.Fatal(err)
      }
      // SaveAs(filename string) saves previously opened PDF-document with new filename
      err = pdf.SaveAs("sample_SetBackground.pdf")
      if err != nil {
        log.Fatal(err)
      }
      // Close() releases allocated resources for PDF-document
      defer pdf.Close()
    }