/// <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);
        }
        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);
        }