Table of Contents

Class TokenWriter

Namespace
UglyToad.PdfPig.Writer
Assembly
UglyToad.PdfPig.dll

Writes any type of IToken to the corresponding PDF document format output.

public class TokenWriter : ITokenWriter
Inheritance
TokenWriter
Implements
Inherited Members

Constructors

TokenWriter()

public TokenWriter()

Fields

StreamEnd

Bytes that indicate end start of stream

protected static readonly byte[] StreamEnd

Field Value

byte[]

StreamStart

Bytes that indicate start of stream

protected static readonly byte[] StreamStart

Field Value

byte[]

Properties

Instance

Single global instance

public static TokenWriter Instance { get; }

Property Value

TokenWriter

Methods

WriteArray(ArrayToken, Stream)

Write an array to the output stream, with whitespace at the end.

protected void WriteArray(ArrayToken array, Stream outputStream)

Parameters

array ArrayToken
outputStream Stream

WriteBoolean(BooleanToken, Stream)

Write a boolean "true" or "false" to the output stream, with whitespace at the end.

protected void WriteBoolean(BooleanToken boolean, Stream outputStream)

Parameters

boolean BooleanToken
outputStream Stream

WriteComment(CommentToken, Stream)

Write a "%comment" in the output stream, with a line break at the end.

protected void WriteComment(CommentToken comment, Stream outputStream)

Parameters

comment CommentToken
outputStream Stream

WriteCrossReferenceTable(IReadOnlyDictionary<IndirectReference, long>, IndirectReference, Stream, IndirectReference?)

public void WriteCrossReferenceTable(IReadOnlyDictionary<IndirectReference, long> objectOffsets, IndirectReference catalogToken, Stream outputStream, IndirectReference? documentInformationReference)

Parameters

objectOffsets IReadOnlyDictionary<IndirectReference, long>
catalogToken IndirectReference
outputStream Stream
documentInformationReference IndirectReference?

WriteDictionary(DictionaryToken, Stream)

Writes dictionary key/value pairs to output stream as Name/Token pairs.

protected void WriteDictionary(DictionaryToken dictionary, Stream outputStream)

Parameters

dictionary DictionaryToken
outputStream Stream

WriteHex(HexToken, Stream)

Write a hex value to the output stream

protected void WriteHex(HexToken hex, Stream stream)

Parameters

hex HexToken
stream Stream

WriteIndirectReference(IndirectReferenceToken, Stream)

Write an indirect reference to the stream, with whitespace at the end.

protected virtual void WriteIndirectReference(IndirectReferenceToken reference, Stream outputStream)

Parameters

reference IndirectReferenceToken
outputStream Stream

WriteInt(int, Stream)

Write an integer to the stream

protected virtual void WriteInt(int value, Stream outputStream)

Parameters

value int
outputStream Stream

WriteLineBreak(Stream)

Write a line break to the output stream

protected virtual void WriteLineBreak(Stream outputStream)

Parameters

outputStream Stream

WriteLong(long, Stream)

Write a long to the stream

protected virtual void WriteLong(long value, Stream outputStream)

Parameters

value long
outputStream Stream

WriteName(NameToken, Stream)

Write a name to the stream, with whitespace at the end.

protected virtual void WriteName(NameToken name, Stream outputStream)

Parameters

name NameToken
outputStream Stream

WriteNumber(NumericToken, Stream)

Write a number to the stream, with whitespace at the end.

protected virtual void WriteNumber(NumericToken number, Stream outputStream)

Parameters

number NumericToken
outputStream Stream

WriteObject(long, int, byte[], Stream)

public void WriteObject(long objectNumber, int generation, byte[] data, Stream outputStream)

Parameters

objectNumber long
generation int
data byte[]
outputStream Stream

WriteObject(ObjectToken, Stream)

Write an object to the stream, with a line break at the end. It writes the following contents:

  • "[ObjectNumber] [Generation] obj"
  • Object data
  • "endobj"
protected virtual void WriteObject(ObjectToken objectToken, Stream outputStream)

Parameters

objectToken ObjectToken
outputStream Stream

WriteStream(StreamToken, Stream)

Write a stream token to the output stream, with the following contents:

  • Dictionary specifying the length of the stream, any applied compression filters and additional information.
  • Stream start indicator
  • Bytes in the StreamToken data
  • Stream end indicator
protected virtual void WriteStream(StreamToken streamToken, Stream outputStream)

Parameters

streamToken StreamToken
outputStream Stream

WriteString(StringToken, Stream)

Write string to the stream, with whitespace at the end

protected virtual void WriteString(StringToken stringToken, Stream outputStream)

Parameters

stringToken StringToken
outputStream Stream

WriteToken(IToken, Stream)

Writes the given input token to the output stream with the correct PDF format and encoding including whitespace and line breaks as applicable.

public void WriteToken(IToken token, Stream outputStream)

Parameters

token IToken

The token to write to the stream.

outputStream Stream

The stream to write the token to.

WriteWhitespace(Stream)

Write a space to the output stream

protected virtual void WriteWhitespace(Stream outputStream)

Parameters

outputStream Stream