diff --git a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs index 8d8221ce..2269f4e1 100644 --- a/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs +++ b/src/UglyToad.PdfPig/Writer/PdfDocumentBuilder.cs @@ -30,7 +30,7 @@ namespace UglyToad.PdfPig.Writer private readonly Dictionary fonts = new Dictionary(); private readonly Dictionary images = new Dictionary(); private readonly Dictionary unwrittenTokens = new Dictionary(); - + private bool completed = false; internal int fontId = 0; /// @@ -444,7 +444,8 @@ namespace UglyToad.PdfPig.Writer } return dict; } - } + } + private void CompleteDocument() { // write fonts to reserved object numbers @@ -584,6 +585,8 @@ namespace UglyToad.PdfPig.Writer context.CompletePdf(catalogRef, informationReference); + completed = true; + (int Count, IndirectReferenceToken Ref) CreatePageTree(List> pagesNodes, IndirectReferenceToken parent) { // TODO shorten page tree when there is a single or small number of pages left in a branch @@ -807,6 +810,11 @@ namespace UglyToad.PdfPig.Writer /// public void Dispose() { + if (!completed) + { + CompleteDocument(); + } + context.Dispose(); } }