/// <summary> /// Writes all the indirect object references that are not free, and have no already beew written to the underlying base stream /// </summary> protected virtual void WriteAllIndirectObjects(PDFXRefTable table) { foreach (PDFXRefTableSection section in table.Sections) { foreach (PDFXRefTableEntry entry in section.Entries) { if (entry.Free == false && entry.Reference != null && entry.Reference.Written == false) { WriteAnIndirectObject(entry.Reference); } } } }
/// <summary> /// Opens a new PDF document for writing to appending as a overwrite of the original file if provided, and copying the content of the original file as specified. /// </summary> /// <param name="orig"></param> /// <param name="copytoDestination"></param> public override void OpenDocument(PDFFile orig, bool copytoDestination) { PDFXRefTable prev = null; int startindex = 0; int gen = 0; if (null != orig) { if (copytoDestination) { orig.WriteTo(this.BaseStream); } prev = orig.DocumentXRefs; startindex = prev.MaxReference + 1; gen = prev.Generation; } this.InitXRefTable(startindex, gen, prev); }
/// <summary> /// Outputs a complete XRefTable onto the base stream /// </summary> /// <param name="table"></param> protected void WriteXRefTable(PDFXRefTable table) { this.Log("Outputting XRefTable onto the stream at position " + this.BaseStream.Position.ToString()); this.BaseStream.Flush(); table.Offset = this.BaseStream.Position; this.BaseStream.WriteLine("xref"); foreach (PDFXRefTableSection section in table.Sections) { this.BaseStream.Write(section.Start.ToString()); this.BaseStream.Write(" "); this.BaseStream.WriteLine(section.Count.ToString()); foreach (PDFXRefTableEntry entry in section.Entries) { if (entry.Free) { int next = 0; if (null != entry.NextFree) { next = entry.NextFree.Index; } this.BaseStream.Write(next.ToString("0000000000")); this.BaseStream.Write(entry.Generation.ToString(" 00000")); this.BaseStream.Write(" f"); } else { this.BaseStream.Write(entry.Offset.ToString("0000000000")); this.BaseStream.Write(entry.Generation.ToString(" 00000")); this.BaseStream.Write(" n"); } this.BaseStream.Write(Constants.XRefEntrySeparator); } } this.BaseStream.Flush(); }