/// <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. 2
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");
            }
        }
Esempio n. 3
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();
        }