public class

ElementWriter

extends Object
implements __Delete AutoCloseable
java.lang.Object
   ↳ com.pdftron.pdf.ElementWriter

Class Overview

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.

Summary

Constants
int e_overlay The Constant e_overlay.
int e_replacement The Constant e_replacement.
int e_underlay Enumeration describing the placement of the element written to a page.
Public Constructors
ElementWriter()
Instantiates a new element writer.
Public Methods
void begin(Page page, int write_mode, boolean page_coord_sys)
Begin writing to the given page.
void begin(Doc doc)
Begin writing an Element sequence to a new stream.
void begin(Obj streamobj_to_update)
Begin writing an Element sequence to a stream.
void begin(Page page)
Begin writing to the given page.
void begin(Page page, int write_mode)
Begin writing to the given page.
void begin(Obj streamobj_to_update, boolean compress)
Begin writing an Element sequence to a stream.
void begin(Page page, int write_mode, boolean page_coord_sys, boolean compress)
Begin writing to the given page.
void begin(Obj streamobj_to_update, boolean compress, Obj resources)
Begin writing an Element sequence to a stream.
void begin(Page page, int write_mode, boolean page_coord_sys, boolean compress, Obj resources)
Begin writing to the given page.
void begin(Doc doc, boolean compress)
Begin writing an Element sequence to a new stream.
void close()
Frees the native memory of the object.
void destroy()
Frees the native memory of the object.
Obj end()
Finish writing to a page.
void flush()
The Flush method flushes all pending Element writing operations.
void setDefaultGState(ElementReader reader)
Initializes ElementWriter state with the state of a given ElementReader.
void writeBuffer(byte[] data)
Writes an arbitrary buffer to the content stream.
void writeElement(Element element)
Writes the Element to the content stream.
void writeGStateChanges(Element element)
Write only the graphics state changes applied to this element and skip writing the element itself.
void writePlacedElement(Element element)
A utility function that surrounds the given Element with a graphics state Save/Restore Element (i.e.
void writeString(String str)
Writes an arbitrary string to the content stream.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.pdftron.pdf.__Delete
From interface java.lang.AutoCloseable

Constants

public static final int e_overlay

The Constant e_overlay.

Constant Value: 1 (0x00000001)

public static final int e_replacement

The Constant e_replacement.

Constant Value: 2 (0x00000002)

public static final int e_underlay

Enumeration describing the placement of the element written to a page.

Constant Value: 0 (0x00000000)

Public Constructors

public ElementWriter ()

Instantiates a new element writer.

Public Methods

public void begin (Page page, int write_mode, boolean page_coord_sys)

Begin writing to the given page.

Parameters
page The page to write content.
write_mode the write mode
page_coord_sys 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).

public void begin (Doc doc)

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.

Note: the newly created content stream object is returned when writing operations are completed (i.e. after the call to ElementWriter::End()).

Parameters
doc - 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.

public void begin (Obj streamobj_to_update)

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
streamobj_to_update A low-level SDF stream object that will contain the new stream. Old stream inside that object will be discarded.

public void begin (Page page)

Begin writing to the given page. By default, new content will be appended to the page, as foreground graphics.

Parameters
page The page to write content.

public void begin (Page page, int write_mode)

Begin writing to the given page.

Parameters
page The page to write content.
write_mode the write mode

public void begin (Obj streamobj_to_update, boolean compress)

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
streamobj_to_update A low-level SDF stream object that will contain the new stream. Old stream inside that object will be discarded.
compress 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 file

public void begin (Page page, int write_mode, boolean page_coord_sys, boolean compress)

Begin writing to the given page.

Parameters
page The page to write content.
write_mode the write mode
page_coord_sys 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 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.

public void begin (Obj streamobj_to_update, boolean compress, Obj 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
streamobj_to_update A low-level SDF stream object that will contain the new stream. Old stream inside that object will be discarded.
compress 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 file
resources the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created.

public void begin (Page page, int write_mode, boolean page_coord_sys, boolean compress, Obj resources)

Begin writing to the given page.

Parameters
page The page to write content.
write_mode the write mode
page_coord_sys 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 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 the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created.

public void begin (Doc doc, boolean compress)

Begin writing an Element sequence to a new stream.

Parameters
doc the document that will contain the new stream.
compress 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.

public void close ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public void destroy ()

Frees the native memory of the object. This can be explicity called to control the deallocation of native memory and avoid situations where the garbage collector does not free the object in a timely manner.

public Obj end ()

Finish writing to a page.

Returns
  • A low-level stream object that was used to store Elements.

public void 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.

public void setDefaultGState (ElementReader reader)

Initializes ElementWriter state with the state of a given ElementReader. This can be used to avoid incorrectly writing inherited GState attributes.

Parameters
reader the ElementReader

public void writeBuffer (byte[] data)

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
data the data

public void writeElement (Element element)

Writes the Element to the content stream.

Parameters
element the element to be written to the content stream

public void writeGStateChanges (Element 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
element The element for which to write graphics state changes.

public void writePlacedElement (Element 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
element the element

public void writeString (String str)

Writes an arbitrary string to the content stream. Serves the same purpose as WriteBuffer().

Parameters
str the str