Some test text!

Write content

Write page content to PDF in Go

To write page content to a new document.

doc := NewPDFDoc(filename)

// ElementBuilder is used to build new Element objects
builder := NewElementBuilder()

// ElementWriter is used to write Elements to the page
writer := NewElementWriter()

// Start a new page
page = doc.PageCreate(NewRect(0, 0, 612.0, 794.0))

// begin writing to the page

// Create an Image that can be reused multiple times in the document or multiple on the same page.		
img := ImageCreate(doc, imagename)
element := builder.CreateImage(img, NewMatrix2D(100.0, 0.0, 0.0, 100.0, 300.0, 500.0))

// use the same image again (just change its matrix).
gstate := element.GetGState()
gstate.SetTransform(200.0, 0.0, 0.0, 300.0, 50.0, 450.0)

// use the same image again (just change its matrix).
writer.WritePlacedElement(eb.CreateImage(img, 300.0, 600.0, 200.0, -150.0))

// save changes to the current page

// Add the new page to the document sequence

Build, Write, Embed Elements in PDF Pages
Full code sample which illustrates how to use PDFNet page writing API, how to embed fonts and images and how to copy graphical elements from one page to another.

About writing page content

New page content can be added to an existing page or a blank new page using ElementBuilder and ElementWriter. ElementBuilder is used to instantiate one or more Elements that can be written to one or more pages using ElementWriter:

Note that once the Element is instantiated using ElementBuilder, you have full control over its properties and graphics state.

Page content can also come from existing pages. For example, you can use ElementReader to read paths, text, and images from existing pages and copy them to the current page. Note that, along the way, you can fully modify an Element's properties or its graphics state. This is how to perform page content editing. For example, the following copies all Elements from an existing page and changes text color to blue:

doc := NewPDFDoc(filename)
page := doc.GetPage(1)

writer := NewElementWriter()
reader := NewElementReader()
writer.Begin(page, ElementWriterE_replacement, false)

element := reader.Next()     
for element.GetMp_elem().Swigcptr() != 0{ // Read page contents
  etype := element.GetType()
  if etype == ElementE_text {
    // Set all text to blue color.
    gs := element.GetGState()
    cp := NewColorPt(0.0, 0.0, 1.0)
  } else {
  element = reader.Next()


PDF Editor (Programmatic)
Full code sample which strips all images from the page and changes text color to blue.

Get the answers you need: Support

UPCOMING WEBINAR: Live tech update and run-through. October 21 @ 11am PDT