예제 #1
0
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Begin(TraceLevel.Verbose, "Annotation Collection", "Outputting the doument annotations to the writer");
            }

            PDFObjectRef        annot   = writer.BeginObject();
            List <PDFObjectRef> entries = new List <PDFObjectRef>();

            //TODO:Render annotations
            foreach (PDFAnnotationEntry entry in this._annots)
            {
                PDFObjectRef oref = entry.OutputToPDF(context, writer);
                if (oref != null)
                {
                    entries.Add(oref);
                }
            }

            writer.WriteArrayRefEntries(entries.ToArray());
            writer.EndObject();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.End(TraceLevel.Verbose, "Annotation Collection", "Completed the output of " + entries.Count + " annotations on the writer");
            }


            return(annot);
        }
        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);
        }
        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();
        }
예제 #4
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);
            }
        }