Add Text to PDF using Go
Contents
[
Hide
]
To add text to existing PDF file:
- Open a PDF file.
- Add the text to the PDF document with PageAddText function.
- Saves the modifications to the same file.
Adding Text
The following code snippet shows you how to add text in an existing PDF 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)
}
// 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()
}