Add Text to PDF using Go

Add text to PDF document with Go via C++. Use Aspose.PDF to modify PDF documents programmatically

How to Work with Text in PDF using Go Library

Do you need to add Text into PDF File? 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 add text into 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.

Add Text to PDF File via Go


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

  1. Load the PDF with an instance of Document.
  2. Create a TextParagraph and define its properties.
  3. Add the TextParagraph to Page using TextBuilder.
  4. Save the file again.

Add Text to PDF - Go

This sample code shows how to add text into PDF document - Go


    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)
        }
        // PageAddText(num int32, addText string) adds text on page
        err = pdf.PageAddText(1, "added text")
        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()
    }