/// <summary> /// If this document has artefacts then the collection is output. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> private void WriteArtefacts(PDFRenderContext context, PDFWriter writer) { PDFArtefactCollectionSet artefacts = this.Artefacts; if (artefacts != null && artefacts.Count > 0) { foreach (IArtefactCollection col in artefacts) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Outputting artefact catalog entry collection " + col.CollectionName); writer.BeginDictionaryEntry(col.CollectionName); PDFObjectRef entry = col.OutputToPDF(context, writer); if (entry != null) { writer.WriteObjectRef(entry); } else { writer.WriteNull(); } writer.EndDictionaryEntry(); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished artefact catalog entry collection " + col.CollectionName); } } }
/// <summary> /// Outputs the first Page tree Component and calls Output on each of the layout pages. /// </summary> /// <param name="context">The current context</param> /// <param name="writer">The current writer</param> /// <returns>A reference to the current page tree root Component</returns> protected virtual PDFObjectRef OutputPageTree(PDFRenderContext context, PDFWriter writer) { //Begin the Pages object and dictionary PDFObjectRef pgs = writer.BeginObject(Const.PageTreeName); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Pages"); List <PDFObjectRef> pagerefs = OutputAllPages(pgs, context, writer); //write the kids array entry in the dictionary writer.BeginDictionaryEntry("Kids"); writer.BeginArray(); foreach (PDFObjectRef kid in pagerefs) { writer.BeginArrayEntry(); writer.WriteFileObject(kid); writer.EndArrayEntry(); } writer.EndArray(); //Write the total number of pages to the dictionary writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Count"); writer.WriteNumber(pagerefs.Count); writer.EndDictionaryEntry(); //close the ditionary and the object writer.EndDictionary(); writer.EndObject(); return(pgs); }
/// <summary> /// Outputs the positioning and visibility of UI elements for the viewer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> protected virtual void WriteViewerPreferences(PDFRenderContext context, PDFWriter writer) { DocumentViewPreferences docview = this.DocumentComponent.ViewPreferences; if (null != docview) { PDFObjectRef view = docview.OutputToPDF(context, writer); if (null != view) { writer.WriteDictionaryObjectRefEntry("ViewerPreferences", view); } string value = docview.GetPageDisplayName(docview.PageDisplay); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageMode", value); } value = docview.GetPageLayoutName(docview.PageLayout); if (!string.IsNullOrEmpty(value)) { writer.WriteDictionaryNameEntry("PageLayout", value); } } }
// // methods // #region public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) + Support methods /// <summary> /// Outputs this Info to the current writer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFObjectRef inforef = writer.BeginObject("Info"); writer.BeginDictionary(); OutputInfoEntry("Title", this.Title, writer); OutputInfoEntry("Subject", this.Subject, writer); OutputInfoEntry("Author", this.Author, writer); OutputInfoEntry("Keywords", this.Keywords, writer); OutputInfoEntry("Producer", this.Producer, writer); OutputInfoEntry("Creator", this.Creator, writer); OutputInfoEntry("CreationDate", this.CreationDate, writer); OutputInfoEntry("ModDate", this.ModifiedDate, writer); if (this.HasTrapping) { writer.WriteDictionaryNameEntry("Trapped", this.Trapped.ToString()); } if (this.HasExtras) { foreach (PDFDocumentInfoExtra extra in this.Extras) { OutputInfoEntry(extra.Name, extra.Value, writer); } } writer.EndDictionary(); writer.EndObject(); return(inforef); }
/// <summary> /// Begns a new data stream on the current indirect object and sets the stream as the new CurrentStream /// </summary> /// <param name="onobject"></param> /// <param name="filters"></param> public override void BeginStream(PDFObjectRef onobject, IStreamFilter[] filters) { PDFIndirectObject pio = onobject.Reference as PDFIndirectObject; pio.InitStream(filters); this.Stack.Push(pio.Stream); }
/// <summary> /// Overides the default implementaton to output the Encryption object before calling the base method /// </summary> /// <param name="documentid"></param> /// <remarks>A reference to the written encrypt object is held so that it can be output on the trailer dictionary later on</remarks> public override void CloseDocument(PDFDocumentID documentid) { PDFObjectRef enc = this.Security.WriteTo(this); _encryptionobject = enc; base.CloseDocument(documentid); }
public PDFTraceLogLayoutDocument(Document doc, IPDFLayoutEngine engine, PDFFile originalfile) : base(doc, engine) { this._originalFile = originalfile; if (null != this._originalFile) { PDFFileIndirectObject catRef = originalfile.DocumentCatalogRef; if (null == catRef) { throw new NullReferenceException("Document catalog could not be found in the original source document"); } this._existCatalog = originalfile.DocumentCatalog; this._existPageTree = originalfile.PageTree; if (null != this._existPageTree) { this._existPageRefs = this.GetAllPages(this._existPageTree, originalfile); } else { this._existPageRefs = new PDFObjectRef[] { } }; } }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Annotation Collection", "Outputting the doument annotations to the writer"); } PDFObjectRef annot = writer.BeginObject(); List <PDFObjectRef> entries = new List <PDFObjectRef>(); //TODO:Render annotations foreach (PDFAnnotationEntry entry in this._annots) { PDFObjectRef oref = entry.OutputToPDF(context, writer); if (oref != null) { entries.Add(oref); } } writer.WriteArrayRefEntries(entries.ToArray()); writer.EndObject(); if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Annotation Collection", "Completed the output of " + entries.Count + " annotations on the writer"); } return(annot); }
protected virtual void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer) { // Pages context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Pages"); PDFObjectRef pglist = this.OutputPageTree(context, writer); writer.WriteDictionaryObjectRefEntry("Pages", pglist); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Pages with page tree " + pglist); // Page Labels context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Page Labels"); PDFObjectRef pglabels = this.WritePageLabels(context, writer); if (null != pglabels) { writer.WriteDictionaryObjectRefEntry("PageLabels", pglabels); } context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Page Labels"); // Artefacts context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write document Artefacts"); this.WriteArtefacts(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing document Artefacts"); //Viewer Preferences context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Starting to write Viewer Preferences"); this.WriteViewerPreferences(context, writer); context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished writing Viewer Preferences"); }
// // methods // public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.IsEmpty()) { if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Viewer Preferences", "No values set on the document viewer preferences so not outputting"); } return(null); } else { PDFObjectRef oref = writer.BeginObject(); writer.BeginDictionary(); this.WriteOptionalFlag("CenterWindow", _centrewindow, context, writer); this.WriteOptionalFlag("FitWindow", _fitwindow, context, writer); this.WriteOptionalFlag("HideWindowUI", _hidewindowui, context, writer); this.WriteOptionalFlag("HideToolbar", _hidetoolbar, context, writer); this.WriteOptionalFlag("HideMenubar", _hidemenubar, context, writer); if (this.NonFullScreenPageDisplay != PageDisplayMode.Undefined) { this.WriteOptionalName("NonFullScreenPageMode", this.NonFullScreenPageDisplay.ToString(), context, writer); } writer.EndDictionary(); writer.EndObject(); return(oref); } }
protected override void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer) { if (null != this.OriginalFile) { PDFObjectRef catalog = writer.LastObjectReference(); PDFObjectRef pageTree = this.OutputPageTree(context, writer); foreach (KeyValuePair <PDFName, IFileObject> item in this.ExistingCatalog) { if (item.Key.Value == "Pages") { //PDFObjectRef pages = this.OutputAllPages writer.BeginDictionaryEntry(item.Key); pageTree.WriteData(writer); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry(item.Key); item.Value.WriteData(writer); writer.EndDictionaryEntry(); } } } else { base.WriteCatalogEntries(context, writer); } }
// // rendering // protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { if (context.ShouldLogVerbose) { context.TraceLog.Begin(TraceLevel.Verbose, "Layout Page", "Starting the render of Page: " + this.PageIndex); } else if (context.ShouldLogMessage) { context.TraceLog.Add(TraceLevel.Message, "Layout Page", "Rendering layout page " + this.PageIndex); } //get the current style and aply it to the style stack Style style = this.FullStyle; context.StyleStack.Push(style); PageSize pagesize = this.PageOwner.GetPageSize(style); //PDFPageNumbering num = this.GetNumbering(style); //this.Document.RegisterPageNumbering(context.PageIndex, this, num); PDFObjectRef last = writer.LastObjectReference(); PDFObjectRef pg; pg = DoWritePage(context, writer, last); context.StyleStack.Pop(); if (context.ShouldLogVerbose) { context.TraceLog.End(TraceLevel.Verbose, "Layout Page", "Completed the rendering of page: " + this.PageIndex); } return(pg); }
protected void DoWriteArtefacts(PDFRenderContext context, PDFWriter writer) { if (this.Artefacts != null && this.Artefacts.Count > 0) { foreach (IArtefactCollection col in this.Artefacts) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Rendering artefact entry " + col.CollectionName); } PDFObjectRef artefact = col.OutputToPDF(context, writer); if (null != artefact) { writer.WriteDictionaryObjectRefEntry(col.CollectionName, artefact); } if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Debug, "Layout Page", "Finished artefact entry " + col.CollectionName); } } } }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.Fields.Count > 0) { PDFObjectRef parent = writer.BeginObject(); List <PDFObjectRef> children = new List <PDFObjectRef>(); foreach (var fld in this.Fields) { var child = fld.OutputToPDF(context, writer); if (null != child) { children.Add(child); } } writer.BeginDictionary(); writer.WriteDictionaryStringEntry("T", this.Name); writer.BeginDictionaryEntry("Kids"); writer.WriteArrayRefEntries(true, children.ToArray()); writer.EndDictionaryEntry(); writer.EndDictionary(); writer.EndObject(); return(parent); } return(null); }
protected virtual PDFObjectRef DoWritePage(PDFRenderContext context, PDFWriter writer, PDFObjectRef parent) { PDFObjectRef pg = writer.BeginPage(context.PageIndex); this.PageObjectRef = pg; writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Page"); writer.WriteDictionaryObjectRefEntry("Parent", parent); writer.BeginDictionaryEntry("MediaBox"); writer.WriteArrayRealEntries(0.0, 0.0, this.Size.Width.ToPoints().Value, this.Size.Height.ToPoints().Value); writer.EndDictionaryEntry(); if (this.FullStyle.IsValueDefined(StyleKeys.PageAngle)) { int value = this.FullStyle.GetValue(StyleKeys.PageAngle, 0); writer.WriteDictionaryNumberEntry("Rotate", value); } context.PageSize = this.Size; context.Offset = new PDFPoint(); context.Space = context.PageSize; if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the contents of page : " + this.PageIndex); } PDFObjectRef content = this.OutputContent(context, writer); if (content != null) { writer.WriteDictionaryObjectRefEntry("Contents", content); } if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the resources of page : " + this.PageIndex); } //PDFObjectRef[] annots = this.DoWriteAnnotations(context, writer); //if (null != annots && annots.Length > 0) //{ // writer.BeginDictionaryEntry("Annots"); // writer.WriteArrayRefEntries(true, annots); // writer.EndDictionaryEntry(); //} PDFObjectRef ress = this.DoWriteResource(context, writer); if (ress != null) { writer.WriteDictionaryObjectRefEntry("Resources", ress); } DoWriteArtefacts(context, writer); writer.EndDictionary(); writer.EndPage(context.PageIndex); return(pg); }
// // overrides // #region BeginObject(string name) /// <summary> /// Overrides the default implementation to push state of encryption data onto a stack before returning the base implementations object /// </summary> /// <param name="name"></param> /// <returns></returns> public override PDFObjectRef BeginObject(string name) { PDFObjectRef oref = base.BeginObject(name); PDFObjectEncryptionStream enc = new PDFObjectEncryptionStream(oref); _encrypters.Push(enc); return(oref); }
public PDFObjectEncryptionStream(PDFObjectRef oref) { if (null == oref) { throw new ArgumentNullException("oref"); } this.ObjectRef = oref; }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (null == _refs) { _refs = this.DoOutputToPDF(context, writer); } return(_refs); }
/// <summary> /// Renders the widths to the output writer /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> public PDFObjectRef RenderToPDF(PDFContextBase context, PDFWriter writer) { PDFObjectRef oref = writer.BeginObject(); this.RenderWidthsArrayToPDF(context, writer); writer.EndObject(); return(oref); }
protected override void RenderImageInformation(PDFContextBase context, PDFWriter writer) { base.RenderImageInformation(context, writer); if (this.AlphaData != null) { PDFObjectRef alpha = this.RenderAlpaImageData(context, writer); writer.WriteDictionaryObjectRefEntry("SMask", alpha); } }
internal IStreamFilter CreateEncryptionFilter(PDFObjectRef oref) { if (null == oref) { throw new ArgumentNullException("oref"); } return(CreateEncryptionFilter(oref.Number, oref.Generation)); }
internal override PDFObjectRef WriteTo(PDFWriter writer) { PDFObjectRef oref = writer.BeginObject("StandardEncryption"); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Filter", "Standard"); this.WriteStandardSecurityEntries(writer); writer.EndDictionary(); writer.EndObject(); return(oref); }
/// <summary> /// Begins a new indirect object returning a reference to the newly started indirect object /// </summary> /// <param name="name">The optional name of the object</param> /// <returns></returns> public override PDFObjectRef BeginObject(string name) { PDFIndirectObject obj = CreateIndirectObject(); PDFObjectRef oref = this.InitializeIndirectObject(name, obj); if (this.TraceLog.ShouldLog(TraceLevel.Debug)) { this.Log(TraceLevel.Debug, "Begun a new indirect object: " + oref + (string.IsNullOrEmpty(name) ? "" : (" with name " + name))); } return(oref); }
/// <summary> /// Overrides the default method to write a 4 element array /// </summary> /// <param name="writer"></param> protected override void RenderCustomColorSpace(PDFWriter writer) { writer.BeginDictionaryEntry("ColorSpace"); if (null == this.Pallette || this.Pallette.Length == 0) { throw new NullReferenceException("Palette"); } else { PDFObjectRef index = writer.BeginObject(); writer.BeginArray(); writer.BeginArrayEntry(); writer.WriteName("Indexed"); writer.EndArrayEntry(); writer.BeginArrayEntry(); ColorSpace cs = this.Pallette[0].ColorSpace; if (cs == ColorSpace.RGB) { writer.WriteName("DeviceRGB"); } else if (cs == ColorSpace.G) { writer.WriteName("DeviceG"); } else { throw new ArgumentOutOfRangeException("Palette[0].ColorSpace"); } writer.EndArrayEntry(); writer.BeginArrayEntry(); writer.WriteNumber(this.Pallette.Length - 1);//maximum value not number of entries writer.EndArrayEntry(); //check the stored instance if (null == _bytestreamdata) { _bytestreamdata = GetPaletteString(cs); } writer.BeginArrayEntry(); writer.WriteByteString(_bytestreamdata); writer.EndArrayEntry(); writer.EndArray(); writer.EndObject(); writer.WriteObjectRef(index); } writer.EndDictionaryEntry(); }
public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFGraphics graphics = context.Graphics; Style full = null; PDFComponentArrangement arrange = this.GetFirstArrangement(); if (null != arrange) { full = arrange.FullStyle; } if (null == full) { full = context.FullStyle; } PDFImageXObject img = this.GetImageObject(context, full); if (img != null) { PDFPoint pos = context.Offset; PDFSize imgsize = context.Space; //the pictures are drawn from their bottom left corner, so take off the height. //if (context.DrawingOrigin == DrawingOrigin.TopLeft) // pos.Y = pos.Y + imgsize.Height; graphics.SaveGraphicsState(); StyleValue <double> op; if (full.TryGetValue(StyleKeys.FillOpacityKey, out op)) { if (op.Value(full) < 1.0) { graphics.SetFillOpacity(op.Value(full)); } } PDFObjectRef imgref = img.EnsureRendered(context, writer); graphics.PaintImageRef(img, imgsize, pos); graphics.RestoreGraphicsState(); return(imgref); } else { return(null); } }
/// <summary> /// Outputs the document catalog (usually the first Component) and then calls output on each of the documents /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected virtual PDFObjectRef WriteCatalog(PDFRenderContext context, PDFWriter writer) { PDFObjectRef catalog = writer.BeginObject("Catalog"); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Catalog"); WriteCatalogEntries(context, writer); writer.EndDictionary(); writer.EndObject(); return(catalog); }
protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer) { //Only do this once, but can be referenced from multiple places; if (null == _renderRef) { _renderRef = this.OutputContent(context, writer); } OutputDrawingContent(context, writer); return(_renderRef); }
public PDFObjectRef[] OutputContentsToPDF(PDFRenderContext context, PDFWriter writer) { List <PDFObjectRef> refs = new List <PDFObjectRef>(); foreach (KeyValuePair <string, PDFCategorisedNameTree> kvp in this.InnerDictionary) { PDFObjectRef oref = kvp.Value.OutputToPDF(writer, context); if (null != oref) { refs.Add(oref); } } return(refs.ToArray()); }
public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { if (this.Roots.Count > 0) { if (context.ShouldLogDebug) { context.TraceLog.Begin(TraceLevel.Verbose, "Outline Stack", "Starting to render the outline tree"); } PDFObjectRef outlines = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Outlines"); PDFObjectRef first, last; int count; this.RenderOutlineCollection(this.Roots, outlines, context, writer, out first, out last, out count); if (null != first) { writer.WriteDictionaryObjectRefEntry("First", first); } if (null != last) { writer.WriteDictionaryObjectRefEntry("Last", last); } if (count > 0) { writer.WriteDictionaryNumberEntry("Count", count); } writer.EndDictionary(); writer.EndObject();//outlines if (context.ShouldLogDebug) { context.TraceLog.End(TraceLevel.Verbose, "Outline Stack", "Finished rendering the outline tree"); } else if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Outline Stack", "Rendered the outline tree to indirect object " + outlines + " with first " + first + ", last " + last + " and count " + count); } return(outlines); } else { return(null); } }
public PDFObjectRef[] OutputContentsToPDF(PDFRenderContext context, PDFWriter writer) { List <PDFObjectRef> entries = new List <PDFObjectRef>(); foreach (PDFAnnotationEntry entry in this._annots) { PDFObjectRef oref = entry.OutputToPDF(context, writer); if (null != oref) { entries.Add(oref); } } return(entries.ToArray()); }