diff --git a/src/UglyToad.PdfPig/Writer/TokenWriter.cs b/src/UglyToad.PdfPig/Writer/TokenWriter.cs
index 058a38494..730257870 100644
--- a/src/UglyToad.PdfPig/Writer/TokenWriter.cs
+++ b/src/UglyToad.PdfPig/Writer/TokenWriter.cs
@@ -94,8 +94,10 @@ public void WriteToken(IToken token, Stream outputStream)
{
if (token == null)
{
- throw new ArgumentNullException(nameof(token));
+ WriteNullToken(outputStream);
+ return;
}
+
switch (token)
{
case ArrayToken array:
@@ -305,8 +307,6 @@ public void WriteObject(long objectNumber, int generation, byte[] data, Stream o
///
/// Write a hex value to the output stream
///
- ///
- ///
protected void WriteHex(HexToken hex, Stream stream)
{
stream.WriteByte(HexStart);
@@ -317,8 +317,6 @@ protected void WriteHex(HexToken hex, Stream stream)
///
/// Write an array to the output stream, with whitespace at the end.
///
- ///
- ///
protected void WriteArray(ArrayToken array, Stream outputStream)
{
outputStream.WriteByte(ArrayStart);
@@ -337,8 +335,6 @@ protected void WriteArray(ArrayToken array, Stream outputStream)
///
/// Write a boolean "true" or "false" to the output stream, with whitespace at the end.
///
- ///
- ///
protected void WriteBoolean(BooleanToken boolean, Stream outputStream)
{
var bytes = boolean.Data ? TrueBytes : FalseBytes;
@@ -349,8 +345,6 @@ protected void WriteBoolean(BooleanToken boolean, Stream outputStream)
///
/// Write a "%comment" in the output stream, with a line break at the end.
///
- ///
- ///
protected void WriteComment(CommentToken comment, Stream outputStream)
{
var bytes = OtherEncodings.StringAsLatin1Bytes(comment.Data);
@@ -359,6 +353,17 @@ protected void WriteComment(CommentToken comment, Stream outputStream)
WriteLineBreak(outputStream);
}
+ ///
+ /// Write "null" in the output stream with a whitespace at the end.
+ ///
+ protected void WriteNullToken(Stream outputStream)
+ {
+ var bytes = OtherEncodings.StringAsLatin1Bytes("null");
+
+ outputStream.Write(bytes, 0, bytes.Length);
+ WriteWhitespace(outputStream);
+ }
+
///
/// Writes dictionary key/value pairs to output stream as Name/Token pairs.
///