/// <summary> /// Writes the trailer flag and the trailer dictionary to the base stream /// </summary> /// <param name="documentid"></param> protected virtual void WriteTrailerObject(PDFDocumentID documentid) { this.BaseStream.WriteLine("trailer"); this.BaseStream.Write(Constants.StartDictionary); WriteTrailerDictionaryEntries(documentid); this.BaseStream.WriteLine(Constants.EndDictionary); }
// // Static Parse - supports the PDFParsableValue attribute // #region public static PDFDocumentID Parse(string value) /// <summary> /// Parses a string value into a PDFDocumentID with the expected format as either a single Guid or a comma separated pair of Guids. /// </summary> /// <param name="value"></param> /// <returns></returns> public static PDFDocumentID Parse(string value) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException(CommonErrors.CannotParseTheDocumentIDs); } try { string[] both = value.Split(','); Guid one = new Guid(both[0].Trim()); Guid two; if (both.Length > 1) { two = new Guid(both[1].Trim()); } else { two = Guid.NewGuid(); } PDFDocumentID ids = PDFDocumentID.Create(one, two); return(ids); } catch (Exception ex) { throw new ArgumentException(CommonErrors.CannotParseTheDocumentIDs, "value", ex); } }
/// <summary> /// Closes the document, writing all the indirect objects, the xreftable, and the trailer to the underlying base stream /// </summary> /// <param name="documentid"></param> public override void CloseDocument(PDFDocumentID documentid) { this.Log(TraceLevel.Message, "Closing the writer and outputting indirect object data onto the underlying stream"); this.WritePDFHeader(); this.WriteAllIndirectObjects(this.XRefTable); this.WriteXRefTable(this.XRefTable); this.BaseStream.WriteLine(); this.WriteTrailerObject(documentid); this.WritePDFEndOfFile(); }
/// <summary> /// Outputs all the trailer dictionary entries - size, catalog, info and id to the base stream /// </summary> /// <param name="documentid"></param> protected virtual void WriteTrailerDictionaryEntries(PDFDocumentID documentid) { this.BaseStream.Write(Constants.StartName); this.BaseStream.Write("Size"); this.BaseStream.Write(Constants.WhiteSpace); this.BaseStream.WriteLine(this.XRefTable.ReferenceCount.ToString()); PDFObjectRef oref; if (this.ObjectDictionary.TryGetValue("Catalog", out oref)) { this.BaseStream.Write(Constants.StartName); this.BaseStream.Write("Root"); this.BaseStream.Write(Constants.WhiteSpace); this.BaseStream.Write(oref.Number + Constants.WhiteSpace + oref.Generation + " R"); this.BaseStream.WriteLine(); } if (this.IsUpdateToExisting) { this.BaseStream.Write(Constants.StartName); this.BaseStream.Write("Prev"); this.BaseStream.Write(Constants.WhiteSpace); this.BaseStream.Write(this.XRefTable.Previous.Offset.ToString()); this.BaseStream.WriteLine(); } if (this.ObjectDictionary.TryGetValue("Info", out oref)) { this.BaseStream.Write(Constants.StartName); this.BaseStream.Write("Info"); this.BaseStream.Write(Constants.WhiteSpace); this.BaseStream.Write(oref.Number + Constants.WhiteSpace + oref.Generation + " R"); } if (documentid != null) { this.BaseStream.WriteLine(); this.BaseStream.Write(Constants.StartName); this.BaseStream.Write("ID"); this.BaseStream.Write(Constants.WhiteSpace); this.BaseStream.Write(Constants.StartArray); this.WriteStringHex(documentid.One); this.BaseStream.Write(" "); this.WriteStringHex(documentid.Two); this.BaseStream.WriteLine(Constants.EndArray); } }
/// <summary> /// Creates and returns a new PDFDocumentID with the known binary values /// </summary> /// <param name="one"></param> /// <param name="two"></param> /// <returns></returns> public static PDFDocumentID Create(byte[] one, byte[] two) { if (null == one || one.Length == 0) { throw new ArgumentOutOfRangeException(CommonErrors.DocumentIDCannotBeEmpty); } if (null == two || two.Length == 0) { throw new ArgumentOutOfRangeException(CommonErrors.DocumentIDCannotBeEmpty); } PDFDocumentID ids = new PDFDocumentID(); ids.One = one; ids.Two = two; return(ids); }
protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { if (null != this.OriginalFile) { writer.OpenDocument(this.OriginalFile, true); PDFObjectRef catalog = this.WriteCatalog(context, writer); this.WriteInfo(context, writer); PDFDocumentID id = this.DocumentComponent.DocumentID; if (null == id) { id = PDFDocumentID.Create(); } writer.CloseDocument(id); return(catalog); } else { return(base.DoOutputToPDF(context, writer)); } }
protected virtual PDFWriterFactory GetSecureWriter(Document forDoc, IDocumentPasswordSettings settings) { if (null == forDoc) { throw new ArgumentNullException("forDoc"); } SecureString owner = null; SecureString user = null; PDFDocumentID id = forDoc.DocumentID; var permissions = forDoc.Permissions; if (null != settings) { owner = settings.OwnerPassword; user = settings.UserPassword; } if (null == id) { id = PDFDocumentID.Create(); forDoc.DocumentID = id; } if (null == permissions) { permissions = new DocumentPermissions(); } var encFactory = permissions.GetFactory(); var enc = encFactory.InitEncrypter(owner, user, id, permissions.GetRestrictions(), forDoc.PerformanceMonitor); return(new PDFSecureWrite14Factory(enc)); }