private HeaderFooterConfig SetHeaderFooterConfig()
        {
            var headerFooterConfig = new HeaderFooterConfig
            {
                HeaderMargin =
                {
                    Top    = Convert.ToDouble(ConfigurationManager.AppSettings["headerTopMargin"]),
                    Bottom = Convert.ToDouble(ConfigurationManager.AppSettings["headerBottomMargin"]),
                    Left   = Convert.ToDouble(ConfigurationManager.AppSettings["headerLeftMargin"]),
                    Right  = Convert.ToDouble(ConfigurationManager.AppSettings["headerRightMargin"])
                },
                FooterMargin =
                {
                    Top    = Convert.ToDouble(ConfigurationManager.AppSettings["footerTopMargin"]),
                    Bottom = Convert.ToDouble(ConfigurationManager.AppSettings["footerBottomMargin"]),
                    Left   = Convert.ToDouble(ConfigurationManager.AppSettings["footerLeftMargin"]),
                    Right  = Convert.ToDouble(ConfigurationManager.AppSettings["footerRightMargin"])
                },
                MarginTopOffset    = Convert.ToDouble(ConfigurationManager.AppSettings["marginTopOffset"]),
                MarginBottomOffset = Convert.ToDouble(ConfigurationManager.AppSettings["marginBottomOffset"])
            };

            return(headerFooterConfig);
        }
        private static void SetHeaderFooter(HeaderFooterType headerFootertype, Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, HeaderFooterConfig headerFooterConfig, string text, int pageNumber, Package package, bool isHeader)
        {
            switch (headerFootertype)
            {
            case HeaderFooterType.Company:
                AddText(page, horizontalAlignment, verticalAlignment, headerFooterConfig, package.CompanyName, isHeader, package);
                break;

            case HeaderFooterType.Copyright:
                AddText(page, horizontalAlignment, verticalAlignment, headerFooterConfig, package.CopyrightText, isHeader, package);
                break;

            case HeaderFooterType.CustomText:
                AddText(page, horizontalAlignment, verticalAlignment, headerFooterConfig, text, isHeader, package);
                break;

            case HeaderFooterType.Date:
                AddText(page, horizontalAlignment, verticalAlignment, headerFooterConfig, DateTime.Now.ToShortDateString(), isHeader, package);
                break;

            case HeaderFooterType.PageNumber:
                if (pageNumber > 0)
                {
                    AddText(page, horizontalAlignment, verticalAlignment, headerFooterConfig, (pageNumber).ToString(CultureInfo.InvariantCulture), isHeader, package);
                }
                break;

            case HeaderFooterType.Logo:
                AddImage(page, horizontalAlignment, verticalAlignment, headerFooterConfig, package.GroupLogo, isHeader, package);
                break;

            default:
                return;
            }
        }
        private static void AddText(Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, HeaderFooterConfig headerFooterConfig, string text, bool isHeader, Package package)
        {
            var pageMargin = GetHeaderFooterMargin(horizontalAlignment, headerFooterConfig, isHeader, package);

            TextStamp textStamp = new TextStamp(text)
            {
                TopMargin           = pageMargin.TopPoints,
                BottomMargin        = pageMargin.BottomPoints,
                LeftMargin          = pageMargin.LeftPoints,
                RightMargin         = pageMargin.RightPoints,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment
            };

            page.AddStamp(textStamp);
        }
        private static Margin GetHeaderFooterMargin(HorizontalAlignment horizontalAlignment, HeaderFooterConfig headerFooterConfig, bool isHeader, Package package)
        {
            var resMargin = new Margin(package.PageSetting.Margin);

            if (horizontalAlignment != HorizontalAlignment.Left)
            {
                resMargin.Left = 0;
            }

            if (horizontalAlignment != HorizontalAlignment.Right)
            {
                resMargin.Right = 0;
            }

            return(resMargin);
        }
        private static void AddImage(Page page, HorizontalAlignment horizontalAlignment, VerticalAlignment verticalAlignment, HeaderFooterConfig headerFooterConfig, GroupLogo groupLogo, bool isHeader, Package package)
        {
            if (groupLogo.ImageStream == null)
            {
                return;
            }

            var pageMargin = GetHeaderFooterMargin(horizontalAlignment, headerFooterConfig, isHeader, package);

            ImageStamp imageStamp = new ImageStamp(groupLogo.ImageStream)
            {
                TopMargin           = pageMargin.TopPoints,
                BottomMargin        = pageMargin.BottomPoints,
                LeftMargin          = pageMargin.LeftPoints,
                RightMargin         = pageMargin.RightPoints,
                HorizontalAlignment = horizontalAlignment,
                VerticalAlignment   = verticalAlignment,
                Width  = groupLogo.ResizedWidth,
                Height = groupLogo.CalculatedHeight > 0 ? groupLogo.CalculatedHeight : groupLogo.Height
            };

            page.AddStamp(imageStamp);
        }