Class: ElementWriter

PDFNet. ElementWriter


new ElementWriter()

ElementWriter can be used to assemble and write new content to a page, Form XObject, Type3 Glyph stream, pattern stream, or any other content stream.

Extends

Members


<static> WriteMode

Properties:
Name Type Description
e_underlay number
e_overlay number
e_replacement number

Methods


<static> create()

Constructor for an ElementWriter object that can be used to assemble and write new content to a page, Form XObject, pattern stream or any other content stream.
Returns:
A promise that resolves to Returns an ElementWriter object
Type
Promise.<PDFNet.ElementWriter>

begin(doc [, compress])

begin writing an Element sequence to a new stream. Use this function to write Elements to a content stream other than the page. For example, you can create Form XObjects (See Section '4.9 Form XObjects' in PDF Reference for more details) pattern streams, Type3 font glyph streams, etc.
Parameters:
Name Type Argument Description
doc PDFNet.PDFDoc | PDFNet.SDFDoc | PDFNet.FDFDoc A low-level SDF/Cos document that will contain the new stream. You can access low-level document using PDFDoc::GetSDFDoc() or Obj::GetDoc() methods.
compress boolean <optional>
An optional flag indicating whether the page content stream should be compressed. This may be useful for debugging content streams. Also some applications need to do a clear text search on strings in the PDF files. By default, all content streams are compressed.
Returns:
Type
Promise.<void>

beginOnObj(stream_obj_to_update [, compress] [, resources])

begin writing an Element sequence to a stream. Use this function to write Elements to a content stream which will replace an existing content stream in an object passed as a parameter.
Parameters:
Name Type Argument Description
stream_obj_to_update PDFNet.Obj A low-level SDF stream object that will contain the new stream. Old stream inside that object will be discarded.
compress boolean <optional>
An optional flag indicating whether the content stream should be compressed. This may be useful for debugging content streams. Also some applications need to do a clear text search on strings in the PDF files. By default, all content streams are compressed.
resources PDFNet.Obj <optional>
the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created.
Returns:
Type
Promise.<void>

beginOnPage(page [, placement] [, page_coord_sys] [, compress] [, resources])

begin writing to the given page. By default, new content will be appended to the page, as foreground graphics. It is possible to add new page content as background graphics by setting the second parameter in begin method to 'true' (e.g. writer.Begin(page, true)).
Parameters:
Name Type Argument Description
page PDFNet.Page The page to write content.
placement number <optional>
PDFNet.ElementWriter.WriteMode = {
	e_underlay : 0
	e_overlay : 1
	e_replacement : 2
}
An optional flag indicating whether the new content should be added as a foreground or background layer to the existing page. By default, the new content will appear on top of the existing graphics.
page_coord_sys boolean <optional>
An optional flag used to select the target coordinate system if true (default), the coordinates are relative to the lower-left corner of the page, otherwise the coordinates are defined in PDF user coordinate system (which may, or may not coincide with the page coordinates).
compress boolean <optional>
An optional flag indicating whether the page content stream should be compressed. This may be useful for debugging content streams. Also some applications need to do a clear text search on strings in the PDF files. By default, all content streams are compressed.
resources PDFNet.Obj <optional>
the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created.
Returns:
Type
Promise.<void>

destroy()

Destructor
Inherited From:
Returns:
Type
Promise.<void>

end()

Finish writing to a page
Returns:
A promise that resolves to a low-level stream object that was used to store Elements.
Type
Promise.<PDFNet.Obj>

flush()

the Flush method flushes all pending Element writing operations. This method is typically only required to be called when intermixing direct content writing (i.e. WriteBuffer/WriteString) with Element writing.
Returns:
Type
Promise.<void>

setDefaultGState(reader)

This method is used to initialize ElementWriter state with the state of a given ElementReader. This can be used to avoid incorrectly writing inherited GState attributes.
Parameters:
Name Type Description
reader PDFNet.ElementReader ElementReader.
Returns:
Type
Promise.<void>

takeOwnership()

Take the ownership of this object, so that PDFNet.runWithCleanup won't destroy this object.
Inherited From:
Returns:
Type
void

writeBuffer(data, data_sz)

Writes an arbitrary buffer to the content stream. This function can be used to insert comments, inline-image data, and chunks of arbitrary content to the output stream.
Parameters:
Name Type Description
data string
data_sz number
Returns:
Type
Promise.<void>

writeElement(element)

Writes the Element to the content stream.
Parameters:
Name Type Description
element PDFNet.Element The element to write to the content stream.
Returns:
Type
Promise.<void>

writeGStateChanges(element)

Write only the graphics state changes applied to this element and skip writing the element itself. This is especially useful when rewriting page content, but with the intention to skip certain elements.
Parameters:
Name Type Description
element PDFNet.Element The element for which to write graphics state changes.
Returns:
Type
Promise.<void>

writePlacedElement(element)

A utility function that surrounds the given Element with a graphics state Save/Restore Element (i.e. in PDF content stream represented as 'q element Q'). The function is equivalent to calling WriteElement three times: WriteElement(eSave); WriteElement(element); WriteElement(eRestore); where eSave is 'e_group_begin' and eRestore is 'e_group_end' Element The function is useful when XObjects such as Images and Forms are drawn on the page.
Parameters:
Name Type Description
element PDFNet.Element Element object to enact function on.
Returns:
Type
Promise.<void>

writeString(str)

Writes an arbitrary string to the content stream. Serves the same purpose as WriteBuffer().
Parameters:
Name Type Description
str string String to write to the content stream.
Returns:
Type
Promise.<void>