|
4 | 4 | using System;
|
5 | 5 | using System.IO;
|
6 | 6 | using System.Reflection;
|
| 7 | +using System.Threading.Tasks; |
7 | 8 |
|
8 | 9 | namespace Synercoding.FileFormats.Pdf
|
9 | 10 | {
|
@@ -236,47 +237,27 @@ private void _writePdfEnding()
|
236 | 237 | var xRefTable = _tableBuilder.GetXRefTable();
|
237 | 238 | uint xRefPosition = xRefTable.WriteToStream(_stream);
|
238 | 239 |
|
239 |
| - var trailer = new Trailer(xRefPosition, xRefTable.Section.ObjectCount, _catalog, DocumentInformation); |
240 |
| - trailer.WriteToStream(_stream); |
| 240 | + _writeTrailer(_stream, xRefPosition, xRefTable.Section.ObjectCount, _catalog.Reference, DocumentInformation.Reference); |
241 | 241 | }
|
242 | 242 |
|
243 |
| - private readonly struct Trailer |
| 243 | + private void _writeTrailer(PdfStream stream, uint startXRef, int size, PdfReference root, PdfReference documentInfo) |
244 | 244 | {
|
245 |
| - public Trailer(uint startXRef, int size, Catalog root, DocumentInformation documentInfo) |
246 |
| - { |
247 |
| - StartXRef = startXRef; |
248 |
| - Size = size; |
249 |
| - Root = root.Reference; |
250 |
| - DocumentInfo = documentInfo.Reference; |
251 |
| - } |
252 |
| - |
253 |
| - public uint StartXRef { get; } |
254 |
| - public int Size { get; } |
255 |
| - public PdfReference Root { get; } |
256 |
| - public PdfReference DocumentInfo { get; } |
257 |
| - |
258 |
| - internal uint WriteToStream(PdfStream stream) |
259 |
| - { |
260 |
| - var position = (uint)stream.Position; |
261 |
| - |
262 |
| - stream |
263 |
| - .Write("trailer") |
264 |
| - .NewLine() |
265 |
| - .Dictionary(this, static (trailer, dictionary) => |
266 |
| - { |
267 |
| - dictionary |
268 |
| - .Write(PdfName.Get("Size"), trailer.Size) |
269 |
| - .Write(PdfName.Get("Root"), trailer.Root) |
270 |
| - .Write(PdfName.Get("Info"), trailer.DocumentInfo); |
271 |
| - }) |
272 |
| - .Write("startxref") |
273 |
| - .NewLine() |
274 |
| - .Write(StartXRef) |
275 |
| - .NewLine() |
276 |
| - .Write("%%EOF"); |
277 |
| - |
278 |
| - return position; |
279 |
| - } |
| 245 | + stream |
| 246 | + .Write("trailer") |
| 247 | + .NewLine() |
| 248 | + .Dictionary((size, root, documentInfo), static (triple, dictionary) => |
| 249 | + { |
| 250 | + var (size, root, documentInfo) = triple; |
| 251 | + dictionary |
| 252 | + .Write(PdfName.Get("Size"), size) |
| 253 | + .Write(PdfName.Get("Root"), root) |
| 254 | + .Write(PdfName.Get("Info"), documentInfo); |
| 255 | + }) |
| 256 | + .Write("startxref") |
| 257 | + .NewLine() |
| 258 | + .Write(startXRef) |
| 259 | + .NewLine() |
| 260 | + .Write("%%EOF"); |
280 | 261 | }
|
281 | 262 | }
|
282 | 263 | }
|
0 commit comments