Class 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.
Implements
Inherited Members
Namespace: pdftron.PDF
Assembly: PDFNet.dll
Syntax
public class ElementWriter : IDisposable
Constructors
ElementWriter()
Instantiates a new element writer.
Declaration
public ElementWriter()
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Methods
Begin(Page)
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)).
Declaration
public void Begin(Page page)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to write content. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Page, WriteMode)
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)).
Declaration
public void Begin(Page page, ElementWriter.WriteMode placement)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to write content. |
ElementWriter.WriteMode | placement | 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. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Page, WriteMode, bool)
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)).
Declaration
public void Begin(Page page, ElementWriter.WriteMode placement, bool page_coord_sys)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to write content. |
ElementWriter.WriteMode | placement | 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. |
bool | 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). |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Page, WriteMode, bool, bool)
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)).
Declaration
public void Begin(Page page, ElementWriter.WriteMode placement, bool page_coord_sys, bool compress)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to write content. |
ElementWriter.WriteMode | placement | 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. |
bool | 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). |
bool | compress | 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. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Page, WriteMode, bool, bool, Obj)
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)).
Declaration
public void Begin(Page page, ElementWriter.WriteMode placement, bool page_coord_sys, bool compress, Obj resources)
Parameters
Type | Name | Description |
---|---|---|
Page | page | The page to write content. |
ElementWriter.WriteMode | placement | 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. |
bool | 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). |
bool | compress | 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. |
Obj | resources | the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Obj, bool)
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.
Declaration
public void Begin(Obj stream_obj_to_update, bool compress)
Parameters
Type | Name | Description |
---|---|---|
Obj | stream_obj_to_update | the streamobj_to_update |
bool | compress | the compress |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(Obj, bool, Obj)
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.
Declaration
public void Begin(Obj stream_obj_to_update, bool compress, Obj resources)
Parameters
Type | Name | Description |
---|---|---|
Obj | stream_obj_to_update | the streamobj_to_update |
bool | compress | the compress |
Obj | resources | the resource dictionary in which to store resources for the final page. By default, a new resource dictionary will be created. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(SDFDoc)
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.
Declaration
public void Begin(SDFDoc doc)
Parameters
Type | Name | Description |
---|---|---|
SDFDoc | doc |
|
Remarks
the newly created content stream object is returned when writing operations are completed (i.e. after the call to ElementWriter::End()).
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Begin(SDFDoc, bool)
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.
Declaration
public void Begin(SDFDoc doc, bool compress)
Parameters
Type | Name | Description |
---|---|---|
SDFDoc | doc | the doc |
bool | compress | the compress |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
Dispose()
Releases all resources used by the ElementWriter
Declaration
public override sealed void Dispose()
Dispose(bool)
Declaration
[HandleProcessCorruptedStateExceptions]
protected virtual void Dispose(bool A_0)
Parameters
Type | Name | Description |
---|---|---|
bool | A_0 |
End()
Finish writing to a page.
Declaration
public Obj End()
Returns
Type | Description |
---|---|
Obj | A low-level stream object that was used to store Elements. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
~ElementWriter()
Declaration
protected ~ElementWriter()
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.
Declaration
public void Flush()
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
SetDefaultGState(ElementReader)
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.
Declaration
public void SetDefaultGState(ElementReader reader)
Parameters
Type | Name | Description |
---|---|---|
ElementReader | reader | the ElementReader |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
WriteBuffer(byte[])
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.
Declaration
public void WriteBuffer(byte[] buf)
Parameters
Type | Name | Description |
---|---|---|
byte[] | buf | the data |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
WriteElement(Element)
Writes the Element to the content stream.
Declaration
public void WriteElement(Element element)
Parameters
Type | Name | Description |
---|---|---|
Element | element | the element |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
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.
Declaration
public void WriteGStateChanges(Element element)
Parameters
Type | Name | Description |
---|---|---|
Element | element | The element for which to write graphics state changes. |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
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.
Declaration
public void WritePlacedElement(Element element)
Parameters
Type | Name | Description |
---|---|---|
Element | element | the element |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |
WriteString(string)
Writes an arbitrary string to the content stream. Serves the same purpose as WriteBuffer().
Declaration
public void WriteString(string data)
Parameters
Type | Name | Description |
---|---|---|
string | data | the str |
Exceptions
Type | Condition |
---|---|
PDFNetException | PDFNetException the PDFNet exception |