/// <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);
        }
Exemple #2
0
        protected override void WriteCatalogEntries(PDFRenderContext context, PDFWriter writer)
        {
            if (null != this.OriginalFile)
            {
                PDFObjectRef catalog  = writer.LastObjectReference();
                PDFObjectRef pageTree = this.OutputPageTree(context, writer);

                foreach (KeyValuePair <PDFName, IFileObject> item in this.ExistingCatalog)
                {
                    if (item.Key.Value == "Pages")
                    {
                        //PDFObjectRef pages = this.OutputAllPages
                        writer.BeginDictionaryEntry(item.Key);
                        pageTree.WriteData(writer);
                        writer.EndDictionaryEntry();
                    }
                    else
                    {
                        writer.BeginDictionaryEntry(item.Key);
                        item.Value.WriteData(writer);
                        writer.EndDictionaryEntry();
                    }
                }
            }
            else
            {
                base.WriteCatalogEntries(context, writer);
            }
        }
Exemple #3
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);
        }
 protected virtual void WriteStandardSecurityEntries(PDFWriter writer)
 {
     writer.WriteDictionaryNumberEntry("V", this.EncryptionVersion);
     writer.WriteDictionaryNumberEntry("R", this.EncryptionRevision);
     writer.WriteDictionaryNumberEntry("Length", this.EncryptionKeySizeBytes * 8);
     writer.BeginDictionaryEntry("O");
     writer.WriteStringHex(this.OwnerHash);
     writer.EndDictionaryEntry();
     writer.BeginDictionaryEntry("U");
     writer.WriteStringHex(this.UserHash);
     writer.EndDictionaryEntry();
     writer.WriteDictionaryNumberEntry("P", (int)this.ProtectionFlags);
 }
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (this.Fields.Count > 0)
            {
                PDFObjectRef parent = writer.BeginObject();

                List <PDFObjectRef> children = new List <PDFObjectRef>();
                foreach (var fld in this.Fields)
                {
                    var child = fld.OutputToPDF(context, writer);
                    if (null != child)
                    {
                        children.Add(child);
                    }
                }

                writer.BeginDictionary();
                writer.WriteDictionaryStringEntry("T", this.Name);
                writer.BeginDictionaryEntry("Kids");
                writer.WriteArrayRefEntries(true, children.ToArray());
                writer.EndDictionaryEntry();
                writer.EndDictionary();
                writer.EndObject();
                return(parent);
            }
            return(null);
        }
        /// <summary>
        /// If this document has artefacts then the collection is output.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        private void WriteArtefacts(PDFRenderContext context, PDFWriter writer)
        {
            PDFArtefactCollectionSet artefacts = this.Artefacts;

            if (artefacts != null && artefacts.Count > 0)
            {
                foreach (IArtefactCollection col in artefacts)
                {
                    context.TraceLog.Begin(TraceLevel.Verbose, "Layout Document", "Outputting artefact catalog entry collection " + col.CollectionName);
                    writer.BeginDictionaryEntry(col.CollectionName);

                    PDFObjectRef entry = col.OutputToPDF(context, writer);
                    if (entry != null)
                    {
                        writer.WriteObjectRef(entry);
                    }
                    else
                    {
                        writer.WriteNull();
                    }
                    writer.EndDictionaryEntry();

                    context.TraceLog.End(TraceLevel.Verbose, "Layout Document", "Finished artefact catalog entry collection " + col.CollectionName);
                }
            }
        }
Exemple #7
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();
        }
Exemple #8
0
        protected virtual PDFObjectRef DoWritePage(PDFRenderContext context, PDFWriter writer, PDFObjectRef parent)
        {
            PDFObjectRef pg = writer.BeginPage(context.PageIndex);

            this.PageObjectRef = pg;
            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Page");
            writer.WriteDictionaryObjectRefEntry("Parent", parent);
            writer.BeginDictionaryEntry("MediaBox");
            writer.WriteArrayRealEntries(0.0, 0.0, this.Size.Width.ToPoints().Value, this.Size.Height.ToPoints().Value);
            writer.EndDictionaryEntry();
            if (this.FullStyle.IsValueDefined(StyleKeys.PageAngle))
            {
                int value = this.FullStyle.GetValue(StyleKeys.PageAngle, 0);
                writer.WriteDictionaryNumberEntry("Rotate", value);
            }

            context.PageSize = this.Size;
            context.Offset   = new PDFPoint();
            context.Space    = context.PageSize;

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the contents of page : " + this.PageIndex);
            }

            PDFObjectRef content = this.OutputContent(context, writer);

            if (content != null)
            {
                writer.WriteDictionaryObjectRefEntry("Contents", content);
            }

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Layout Page", "Rendering the resources of page : " + this.PageIndex);
            }

            //PDFObjectRef[] annots = this.DoWriteAnnotations(context, writer);
            //if (null != annots && annots.Length > 0)
            //{
            //    writer.BeginDictionaryEntry("Annots");
            //    writer.WriteArrayRefEntries(true, annots);
            //    writer.EndDictionaryEntry();
            //}

            PDFObjectRef ress = this.DoWriteResource(context, writer);

            if (ress != null)
            {
                writer.WriteDictionaryObjectRefEntry("Resources", ress);
            }

            DoWriteArtefacts(context, writer);
            writer.EndDictionary();
            writer.EndPage(context.PageIndex);

            return(pg);
        }
        private void OutputDefaultResources(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionaryEntry("DR");
            writer.BeginDictionaryS();

            writer.BeginDictionaryEntry("Font");

            writer.BeginDictionary();
            writer.WriteDictionaryObjectRefEntry("frsc1", new PDFObjectRef(7, 0));
            writer.EndDictionary();

            writer.EndDictionaryEntry();

            writer.EndDictionary();

            writer.EndDictionaryEntry();
        }
 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();
 }
 protected void OutputInfoEntry(string name, DateTime value, PDFWriter writer)
 {
     if (value > DateTime.MinValue)
     {
         writer.BeginDictionaryEntry(name);
         writer.WriteDate(value);
         writer.EndDictionaryEntry();
     }
 }
        public override void WriteFunctionDictionary(PDFContextBase context, PDFWriter writer)
        {
            writer.BeginDictionary();
            writer.WriteDictionaryNumberEntry("FunctionType", 2);

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

            writer.BeginDictionaryEntry("C0");
            writer.WriteArrayRealEntries(this.ColorZero.Red.Value, this.ColorZero.Green.Value, this.ColorZero.Blue.Value);
            writer.EndDictionaryEntry();

            writer.BeginDictionaryEntry("C1");
            writer.WriteArrayRealEntries(this.ColorOne.Red.Value, this.ColorOne.Green.Value, this.ColorOne.Blue.Value);
            writer.EndDictionaryEntry();

            writer.WriteDictionaryRealEntry("N", this.Exponent);
            writer.EndDictionary(); //function
        }
 /// <summary>
 /// Writes the dictionary entries usign the PDFWriter
 /// </summary>
 /// <param name="writer">The PDFWriter to use</param>
 public void WriteData(PDFWriter writer)
 {
     writer.BeginDictionaryS();
     foreach (KeyValuePair <PDFName, IFileObject> kvp in this)
     {
         writer.BeginDictionaryEntry(kvp.Key);
         kvp.Value.WriteData(writer);
         writer.EndDictionaryEntry();
     }
     writer.EndDictionary();
 }
Exemple #14
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();
        }
Exemple #15
0
        public PDFObjectRef WriteResourceList(PDFContextBase context, PDFWriter writer)
        {
            PDFObjectRef oref = writer.BeginObject();

            writer.BeginDictionary();

            if (this._includeProcSet)
            {
                writer.BeginDictionaryEntry("ProcSet");
                writer.WriteArrayNameEntries(ProcSets);
                writer.EndDictionaryEntry();
            }
            foreach (PDFResourceItemList list in this.types)
            {
                writer.BeginDictionaryEntry(list.Type);
                writer.BeginDictionary();
                foreach (PDFResource rsrc in list)
                {
                    PDFObjectRef rref = rsrc.EnsureRendered(context, writer);
                    if (rref != null)
                    {
                        writer.BeginDictionaryEntry(rsrc.Name);
                        writer.WriteObjectRef(rref);
                        writer.EndDictionaryEntry();
                    }
                }
                writer.EndDictionary();
                writer.EndDictionaryEntry();
            }


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

            return(oref);
        }
        /// <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);
        }
Exemple #17
0
        protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer)
        {
            PDFObjectRef oref = writer.BeginObject();

            writer.BeginDictionaryS();
            writer.WriteDictionaryNameEntry("Type", "ExtGState");
            foreach (PDFName name in this.States.Keys)
            {
                writer.BeginDictionaryEntry(name);
                this.States[name].WriteData(writer);
                writer.EndDictionaryEntry();
            }
            writer.EndDictionary();
            writer.EndObject();
            return(oref);
        }
        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));
                }
            }
        }
        private void WriteOptionalFlag(string name, object value, PDFRenderContext context, PDFWriter writer)
        {
            if (null == value)
            {
                return;
            }
            else
            {
                writer.BeginDictionaryEntry(name);
                writer.WriteBoolean((bool)value);
                writer.EndDictionaryEntry();

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, "Viewer Preferences", String.Format("Output /{0} value to {1}", name, value));
                }
            }
        }
Exemple #20
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();
 }
        private void OutputFields(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionaryEntry("Fields");

            List <PDFObjectRef> entries = new List <PDFObjectRef>();

            Resources.PDFResourceCollection all = new Resources.PDFResourceCollection(this.Owner);

            foreach (PDFAcrobatFormFieldWidget entry in this.Fields)
            {
                PDFObjectRef oref = entry.OutputToPDF(context, writer);
                if (null != oref)
                {
                    entries.Add(oref);
                }
            }
            writer.WriteArrayRefEntries(true, entries.ToArray());
            List <IPDFResource> rsrs = new List <IPDFResource>();

            writer.EndDictionaryEntry();
        }
        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 the collection of page labels and returns a reference to this collection
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        private PDFObjectRef WritePageLabels(PDFRenderContext context, PDFWriter writer)
        {
            PDFPageNumbers nums   = this.Numbers;
            PDFObjectRef   labels = writer.BeginObject("PageLabels");

            writer.BeginDictionary();
            writer.BeginDictionaryEntry("Nums");
            writer.BeginArrayS();

            //PDFPageNumberRegistration def = this.Numbers.;
            //this.WriteAPageLabel(context, writer, def);

            foreach (PDFPageNumberRegistration entry in this.Numbers.Registrations)
            {
                WriteAPageLabel(context, writer, entry);
            }
            writer.EndArray();
            writer.EndDictionaryEntry();
            writer.EndDictionary();
            writer.EndObject();
            return(labels);
        }
Exemple #24
0
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            List <PDFObjectRef> all = new List <PDFObjectRef>();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Begin(TraceLevel.Debug, "Link Annotation", "Outputting all required link annotations for component " + this.Component.UniqueID);
            }

            int pageindex = context.PageIndex;
            PDFComponentArrangement arrange = this.Component.GetFirstArrangement();
            int index = 1;

            while (null != arrange && arrange.PageIndex == pageindex)
            {
                PDFObjectRef annotref = writer.BeginObject();
                writer.BeginDictionary();
                writer.WriteDictionaryNameEntry("Type", "Annot");
                writer.WriteDictionaryNameEntry("Subtype", "Link");
                if (!string.IsNullOrEmpty(this.AlternateText))
                {
                    writer.WriteDictionaryStringEntry("Contents", this.AlternateText);
                }
                PDFRect bounds = arrange.RenderBounds;
                if (bounds != PDFRect.Empty && bounds.Size != PDFSize.Empty)
                {
                    if (context.DrawingOrigin == DrawingOrigin.TopLeft)
                    {
                        //PDFs have origin at bottom so need to convert.
                        PDFReal value = context.Graphics.GetXPosition(bounds.X.RealValue);
                        bounds.X      = new PDFUnit(value.Value, PageUnits.Points);
                        value         = context.Graphics.GetYPosition(bounds.Y.RealValue);
                        bounds.Y      = new PDFUnit(value.Value, PageUnits.Points);
                        bounds.Width  = bounds.X + bounds.Width;
                        bounds.Height = bounds.Y - bounds.Height;
                    }
                    else
                    {
                        bounds.Width  = bounds.X + bounds.Width;
                        bounds.Height = bounds.Y + bounds.Height;
                    }

                    writer.BeginDictionaryEntry("Rect");
                    writer.WriteArrayRealEntries(bounds.X.Value, bounds.Y.Value, bounds.Width.Value, bounds.Height.Value);
                    writer.EndDictionaryEntry();
                }
                string name = this.Component.UniqueID + "_" + index.ToString();
                writer.WriteDictionaryStringEntry("NM", name);

                //Draw the border
                StyleValue <LineType> lstyle;

                /* if (this.AnnotationStyle != null && this.AnnotationStyle.TryGetValue(StyleKeys.BorderStyleKey, out lstyle) && lstyle != null && lstyle.Value != LineType.None)
                 * {
                 *  PDFUnit corner = this.AnnotationStyle.GetValue(StyleKeys.BorderCornerRadiusKey, (PDFUnit)0);
                 *  PDFUnit width = this.AnnotationStyle.GetValue(StyleKeys.BorderWidthKey, (PDFUnit)1);
                 *  PDFColor c = this.AnnotationStyle.GetValue(StyleKeys.BorderColorKey, PDFColors.Transparent);
                 *
                 *  if (c != null && width > 0)
                 *  {
                 *      writer.BeginDictionaryEntry("Border");
                 *      writer.WriteArrayRealEntries(corner.PointsValue, corner.PointsValue, width.PointsValue);
                 *      writer.EndDictionaryEntry();
                 *
                 *      writer.BeginDictionaryEntry("C");
                 *      if (c.ColorSpace == ColorSpace.G)
                 *          writer.WriteArrayRealEntries(c.Gray.Value);
                 *      else if (c.ColorSpace == ColorSpace.RGB)
                 *          writer.WriteArrayRealEntries(c.Red.Value, c.Green.Value, c.Blue.Value);
                 *      else if (context.Conformance == ParserConformanceMode.Strict)
                 *          RecordAndRaise.ArgumentOutOfRange("c", Errors.ColorValueIsNotCurrentlySupported, c.ColorSpace);
                 *      else
                 *          context.TraceLog.Add(TraceLevel.Error, "Link Annotation", string.Format(Errors.ColorValueIsNotCurrentlySupported, c.ColorSpace));
                 *
                 *      writer.EndDictionaryEntry();
                 *  }
                 *
                 * }
                 * else
                 * {   */

                writer.BeginDictionaryEntry("Border");
                //writer.WriteArrayRealEntries(1.0, 1.0, 1.0);
                writer.WriteArrayRealEntries(0.0, 0.0, 0.0);
                writer.EndDictionaryEntry();
                //}

                if (null != this.Action)
                {
                    writer.BeginDictionaryEntry("A");
                    PDFObjectRef actionref = this.Action.OutputToPDF(context, writer);
                    if (null != actionref)
                    {
                        writer.WriteObjectRefS(actionref);
                    }
                    writer.EndDictionaryEntry();
                }
                writer.EndDictionary();
                writer.EndObject();

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, "Link Annotation", "Annotation added " + name + " for bounds " + bounds + " on page " + context.PageIndex);
                }

                all.Add(annotref);

                //If we have more than one arrangement on the object then move to the next one
                if (arrange is PDFComponentMultiArrangement)
                {
                    arrange = ((PDFComponentMultiArrangement)arrange).NextArrangement;
                }
                index++;
            }



            if (all.Count == 0)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Debug, "Link Annotation", "No required link annotations for component " + this.Component.UniqueID);
                }

                return(null);
            }
            else if (all.Count == 1)
            {
                return(all[0]);
            }
            else
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Debug, "Link Annotation", "All " + all.Count + " link annotations for component " + this.Component.UniqueID + " were output");
                }
                PDFObjectRef array = writer.BeginObject();
                writer.WriteArrayRefEntries(all.ToArray());
                writer.EndObject();
                return(array);
            }
        }
        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);
        }
        //
        // 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);
        }
Exemple #27
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);
        }
Exemple #28
0
        protected override PDFObjectRef DoOutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            //Get the default font and size required for the DA (default Appearance value)
            var xObject = this._states[FormFieldAppearanceState.Normal];

            if (null == xObject)
            {
                return(null);
            }

            PDFObjectRef root = writer.BeginObject();

            var    font = this._style.CreateFont();
            var    rsrc = xObject.Document.GetResource(Scryber.Resources.PDFResource.FontDefnResourceType, font.FullName, true);
            string da   = rsrc.Name.ToString() + " " + font.Size.ToPoints().Value.ToString() + " Tf";

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Subtype", "Widget");
            writer.WriteDictionaryStringEntry("T", this.Name);

            if (!string.IsNullOrEmpty(this.Value))
            {
                writer.WriteDictionaryStringEntry("V", this.Value);
            }

            if (!string.IsNullOrEmpty(this.DefaultValue))
            {
                writer.WriteDictionaryStringEntry("DV", this.DefaultValue);
            }

            writer.WriteDictionaryNumberEntry("Ff", (int)this.FieldOptions + (int)this.FieldType);
            writer.WriteDictionaryStringEntry("DA", da);
            writer.WriteDictionaryNameEntry("FT", GetFieldTypeName(this.FieldType));
            if (null != this._page && null != this._page.PageObjectRef)
            {
                writer.WriteDictionaryObjectRefEntry("P", this._page.PageObjectRef);
            }

            //MK - appearance dictionary
            writer.BeginDictionaryEntry("MK");
            writer.BeginDictionary();

            if (this._style.IsValueDefined(Styles.StyleKeys.BorderColorKey))
            {
                WriteInputColor(context, writer, "BC", this._style.Border.Color);
            }
            if (this._style.IsValueDefined(Styles.StyleKeys.BgColorKey))
            {
                WriteInputColor(context, writer, "BG", this._style.Background.Color);
            }
            writer.EndDictionary();
            writer.EndDictionaryEntry();

            if (this._states.Count > 0)
            {
                _location = context.Offset;

                Drawing.PDFRect bounds = Drawing.PDFRect.Empty;
                writer.BeginDictionaryEntry("AP");
                writer.BeginDictionary();
                foreach (var kvp in _states)
                {
                    xObject = kvp.Value;
                    FormFieldAppearanceState state = kvp.Key;

                    PDFObjectRef oref = xObject.OutputToPDF(context, writer);

                    if (null != oref)
                    {
                        PDFSize sz = new Drawing.PDFSize(xObject.Width, xObject.Height);
                        if (_size == PDFSize.Empty)
                        {
                            _size = sz;
                        }
                        else
                        {
                            if (_size.Width < sz.Width)
                            {
                                _size.Width = sz.Width;
                            }
                            if (_size.Height < sz.Height)
                            {
                                _size.Height = sz.Height;
                            }
                        }
                        var name = GetFieldStateName(kvp.Key);
                        writer.WriteDictionaryObjectRefEntry(name, oref);

                        //We should have all states starting at the same location no matter what.
                        this._location = xObject.Location;
                    }
                }
                writer.EndDictionary();
                writer.EndDictionaryEntry();

                PDFReal left   = context.Graphics.GetXPosition(_location.X);
                PDFReal top    = context.Graphics.GetYPosition(_location.Y);
                PDFReal right  = left + context.Graphics.GetXOffset(_size.Width);
                PDFReal bottom = top + context.Graphics.GetYOffset(_size.Height);

                writer.BeginDictionaryEntry("Rect");
                writer.WriteArrayRealEntries(true, left.Value, bottom.Value, right.Value, top.Value);
                writer.EndDictionaryEntry();
            }
            writer.EndDictionary();
            writer.EndObject();
            //context.Offset = new PDFPoint(context.Offset.X, context.Offset.Y + _size.Height);
            return(root);
        }
Exemple #29
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);
        }
Exemple #30
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();
            }
        }