Esempio n. 1
0
        /// <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();
        }
Esempio n. 2
0
        protected virtual PDFObjectRef RenderShadingDictionary(PDFContextBase context, PDFWriter writer)
        {
            PDFPoint offset = new PDFPoint(this.Start.X, this.Start.Y);// this.Start;
            PDFSize  size   = this.Size;

            PDFSize graphicsSize = new PDFSize(size.Width + offset.X, size.Height + offset.Y);
            var     func         = this._descriptor.GetGradientFunction(offset, size);
            var     coords       = GetCoords(offset, size, _descriptor.Size, _descriptor.XCentre, _descriptor.YCentre);


            writer.BeginDictionaryEntry("Shading");
            writer.BeginDictionary();
            writer.WriteDictionaryNumberEntry("ShadingType", (int)ShadingType.Radial);
            writer.WriteDictionaryNameEntry("ColorSpace", "DeviceRGB");
            writer.WriteDictionaryBooleanEntry("AntiAlias", true);

            writer.BeginDictionaryEntry("BBox");
            writer.WriteArrayRealEntries(true, offset.X.PointsValue,
                                         offset.Y.PointsValue,
                                         offset.X.PointsValue + size.Width.PointsValue,
                                         offset.Y.PointsValue + size.Height.PointsValue);
            writer.EndDictionaryEntry();

            writer.BeginDictionaryEntry("Coords");
            writer.WriteArrayRealEntries(true, coords);
            writer.EndDictionaryEntry();

            writer.BeginDictionaryEntry("Extend");
            writer.BeginArray();

            writer.BeginArrayEntry();
            writer.WriteBooleanS(true);
            writer.EndArrayEntry();

            writer.BeginArrayEntry();
            writer.WriteBooleanS(true);
            writer.EndArrayEntry();

            writer.EndArray();
            writer.EndDictionaryEntry();

            if (null != func)
            {
                writer.BeginDictionaryEntry("Function");
                func.WriteFunctionDictionary(context, writer);
                writer.EndDictionaryEntry();
            }


            writer.EndDictionary();//shading
            return(null);
        }
        /// <summary>
        /// Writes a single destination
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        internal bool WriteDestination(PDFRenderContext context, PDFWriter writer, string name)
        {
            PDFDestination dest = _dests[name];

            writer.BeginArrayEntry();
            writer.WriteStringLiteral(name);
            writer.EndArrayEntry();

            writer.BeginArrayEntry();
            dest.OutputToPDF(context, writer);
            writer.EndArrayEntry();
            writer.WriteLine();
            return(true);
        }
        /// <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);
        }
Esempio n. 5
0
        public override void WriteFunctionDictionary(PDFContextBase context, PDFWriter writer)
        {
            writer.BeginDictionary();
            writer.WriteDictionaryNumberEntry("FunctionType", 3);

            writer.BeginDictionaryEntry("Domain");
            writer.WriteArrayRealEntries(this.DomainStart, this.DomainEnd);
            writer.EndDictionaryEntry();


            //The bounds is the function extents of the functions
            writer.BeginDictionaryEntry("Bounds");
            writer.BeginArray();
            foreach (var boundary in this.Boundaries)
            {
                writer.BeginArrayEntry();
                writer.WriteRealS(boundary.Bounds);
                writer.EndArrayEntry();
            }
            writer.EndArray();
            writer.EndDictionaryEntry();

            //Write the array of function 2 (Axial aka Linear between 2 colours)
            List <double> encodes = new List <double>();

            writer.BeginDictionaryEntry("Functions");
            writer.BeginArray();
            foreach (var func in this.Functions)
            {
                writer.BeginArrayEntry();
                func.WriteFunctionDictionary(context, writer);
                writer.EndArrayEntry();
                //May need to change these values
                encodes.Add(0);
                encodes.Add(1);
            }

            writer.EndArray();
            writer.EndDictionaryEntry();

            //Write the encodes for each of the functions 0 1 in a single array
            writer.BeginDictionaryEntry("Encode");
            writer.WriteArrayRealEntries(encodes.ToArray());

            writer.EndDictionaryEntry();
            writer.EndDictionary();
        }
Esempio n. 6
0
 /// <summary>
 /// Writes the underlying data of the file object to the passed text writer
 /// </summary>
 /// <param name="tw">The text writer object to write data to</param>
 public void WriteData(PDFWriter writer)
 {
     writer.BeginArrayS();
     foreach (IFileObject pfo in this)
     {
         writer.BeginArrayEntry();
         pfo.WriteData(writer);
         writer.EndArrayEntry();
     }
     writer.EndArray();
 }
        private void WriteAPageLabel(PDFRenderContext context, PDFWriter writer, PDFPageNumberRegistration entry)
        {
            writer.WriteLine();
            writer.BeginArrayEntry();
            writer.WriteNumberS(entry.FirstPageIndex);
            writer.BeginDictionaryS();
            string type;

            switch (entry.Group.NumberStyle)
            {
            case PageNumberStyle.Decimals:
                type = "D";
                break;

            case PageNumberStyle.UppercaseRoman:
                type = "R";
                break;

            case PageNumberStyle.LowercaseRoman:
                type = "r";
                break;

            case PageNumberStyle.UppercaseLetters:
                type = "A";
                break;

            case PageNumberStyle.LowercaseLetters:
                type = "a";
                break;

            default:
                type = "";
                break;
            }
            if (!string.IsNullOrEmpty(type))
            {
                writer.WriteDictionaryNameEntry("S", type);
            }
            if (entry.Group.NumberStart > 0)
            {
                writer.WriteDictionaryNumberEntry("St", entry.Group.NumberStart + entry.PreviousLinkedRegistrationPageCount);
            }
            writer.EndDictionary();
            writer.EndArrayEntry();

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Page Labels", "Output the page label entry starting at page index " + entry.FirstPageIndex + " with style " + entry.Group.NumberStyle + ", starting at " + entry.Group.NumberStart);
            }
        }
        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");
                }
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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();
            }
        }
Esempio n. 11
0
        //
        // 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);
        }
        public Native.PDFObjectRef OutputToPDF(PDFWriter writer, PDFRenderContext context)
        {
            List <ICategorisedArtefactNamesEntry> entries = new List <ICategorisedArtefactNamesEntry>();

            Native.PDFObjectRef oref = null;
            if (this.InnerEntries.Count == 0)
            {
                return(oref);
            }
            if (this.NameType == PDFCategorisedNameDictionary.DestinationsName)
            {
                oref = writer.BeginObject();
                writer.BeginDictionary();
                writer.BeginDictionaryEntry("Names");


                string first = null;
                string last  = null;
                writer.BeginArray();
                foreach (KeyValuePair <string, IArtefactEntry> kvp in this.InnerEntries)
                {
                    if (string.IsNullOrEmpty(first))
                    {
                        first = kvp.Key;
                    }
                    else
                    {
                        last = kvp.Key;
                    }

                    writer.BeginArrayEntry();
                    writer.WriteStringLiteral(kvp.Key);
                    writer.EndArrayEntry();

                    writer.BeginArrayEntry();
                    ((PDFDestination)kvp.Value).OutputToPDF(context, writer);
                    writer.EndArrayEntry();
                    writer.WriteLine();
                }

                writer.EndArray();
                writer.EndDictionaryEntry();

                if (!string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
                {
                    writer.BeginDictionaryEntry("Limits");
                    writer.WriteArrayStringEntries(true, first, last);
                    writer.EndDictionaryEntry();
                }

                writer.EndDictionary();
                writer.EndObject();
            }
            else //we contain ICategorizedArtefactNameEntry(s)
            {
                oref = writer.BeginObject();
                writer.BeginDictionary();
                writer.BeginDictionaryEntry("Names");


                //string first = null;
                //string last = null;

                writer.BeginArray();
                foreach (KeyValuePair <string, IArtefactEntry> kvp in this.InnerEntries)
                {
                    //if (string.IsNullOrEmpty(first))
                    //    first = kvp.Key;
                    //else
                    //    last = kvp.Key;

                    writer.BeginArrayEntry();
                    writer.WriteStringLiteral(kvp.Key);
                    writer.EndArrayEntry();

                    writer.BeginArrayEntry();
                    ICategorisedArtefactNamesEntry entry = (ICategorisedArtefactNamesEntry)kvp.Value;

                    Native.PDFObjectRef entryOref = entry.OutputToPDF(context, writer);
                    if (null != entryOref)
                    {
                        writer.WriteObjectRef(entryOref);
                    }

                    writer.EndArrayEntry();
                    writer.WriteLine();
                }

                writer.EndArray();
                writer.EndDictionaryEntry();

                //Limits only required on Intermediate and Leaf nodes of a tree, not the root
                //if (!string.IsNullOrEmpty(first) && !string.IsNullOrEmpty(last))
                //{
                //    writer.BeginDictionaryEntry("Limits");
                //    writer.WriteArrayStringEntries(true, first, last);
                //    writer.EndDictionaryEntry();

                //}

                writer.EndDictionary();
                writer.EndObject();
            }

            return(oref);
        }