protected virtual void RenderImageInformation(PDFContextBase context, PDFWriter writer)
        {
            writer.WriteDictionaryNumberEntry("Width", this.PixelWidth);
            writer.WriteDictionaryNumberEntry("Height", this.PixelHeight);
            //writer.WriteDictionaryNumberEntry("Length", this.Data.LongLength); //- commented for data length fix

            if (this.ColorSpace == ColorSpace.G)
            {
                writer.WriteDictionaryNameEntry("ColorSpace", "DeviceGray");
            }
            else if (this.ColorSpace == ColorSpace.Custom)
            {
                this.RenderCustomColorSpace(writer);
            }
            else if (this.ColorSpace == Drawing.ColorSpace.CMYK)
            {
                writer.WriteDictionaryNameEntry("ColorSpace", "DeviceCMYK");
            }
            else
            {
                writer.WriteDictionaryNameEntry("ColorSpace", "DeviceRGB");
            }

            WriteFilterNames(context, writer);

            writer.WriteDictionaryNumberEntry("BitsPerComponent", this.BitsPerColor);

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Image Data", "Rendered image information dictionary : cs=" + this.ColorSpace + ", w=" + this.PixelWidth + ", h=" + this.PixelHeight + ", bpc=" + BitsPerColor);
            }
        }
        /// <summary>
        /// Outputs the positioning and visibility of UI elements for the viewer
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        protected virtual void WriteViewerPreferences(PDFRenderContext context, PDFWriter writer)
        {
            DocumentViewPreferences docview = this.DocumentComponent.ViewPreferences;

            if (null != docview)
            {
                PDFObjectRef view = docview.OutputToPDF(context, writer);
                if (null != view)
                {
                    writer.WriteDictionaryObjectRefEntry("ViewerPreferences", view);
                }

                string value = docview.GetPageDisplayName(docview.PageDisplay);
                if (!string.IsNullOrEmpty(value))
                {
                    writer.WriteDictionaryNameEntry("PageMode", value);
                }

                value = docview.GetPageLayoutName(docview.PageLayout);
                if (!string.IsNullOrEmpty(value))
                {
                    writer.WriteDictionaryNameEntry("PageLayout", value);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Overrides the abstract base implementation to render the URI action dictionary to current PDFObject stream in the writer. Returns null.
        /// </summary>
        /// <param name="context">The current context</param>
        /// <param name="writer">The writer to write to</param>
        /// <returns></returns>
        public override PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Action");
            writer.WriteDictionaryNameEntry("S", "URI");
            writer.WriteDictionaryStringEntry("URI", this.Url);
            writer.EndDictionary();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Uri Action", "Added Uri destination action to location " + this.Url);
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Renders the action data within the current object
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public override PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Action");
            writer.WriteDictionaryNameEntry("S", "Named");
            string name = this.GetNameForAction(this.ActionType);

            writer.WriteDictionaryNameEntry("N", name);
            writer.EndDictionary();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Named Action", "Added named action " + name + "for annotation");
            }
            return(null);
        }
        //
        // methods
        //

        #region public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer) + Support methods

        /// <summary>
        /// Outputs this Info to the current writer
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public virtual PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            PDFObjectRef inforef = writer.BeginObject("Info");

            writer.BeginDictionary();
            OutputInfoEntry("Title", this.Title, writer);
            OutputInfoEntry("Subject", this.Subject, writer);
            OutputInfoEntry("Author", this.Author, writer);
            OutputInfoEntry("Keywords", this.Keywords, writer);
            OutputInfoEntry("Producer", this.Producer, writer);
            OutputInfoEntry("Creator", this.Creator, writer);
            OutputInfoEntry("CreationDate", this.CreationDate, writer);
            OutputInfoEntry("ModDate", this.ModifiedDate, writer);

            if (this.HasTrapping)
            {
                writer.WriteDictionaryNameEntry("Trapped", this.Trapped.ToString());
            }

            if (this.HasExtras)
            {
                foreach (PDFDocumentInfoExtra extra in this.Extras)
                {
                    OutputInfoEntry(extra.Name, extra.Value, writer);
                }
            }
            writer.EndDictionary();
            writer.EndObject();

            return(inforef);
        }
        /// <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. 7
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);
        }
Esempio n. 8
0
        private PDFObjectRef RenderAlpaImageData(PDFContextBase context, PDFWriter writer)
        {
            context.TraceLog.Add(TraceLevel.Debug, "IMAGE", "Rendering image alpha mask");
            PDFObjectRef mask = writer.BeginObject();

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "XObject");
            writer.WriteDictionaryNameEntry("Subtype", "Image");
            writer.WriteDictionaryNumberEntry("Width", this.PixelWidth);
            writer.WriteDictionaryNumberEntry("Height", this.PixelHeight);
            //writer.WriteDictionaryNumberEntry("Length", this.AlphaData.LongLength);
            writer.WriteDictionaryNameEntry("ColorSpace", "DeviceGray");
            writer.WriteDictionaryNumberEntry("BitsPerComponent", 8);
            this.WriteFilterNames(context, writer);

            //writer.EndDictionary();
            writer.BeginStream(mask);

            byte[] data;
            if (this.HasFilter && this.ShouldApplyFilters(context))
            {
                data = this.GetAlphaFilteredData(this.Filters, context);
                if (null == data)
                {
                    data = this.ApplyFiltersToData(this.AlphaData, context);
                    this.SetAlphaFilteredData(this.Filters, data, context);
                }
            }
            else
            {
                data = this.AlphaData;
            }

            writer.WriteRaw(data, 0, data.Length);

            writer.EndStream();

            //inserted 15/01/15 - Write the filtered length, not the actua image data length to the dictionary.
            writer.WriteDictionaryNumberEntry("Length", data.Length);
            writer.EndDictionary();
            //end of insert

            writer.EndObject();

            return(mask);
        }
        internal PDFObjectRef Render(PDFName name, PDFContextBase context, PDFWriter writer)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Begin(TraceLevel.Message, "Image Data", "Rendering image data for '" + name.ToString() + "'");
            }

            PDFObjectRef renderref = writer.BeginObject(name.Value);

            writer.BeginDictionaryS();
            writer.WriteDictionaryNameEntry("Name", name.Value);
            writer.WriteDictionaryNameEntry("Type", "XObject");
            writer.WriteDictionaryNameEntry("Subtype", "Image");

            RenderImageInformation(context, writer);

            //writer.EndDictionary(); //- commented for data length fix

            writer.BeginStream(renderref);

            int length = this.RenderImageStreamData(context, writer);

            writer.EndStream();

            //Added for Data Length fix HRB 15/01/2015
            writer.WriteDictionaryNumberEntry("Length", length);
            writer.EndDictionary();
            //End of add

            writer.EndObject();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.End(TraceLevel.Message, "Image Data", "Completed render of the image data for '" + name + "' with source " + this.SourcePath);
            }
            else
            {
                context.TraceLog.Add(TraceLevel.Message, "Image Data", "Rendered the image data for '" + name.ToString() + "' with source " + this.SourcePath);
            }


            return(renderref);
        }
Esempio n. 10
0
        /// <summary>
        /// Overrides the abstract base method to render the remote destination
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public override PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Action");
            writer.WriteDictionaryNameEntry("S", "GoToR");
            writer.WriteDictionaryStringEntry("F", this.File);
            if (!string.IsNullOrEmpty(this.DestinationName))
            {
                writer.WriteDictionaryStringEntry("D", this.DestinationName);
            }
            writer.WriteDictionaryBooleanEntry("NewWindow", this.NewWindow);
            writer.EndDictionary();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Remote Action", "Added remote destination action to file " + this.File);
            }

            return(null);
        }
        internal override PDFObjectRef WriteTo(PDFWriter writer)
        {
            PDFObjectRef oref = writer.BeginObject("StandardEncryption");

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Filter", "Standard");
            this.WriteStandardSecurityEntries(writer);
            writer.EndDictionary();
            writer.EndObject();
            return(oref);
        }
Esempio n. 12
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);
        }
        private void WriteAPageLabel(PDFRenderContext context, PDFWriter writer, PDFPageNumberRegistration entry)
        {
            writer.WriteLine();
            writer.BeginArrayEntry();
            writer.WriteNumberS(entry.FirstPageIndex);
            writer.BeginDictionaryS();
            string type;

            switch (entry.Group.NumberStyle)
            {
            case PageNumberStyle.Decimals:
                type = "D";
                break;

            case PageNumberStyle.UppercaseRoman:
                type = "R";
                break;

            case PageNumberStyle.LowercaseRoman:
                type = "r";
                break;

            case PageNumberStyle.UppercaseLetters:
                type = "A";
                break;

            case PageNumberStyle.LowercaseLetters:
                type = "a";
                break;

            default:
                type = "";
                break;
            }
            if (!string.IsNullOrEmpty(type))
            {
                writer.WriteDictionaryNameEntry("S", type);
            }
            if (entry.Group.NumberStart > 0)
            {
                writer.WriteDictionaryNumberEntry("St", entry.Group.NumberStart + entry.PreviousLinkedRegistrationPageCount);
            }
            writer.EndDictionary();
            writer.EndArrayEntry();

            if (context.ShouldLogVerbose)
            {
                context.TraceLog.Add(TraceLevel.Verbose, "Page Labels", "Output the page label entry starting at page index " + entry.FirstPageIndex + " with style " + entry.Group.NumberStyle + ", starting at " + entry.Group.NumberStart);
            }
        }
        /// <summary>
        /// Outputs the document catalog (usually the first Component) and then calls output on each of the documents
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        protected virtual PDFObjectRef WriteCatalog(PDFRenderContext context, PDFWriter writer)
        {
            PDFObjectRef catalog = writer.BeginObject("Catalog");

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Catalog");

            WriteCatalogEntries(context, writer);

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

            return(catalog);
        }
Esempio n. 15
0
        public PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (this.Roots.Count > 0)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Begin(TraceLevel.Verbose, "Outline Stack", "Starting to render the outline tree");
                }

                PDFObjectRef outlines = writer.BeginObject();
                writer.BeginDictionary();
                writer.WriteDictionaryNameEntry("Type", "Outlines");
                PDFObjectRef first, last;
                int          count;

                this.RenderOutlineCollection(this.Roots, outlines, context, writer, out first, out last, out count);

                if (null != first)
                {
                    writer.WriteDictionaryObjectRefEntry("First", first);
                }
                if (null != last)
                {
                    writer.WriteDictionaryObjectRefEntry("Last", last);
                }
                if (count > 0)
                {
                    writer.WriteDictionaryNumberEntry("Count", count);
                }

                writer.EndDictionary();
                writer.EndObject();//outlines

                if (context.ShouldLogDebug)
                {
                    context.TraceLog.End(TraceLevel.Verbose, "Outline Stack", "Finished rendering the outline tree");
                }
                else if (context.ShouldLogVerbose)
                {
                    context.TraceLog.Add(TraceLevel.Verbose, "Outline Stack", "Rendered the outline tree to indirect object " + outlines + " with first " + first + ", last " + last + " and count " + count);
                }

                return(outlines);
            }
            else
            {
                return(null);
            }
        }
        internal PDFObjectRef Render(PDFName name, PDFContextBase context, PDFWriter writer)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Begin(TraceLevel.Message, "Path Data", "Rendering path data for '" + name.ToString() + "'");
            }

            PDFObjectRef renderref = writer.BeginObject(name.Value);

            writer.BeginDictionaryS();
            writer.WriteDictionaryNameEntry("Name", name.Value);
            writer.WriteDictionaryNameEntry("Type", "XObject");
            writer.WriteDictionaryNameEntry("Subtype", "Image");

            RenderPathInformation(context, writer, renderref);

            int length = this.RenderPathData(context, writer, renderref);

            writer.WriteDictionaryNumberEntry("Length", length);
            writer.EndDictionary();
            //End of add

            writer.EndObject();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.End(TraceLevel.Message, "Path Data", "Completed render of the path data for '" + name.ToString());
            }
            else
            {
                context.TraceLog.Add(TraceLevel.Message, "Path Data", "Rendered the path data for '" + name.ToString());
            }


            return(renderref);
        }
Esempio n. 17
0
        /// <summary>
        /// Overrides the base abstract method to write the action dictionary to the current object.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="writer"></param>
        /// <returns></returns>
        public override PDFObjectRef OutputToPDF(PDFRenderContext context, PDFWriter writer)
        {
            if (null == this.Destination)
            {
                throw new NullReferenceException(string.Format("Destination cannot be null for the destination action on component '{0}'", this.Component));
            }

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Action");
            writer.WriteDictionaryNameEntry("S", "GoTo");

            //The destination should be registered with the Name Dictionary
            //so we use the full name here to refer to it.
            writer.WriteDictionaryStringEntry("D", this.Destination.FullName);
            writer.EndDictionaryEntry();

            writer.EndDictionary();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Destination Action", "Added destination action " + this.Destination.FullName + "for annotation");
            }
            return(null);
        }
Esempio n. 18
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);
        }
Esempio n. 19
0
        protected override PDFObjectRef DoRenderToPDF(PDFContextBase context, PDFWriter writer)
        {
            PDFObjectRef oref = writer.BeginObject(this.Name.Value);

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "Pattern");
            writer.WriteDictionaryNumberEntry("PatternType", (int)this.PatternType);
            //Actual shading dictionary
            var shading = this.RenderShadingDictionary(context, writer);

            if (null != shading)
            {
                writer.WriteDictionaryObjectRefEntry("Shading", shading);
            }

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

            return(oref);
        }
Esempio n. 20
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");
                }
            }
        }
Esempio n. 21
0
        public PDFObjectRef RenderToPDF(string fullname, PDFContextBase context, PDFWriter writer)
        {
            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Rendering the font descriptor information");
            }

            PDFObjectRef oref = writer.BeginObject();

            writer.BeginDictionary();
            writer.WriteDictionaryNameEntry("Type", "FontDescriptor");
            writer.WriteDictionaryNameEntry("FontName", fullname);

            if (this.FontFamily != String.Empty)
            {
                writer.WriteDictionaryStringEntry("FontFamily", this.FontFamily);
            }

            if (this.BoundingBox != null && this.BoundingBox.Length > 0)
            {
                writer.BeginDictionaryEntry("FontBBox");
                writer.WriteArrayNumberEntries(this.BoundingBox);
                writer.EndDictionaryEntry();
            }

            if (this.FontStretch != FontStretch.Normal)
            {
                writer.WriteDictionaryStringEntry("FontStretch", this.FontStretch.ToString());
            }

            if (this.Weight != 400)
            {
                writer.WriteDictionaryNumberEntry("FontWeight", this.Weight);
            }

            writer.WriteDictionaryNumberEntry("FontWeight", 700);
            writer.WriteDictionaryNumberEntry("Flags", (int)this.Flags);
            writer.WriteDictionaryNumberEntry("Ascent", (int)(this.Ascent * 0.6));
            writer.WriteDictionaryNumberEntry("Descent", this.Descent);

            //if (this.Leading != 0.0)
            //    writer.WriteDictionaryNumberEntry("Leading", this.Leading);

            if (this.CapHeight != 0.0)
            {
                writer.WriteDictionaryNumberEntry("CapHeight", this.CapHeight);
            }

            if (this.XHeight != 0.0)
            {
                writer.WriteDictionaryNumberEntry("XHeight", this.XHeight);
            }

            writer.WriteDictionaryNumberEntry("StemV", this.StemV);

            writer.WriteDictionaryNumberEntry("ItalicAngle", this.ItalicAngle);

            if (this.StemH != 0.0)
            {
                writer.WriteDictionaryNumberEntry("StemH", this.StemH);
            }

            if (this.AvgWidth != 0.0)
            {
                writer.WriteDictionaryNumberEntry("AvgWidth", this.AvgWidth);
            }

            if (this.MaxWidth != 0.0)
            {
                writer.WriteDictionaryNumberEntry("MaxWidth", this.MaxWidth);
            }

            if (this.MissingWidth != 0.0)
            {
                writer.WriteDictionaryNumberEntry("MissingWidth", this.MissingWidth);
            }

            if (this.FontFile != null)
            {
                if (context.ShouldLogDebug)
                {
                    context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Rendering the font descriptor font file");
                }

                byte[] outputdata = this.FontFile;
                string filter     = null;
                if (context.Compression == OutputCompressionType.FlateDecode)
                {
                    if (context.ShouldLogDebug)
                    {
                        context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Ensuring the font data is compressed");
                    }

                    outputdata = this.FilteredFontFile;
                    filter     = this.FilterName;
                }

                PDFObjectRef fileref = writer.BeginObject();
                writer.BeginDictionary();
                writer.WriteDictionaryNumberEntry("Length", outputdata.Length);
                if (this.FontType == FontType.TrueType)
                {
                    writer.WriteDictionaryNumberEntry("Length1", this.FontFile.Length);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("FontType");
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    writer.WriteDictionaryNameEntry("Filter", this.FilterName);
                }

                writer.EndDictionary();
                writer.BeginStream(fileref);

                writer.WriteRaw(outputdata, 0, outputdata.Length);
                writer.EndStream();
                writer.EndObject();

                //We know this is a true type font program from above
                writer.WriteDictionaryObjectRefEntry("FontFile2", fileref);
            }
            writer.EndDictionary();
            writer.EndObject();

            if (context.ShouldLogDebug)
            {
                context.TraceLog.Add(TraceLevel.Debug, "Font Descriptor", "Completed font descriptor");
            }
            return(oref);
        }
Esempio n. 22
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);
            }
        }
        //
        // 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);
        }
Esempio n. 24
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();
            }
        }
Esempio n. 25
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);
        }