/// <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(); }
private void WriteOptionalName(string name, string value, PDFRenderContext context, PDFWriter writer) { if (String.IsNullOrEmpty(value)) { return; } else { writer.BeginDictionaryEntry(name); writer.WriteName(value); writer.EndDictionaryEntry(); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Viewer Preferences", String.Format("Output /{0} value to {1}", name, value)); } } }
protected void WriteFilterNames(PDFContextBase context, PDFWriter writer) { if (this.ShouldApplyFilters(context)) { if (this.Filters.Length == 1) { writer.WriteDictionaryNameEntry("Filter", this.Filters[0].FilterName); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Image Data", "Output Image Filter with name " + this.Filters[0].FilterName); } } else { writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); for (int i = 0; i < this.Filters.Length; i++) { writer.BeginArrayEntry(); writer.WriteName(this.Filters[i].FilterName); writer.EndArrayEntry(); if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Image Data", "Output Image Filter with name " + this.Filters[i].FilterName); } } writer.EndArray(); writer.EndDictionaryEntry(); } } else { if (context.ShouldLogDebug) { context.TraceLog.Add(TraceLevel.Debug, "Image Data", "No image filters to apply or not appropriate"); } } }
protected virtual PDFObjectRef OutputContent(PDFRenderContext context, PDFWriter writer) { PDFObjectRef oref = writer.BeginObject(); IStreamFilter[] filters = (context.Compression == OutputCompressionType.FlateDecode) ? this.PageCompressionFilters : null; writer.BeginStream(oref, filters); PDFPoint pt = context.Offset.Clone(); PDFSize sz = context.Space.Clone(); using (PDFGraphics g = this.CreateGraphics(writer, context.StyleStack, context)) { context.Graphics = g; if (null != this.HeaderBlock) { this.HeaderBlock.OutputToPDF(context, writer); } this.ContentBlock.OutputToPDF(context, writer); if (null != this.FooterBlock) { this.FooterBlock.OutputToPDF(context, writer); } if (_outputbadge) { this.PaintBadgeXObj(context, writer); } } context.Offset = pt; context.Space = sz; long len = writer.EndStream(); writer.BeginDictionary(); if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } writer.EndDictionary(); writer.EndObject(); return(oref); }
private void WriteXObjectDictionaryContent(PDFRenderContext context, PDFWriter writer, long len, IStreamFilter[] filters) { writer.WriteDictionaryNameEntry("Type", "XObject"); if (!string.IsNullOrEmpty(this.SubType)) { writer.WriteDictionaryNameEntry("Subtype", "Form"); } writer.BeginDictionaryEntry("Matrix"); writer.WriteArrayRealEntries(PDFTransformationMatrix.Identity().Components); // this.Matrix.Components); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("BBox"); writer.BeginArrayS(); if (this._position.ViewPort.HasValue) { PDFRect vp = this._position.ViewPort.Value; writer.WriteReal(vp.X.PointsValue); writer.WriteRealS(vp.Y.PointsValue); writer.WriteRealS(vp.Width.PointsValue); writer.WriteRealS(vp.Height.PointsValue); } else { writer.WriteReal(0.0F); writer.WriteRealS(0.0F); writer.WriteRealS(this._childContainer.Height.PointsValue); writer.WriteRealS(this._childContainer.Height.PointsValue); } writer.EndArray(); writer.EndDictionaryEntry(); PDFObjectRef res = this._resources.WriteResourceList(context, writer); if (null != res) { writer.WriteDictionaryObjectRefEntry("Resources", res); } if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } }
// // methods // #region public PDFObjectRef OutputToPDF(PDFWriter writer, PDFRenderContext context) /// <summary> /// Renderes this destination within the current PDFObject stream of the provided writer. /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) { PDFComponentArrangement arrange; arrange = this.GetFirstArrangementInTree(this.Component); if (null == arrange) { //The component does not have an arrangement so cannot output the destination writer.WriteNullS(); if (context.TraceLog.ShouldLog(TraceLevel.Warning)) { context.TraceLog.Add(TraceLevel.Warning, "Destination", "Destination to component " + this.Component.UniqueID + " cannot be written as it has no arrangement"); } return(null); } int pgindex = arrange.PageIndex; PDFObjectRef oref = writer.PageRefs[pgindex]; if (null == oref) { //No page, so cannot output the destination writer.WriteNullS(); if (context.TraceLog.ShouldLog(TraceLevel.Warning)) { context.TraceLog.Add(TraceLevel.Warning, "Destination", "Destination to component " + this.Component.UniqueID + " cannot be written as it has no page reference"); } return(null); } writer.BeginArray(); //Write the page reference writer.BeginArrayEntry(); writer.WriteObjectRef(oref); writer.EndArrayEntry(); //Write the page fit method switch (this.Fit) { case OutlineFit.FullPage: writer.BeginArrayEntry(); writer.WriteName("Fit"); writer.EndArrayEntry(); break; case OutlineFit.PageWidth: writer.BeginArrayEntry(); writer.WriteName("FitH"); writer.EndArrayEntry(); break; case OutlineFit.PageHeight: writer.BeginArrayEntry(); writer.WriteName("FitV"); writer.EndArrayEntry(); break; case OutlineFit.BoundingBox: writer.BeginArrayEntry(); writer.WriteName("FitR"); writer.EndArrayEntry(); PDFReal left = arrange.RenderBounds.X.RealValue; PDFReal top = arrange.RenderBounds.Y.RealValue; PDFReal right = left + arrange.RenderBounds.Width.RealValue; PDFReal bottom = top + arrange.RenderBounds.Height.RealValue; left = context.Graphics.GetXPosition(left); right = context.Graphics.GetXPosition(right); top = context.Graphics.GetYPosition(top); bottom = context.Graphics.GetYPosition(bottom); if (bottom < top) { PDFReal temp = top; top = bottom; bottom = temp; } if (left > right) { PDFReal temp = left; left = right; right = temp; } writer.BeginArrayEntry(); left.WriteData(writer); writer.EndArrayEntry(); writer.BeginArrayEntry(); bottom.WriteData(writer); writer.EndArrayEntry(); writer.BeginArrayEntry(); right.WriteData(writer); writer.EndArrayEntry(); writer.BeginArrayEntry(); top.WriteData(writer); writer.EndArrayEntry(); break; default: break; } writer.EndArray(); if (context.ShouldLogVerbose) { context.TraceLog.Add(TraceLevel.Verbose, "Destination", "Added a destination to component " + this.Component.UniqueID + " with first arrangment on page " + pgindex + " (" + oref + ") with size fit of " + this.Fit); } return(null); }
// // methods // #region protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer) /// <summary> /// Renders the tiling image /// </summary> /// <param name="context"></param> /// <param name="writer"></param> /// <returns></returns> protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer) { IStreamFilter[] filters = writer.DefaultStreamFilters; PDFObjectRef pattern = writer.BeginObject(); writer.BeginDictionary(); writer.WriteDictionaryNameEntry("Type", "Pattern"); writer.WriteDictionaryNumberEntry("PatternType", (int)this.PatternType); writer.WriteDictionaryNumberEntry("PaintType", (int)this.PaintType); writer.WriteDictionaryNumberEntry("TilingType", (int)this.TilingType); writer.BeginDictionaryEntry("BBox"); PDFPoint offset = new PDFPoint(this.Start.X, this.Start.Y - this.ImageSize.Height);// this.Start; PDFSize size = this.ImageSize; PDFSize graphicsSize = new PDFSize(size.Width + offset.X, size.Height + offset.Y); writer.WriteArrayRealEntries(true, offset.X.PointsValue, offset.Y.PointsValue, offset.X.PointsValue + size.Width.PointsValue, offset.Y.PointsValue + size.Height.PointsValue); writer.EndDictionaryEntry(); writer.WriteDictionaryRealEntry("XStep", this.Step.Width.PointsValue); writer.WriteDictionaryRealEntry("YStep", this.Step.Height.PointsValue); PDFObjectRef all = this.Resources.WriteResourceList(context, writer); writer.WriteDictionaryObjectRefEntry("Resources", all); writer.BeginStream(pattern); using (PDFGraphics g = PDFGraphics.Create(writer, false, this, DrawingOrigin.TopLeft, graphicsSize, context)) { offset = new PDFPoint(offset.X, 0.0); g.PaintImageRef(this.Image, size, offset); } long len = writer.EndStream(); if (null != filters && filters.Length > 0) { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); writer.BeginDictionaryEntry("Filter"); writer.BeginArray(); foreach (IStreamFilter filter in filters) { writer.BeginArrayEntry(); writer.WriteName(filter.FilterName); writer.EndArrayEntry(); } writer.EndArray(); writer.EndDictionaryEntry(); } else { writer.BeginDictionaryEntry("Length"); writer.WriteNumberS(len); writer.EndDictionaryEntry(); } writer.EndDictionary(); writer.EndObject(); return(pattern); }