/// <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);
        }
Exemplo n.º 2
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();
        }
 protected virtual void RenderPathInformation(PDFContextBase context, PDFWriter writer, PDFObjectRef xobj)
 {
     writer.BeginDictionaryEntry("BBox");
     writer.BeginArray();
     writer.WriteArrayRealEntries(0.0, 0.0, _size.Width.PointsValue, _size.Height.PointsValue);
     writer.EndArray();
     writer.EndDictionaryEntry();
 }
Exemplo n.º 4
0
        public override void RenderWidthsArrayToPDF(PDFContextBase context, PDFWriter writer)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "PDFFontWidths", "Width information will be rendered as a CID lookup set");
            }

            List <char> keys = new List <char>(this._char2offset.Keys);

            keys.Sort();
            writer.BeginArray();

            SortedDictionary <int, int> glyph2width = new SortedDictionary <int, int>();

            foreach (WidthMetric met in this._char2offset.Values)
            {
                glyph2width[met.Glyph] = met.Width;
            }

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "PDFFontWidths", "CID Lookup built with glyph widths");
            }

            //Writes the used characters as [c[w] c[w] c[w]]
            //TODO: Improve rendering
            foreach (int g in glyph2width.Keys)
            {
                int w = glyph2width[g];
                writer.WriteNumber(g);
                writer.BeginArray();
                writer.WriteNumber(w);
                writer.EndArray();
            }
            writer.EndArray();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "PDFFontWidths", glyph2width.Count.ToString() + " widths written as CID lookup set");
            }
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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();
        }
Exemplo n.º 7
0
 private void WriteInputColor(PDFRenderContext context, PDFWriter writer, string key, PDFColor color)
 {
     writer.BeginDictionaryEntry(key);
     if (color.ColorSpace == ColorSpace.RGB)
     {
         writer.WriteArrayRealEntries(true, color.Red.Value, color.Green.Value, color.Blue.Value);
     }
     else if (color.ColorSpace == ColorSpace.G)
     {
         writer.WriteArrayRealEntries(true, color.Gray.Value);
     }
     else
     {
         writer.BeginArray();
         writer.EndArray();
         context.TraceLog.Add(TraceLevel.Warning, "Output", "The color space " + color.ColorSpace.ToString() + " is not supported in input backgrounds");
     }
     writer.EndDictionaryEntry();
 }
Exemplo n.º 8
0
        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");
                }
            }
        }
        /// <summary>
        /// Writes all the destinations to the current PDF Object
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <param name="all"></param>
        /// <returns></returns>
        private PDFObjectRef WriteDestinationNames(PDFRenderContext context, PDFWriter writer, IEnumerable <string> all)
        {
            PDFObjectRef dests = writer.BeginObject();

            writer.BeginDictionary();

            //Write the names array
            writer.BeginDictionaryEntry("Names");
            writer.BeginArray();

            string firstname = string.Empty;
            string lastname  = string.Empty;

            foreach (string name in all)
            {
                if (WriteDestination(context, writer, name))
                {
                    if (string.IsNullOrEmpty(firstname))
                    {
                        firstname = name;
                    }
                    lastname = name;
                }
            }
            writer.EndArray();
            writer.EndDictionaryEntry();

            //Write limits
            writer.BeginDictionaryEntry("Limits");
            writer.WriteArrayStringEntries(firstname, lastname);
            writer.EndDictionaryEntry();

            writer.EndDictionary();
            writer.EndObject();
            return(dests);
        }
Exemplo n.º 10
0
        private PDFObjectRef RenderOutlineItem(PDFOutlineRef outlineref, PDFObjectRef parent, PDFObjectRef prev, PDFRenderContext context, PDFWriter writer, out int count)
        {
            PDFOutline outline = outlineref.Outline;

            Scryber.Drawing.PDFColor  c  = outlineref.GetColor();
            Scryber.Drawing.FontStyle fs = outlineref.GetFontStyle();
            bool isopen = outlineref.GetIsOpen();

            count = 1;//this one
            PDFObjectRef item = writer.BeginObject();

            writer.BeginDictionary();
            writer.WriteDictionaryObjectRefEntry("Parent", parent);
            writer.WriteDictionaryStringEntry("Title", outline.Title);
            writer.WriteDictionaryStringEntry("Dest", outline.DestinationName);
            if (null != c)
            {
                writer.BeginDictionaryEntry("C");
                writer.BeginArray();
                writer.WriteRealS(c.Red.Value, c.Green.Value, c.Blue.Value);
                writer.EndArray();
                writer.EndDictionaryEntry();
            }

            if (fs != Scryber.Drawing.FontStyle.Regular)
            {
                int f = 0;
                if ((fs & Scryber.Drawing.FontStyle.Bold) > 0)
                {
                    f = 2;
                }
                if ((fs & Scryber.Drawing.FontStyle.Italic) > 0)
                {
                    f += 1;
                }
                writer.WriteDictionaryNumberEntry("F", f);
            }

            if (null != prev)
            {
                writer.WriteDictionaryObjectRefEntry("Prev", prev);
            }

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Outline Stack", "Rendered outline item " + item + " with title '" + outline.Title + " and destination name " + outline.DestinationName);
            }

            if (outlineref.HasInnerItems)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Begin(TraceLevel.Debug, "Outline Stack", "Started rendering inner outline items");
                }


                int          opencount;
                PDFObjectRef childfirst, childlast;
                this.RenderOutlineCollection(outlineref.InnerItems, item, context, writer, out childfirst, out childlast, out opencount);

                writer.WriteDictionaryObjectRefEntry("First", childfirst);
                writer.WriteDictionaryObjectRefEntry("Last", childlast);
                if (opencount > 0)
                {
                    if (isopen)
                    {
                        writer.WriteDictionaryNumberEntry("Count", opencount);
                        count += opencount;
                    }
                    else
                    {
                        writer.WriteDictionaryNumberEntry("Count", -opencount);
                    }
                }

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Debug, "Outlines", " Finished rendering inner outline items");
                }
            }

            //we don't close the dictionary here as we need the next entry written
            //It should be closed in the calling method

            return(item);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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();
            }
        }
Exemplo n.º 13
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);
        }