diff --git a/src/UglyToad.PdfPig/Writer/ITokenWriter.cs b/src/UglyToad.PdfPig/Writer/ITokenWriter.cs
index ea851127..1445f1e4 100644
--- a/src/UglyToad.PdfPig/Writer/ITokenWriter.cs
+++ b/src/UglyToad.PdfPig/Writer/ITokenWriter.cs
@@ -1,5 +1,7 @@
namespace UglyToad.PdfPig.Writer;
+using Core;
+using System.Collections.Generic;
using System.IO;
using Tokens;
@@ -14,4 +16,22 @@ public interface ITokenWriter
/// The token to write to the stream.
/// The stream to write the token to.
void WriteToken(IToken token, Stream outputStream);
+
+ ///
+ /// Writes pre-serialized token as an object token to the output stream.
+ ///
+ /// Object number of the indirect object.
+ /// Generation of the indirect object.
+ /// Pre-serialized object contents.
+ /// The stream to write the token to.
+ void WriteObject(long objectNumber, int generation, byte[] data, Stream outputStream);
+
+ ///
+ /// Writes a valid single section cross-reference (xref) table plus trailer dictionary to the output for the set of object offsets.
+ ///
+ /// The byte offset from the start of the document for each object in the document.
+ /// The object representing the catalog dictionary which is referenced from the trailer dictionary.
+ /// The output stream to write to.
+ /// The object reference for the document information dictionary if present.
+ void WriteCrossReferenceTable(IReadOnlyDictionary objectOffsets, IndirectReference catalogToken, Stream outputStream, IndirectReference? documentInformationReference);
}
\ No newline at end of file
diff --git a/src/UglyToad.PdfPig/Writer/PdfDedupStreamWriter.cs b/src/UglyToad.PdfPig/Writer/PdfDedupStreamWriter.cs
index 0d1cb1af..bd547b89 100644
--- a/src/UglyToad.PdfPig/Writer/PdfDedupStreamWriter.cs
+++ b/src/UglyToad.PdfPig/Writer/PdfDedupStreamWriter.cs
@@ -8,7 +8,7 @@
{
private readonly Dictionary hashes = new Dictionary(new FNVByteComparison());
- public PdfDedupStreamWriter(Stream stream, bool dispose) : base(stream, dispose)
+ public PdfDedupStreamWriter(Stream stream, bool dispose, ITokenWriter tokenWriter = null) : base(stream, dispose, tokenWriter)
{
}
diff --git a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs
index 039223bf..56b102a3 100644
--- a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs
+++ b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs
@@ -3,7 +3,6 @@ namespace UglyToad.PdfPig.Writer
{
using System;
using System.Collections.Generic;
- using System.Diagnostics;
using System.IO;
using System.Linq;
using Content;
@@ -27,7 +26,7 @@ namespace UglyToad.PdfPig.Writer
private readonly Dictionary pages = new Dictionary();
private readonly Dictionary fonts = new Dictionary();
private bool completed = false;
- internal int fontId = 0;
+ private int fontId = 0;
private readonly static ArrayToken DefaultProcSet = new ArrayToken(new List
{
@@ -90,20 +89,21 @@ namespace UglyToad.PdfPig.Writer
/// If stream should be disposed when builder is.
/// Type of pdf stream writer to use
/// Pdf version to use in header.
- public PdfDocumentBuilder(Stream stream, bool disposeStream = false, PdfWriterType type = PdfWriterType.Default, decimal version = 1.7m)
+ /// Token writer to use
+ public PdfDocumentBuilder(Stream stream, bool disposeStream = false, PdfWriterType type = PdfWriterType.Default, decimal version = 1.7m, ITokenWriter tokenWriter = null)
{
switch (type)
{
case PdfWriterType.ObjectInMemoryDedup:
- context = new PdfDedupStreamWriter(stream, disposeStream);
+ context = new PdfDedupStreamWriter(stream, disposeStream, tokenWriter);
break;
default:
- context = new PdfStreamWriter(stream, disposeStream);
+ context = new PdfStreamWriter(stream, disposeStream, tokenWriter);
break;
}
context.InitializePdf(version);
}
-
+
///
/// Determines whether the bytes of the TrueType font file provided can be used in a PDF document.
///
diff --git a/src/UglyToad.PdfPig/Writer/PdfStreamWriter.cs b/src/UglyToad.PdfPig/Writer/PdfStreamWriter.cs
index 364a57ef..0f0e6f7f 100644
--- a/src/UglyToad.PdfPig/Writer/PdfStreamWriter.cs
+++ b/src/UglyToad.PdfPig/Writer/PdfStreamWriter.cs
@@ -18,17 +18,17 @@
protected bool DisposeStream { get; set; }
protected bool Initialized { get; set; }
protected int CurrentNumber { get; set; } = 1;
- protected readonly static TokenWriter TokenWriter = new TokenWriter();
+ protected readonly ITokenWriter TokenWriter;
- internal PdfStreamWriter(Stream baseStream, bool disposeStream = true)
+ internal PdfStreamWriter(Stream baseStream, bool disposeStream = true, ITokenWriter tokenWriter = null)
{
Stream = baseStream ?? throw new ArgumentNullException(nameof(baseStream));
if (!baseStream.CanWrite)
{
throw new ArgumentException("Output stream must be writable");
}
-
DisposeStream = disposeStream;
+ TokenWriter = tokenWriter ?? new TokenWriter();
}
public Stream Stream { get; protected set; }
diff --git a/src/UglyToad.PdfPig/Writer/TokenWriter.cs b/src/UglyToad.PdfPig/Writer/TokenWriter.cs
index 50cbb2ef..05cac5b2 100644
--- a/src/UglyToad.PdfPig/Writer/TokenWriter.cs
+++ b/src/UglyToad.PdfPig/Writer/TokenWriter.cs
@@ -135,14 +135,8 @@
}
}
- ///
- /// Writes a valid single section cross-reference (xref) table plus trailer dictionary to the output for the set of object offsets.
- ///
- /// The byte offset from the start of the document for each object in the document.
- /// The object representing the catalog dictionary which is referenced from the trailer dictionary.
- /// The output stream to write to.
- /// The object reference for the document information dictionary if present.
- internal void WriteCrossReferenceTable(IReadOnlyDictionary objectOffsets,
+ ///
+ public void WriteCrossReferenceTable(IReadOnlyDictionary objectOffsets,
IndirectReference catalogToken,
Stream outputStream,
IndirectReference? documentInformationReference)
@@ -277,14 +271,8 @@
outputStream.Write(Eof, 0, Eof.Length);
}
- ///
- /// Writes pre-serialized token as an object token to the output stream.
- ///
- /// Object number of the indirect object.
- /// Generation of the indirect object.
- /// Pre-serialized object contents.
- /// The stream to write the token to.
- internal void WriteObject(long objectNumber, int generation, byte[] data, Stream outputStream)
+ ///
+ public void WriteObject(long objectNumber, int generation, byte[] data, Stream outputStream)
{
WriteLong(objectNumber, outputStream);
WriteWhitespace(outputStream);