コード例 #1
0
        public void StartNumbering(PDFPageNumberOptions opts)
        {
            this._registrations = new List <PDFPageNumberRegistration>();
            this._route         = new Stack <PDFPageNumberGroup>();
            this._namedGroups   = new Dictionary <string, PDFPageNumberGroup>();

            PDFPageNumberGroup grp;

            if (null != opts && opts.HasPageNumbering && GetGroupingFromOptions(this._default, opts, out grp))
            {
                this._route.Push(grp);
            }
        }
コード例 #2
0
        /// <summary>
        /// Extracts out the relevant information from the style and builds a group
        /// or returns the DefaultGrouping if there is no relevant information
        /// </summary>
        /// <param name="style"></param>
        /// <returns></returns>
        private static bool GetGroupingFromOptions(PDFPageNumberGroup template, PDFPageNumberOptions opts, out PDFPageNumberGroup updated)
        {
            if (null == opts)
            {
                throw new ArgumentNullException("opts");
            }
            if (null == template)
            {
                throw new ArgumentNullException("template");
            }

            bool            modified = false;
            PageNumberStyle numStyle = template.NumberStyle;
            int             numStart = template.NumberStart;
            string          grpName  = template.GroupName;


            if (!string.IsNullOrEmpty(opts.NumberGroup))
            {
                if (opts.NumberGroup == template.GroupName)
                {
                    throw new InvalidOperationException("The new style and the template have the same name - they should use the same options");
                }
                grpName  = opts.NumberGroup;
                modified = true;
            }


            if (opts.NumberStyle.HasValue)// && style.NumberStyle != numStyle)
            {
                modified = true;
                numStyle = opts.NumberStyle.Value;
            }

            if (opts.StartIndex.HasValue)// && style.NumberStartIndex != numStart)
            {
                modified = true;
                numStart = opts.StartIndex.Value;
            }

            if (modified)
            {
                updated = new PDFPageNumberGroup(template.Owner, grpName, numStyle, numStart);
                return(modified);
            }
            else
            {
                updated = null;
                return(false);
            }
        }
コード例 #3
0
        //
        // public methods
        //

        public PDFPageNumberGroup PushPageNumber(PDFPageNumberOptions opts)
        {
            if (null != opts && opts.HasPageNumbering)
            {
                PDFPageNumberGroup grp;

                if (string.IsNullOrEmpty(opts.NumberGroup) || !_namedGroups.TryGetValue(opts.NumberGroup, out grp))
                {
                    if (this._route.Count == 0)
                    {
                        GetGroupingFromOptions(this._default, opts, out grp);
                    }

                    else
                    {
                        GetGroupingFromOptions(this._route.Peek(), opts, out grp);
                    }
                }

                //check if the pushed style is different from the current group or we don't have anything on the stack.
                if (null != grp)
                {
                    if (this._route.Count > 0 && _route.Peek().IsCounting)
                    {
                        this._lastGroup = this._route.Peek();
                    }

                    this._route.Push(grp);

                    if (!string.IsNullOrEmpty(grp.GroupName))
                    {
                        this._namedGroups.Add(grp.GroupName, grp);
                    }

                    return(grp);
                }
            }

            return(null);
        }