Пример #1
0
        /// <summary>
        /// Returns pdf content based on html content
        /// </summary>
        /// <param name="headerHtml"></param>
        /// <param name="bodyHtml"></param>
        /// <param name="footerHtml"></param>
        /// <param name="templateOption"></param>
        /// <returns></returns>
        public Byte[] CreatePDFBasedOnHTMLTemplate(string headerHtml, string bodyHtml, string footerHtml, TemplateOption templateOption = null)
        {
            string baseUrl = string.Empty;


            HtmlToPdf          htmlToPdfConverter = new HtmlToPdf();
            PdfDocumentControl doc = htmlToPdfConverter.Document;

            doc.FontEmbedding   = true;
            this.templateOption = templateOption;
            if (templateOption != null)
            {
                if (templateOption.PageMargin != null)
                {
                    htmlToPdfConverter.PageLayoutingEvent += htmlToPdfConverter_PageLayoutingEvent;

                    htmlToPdfConverter.Document.Margins = new PdfMargins(templateOption.PageMargin.LeftMargin, templateOption.PageMargin.RightMargin, templateOption.PageMargin.TopMargin, templateOption.PageMargin.BottomMargin);
                }

                // Setting page orientation
                if (templateOption.IsLandscapeOrientation)
                {
                    htmlToPdfConverter.Document.PageOrientation = PdfPageOrientation.Landscape;
                }
            }
            htmlToPdfConverter.SerialNumber = "bad==";

            // set header and footer
            SetHeader(htmlToPdfConverter.Document, headerHtml, baseUrl, templateOption);
            SetFooter(htmlToPdfConverter.Document, footerHtml, baseUrl, templateOption);



            return(htmlToPdfConverter.ConvertHtmlToMemory(bodyHtml, baseUrl));
        }
Пример #2
0
        private void SetFooter(PdfDocumentControl htmlToPdfDocument)
        {
            // enable footer display
            htmlToPdfDocument.Footer.Enabled = true;

            // set footer height
            htmlToPdfDocument.Footer.Height = 50;

            // set footer background color
            htmlToPdfDocument.Footer.BackgroundColor = System.Drawing.Color.WhiteSmoke;

            float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                                 htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

            float footerWidth  = pdfPageWidth - htmlToPdfDocument.Margins.Left - htmlToPdfDocument.Margins.Right;
            float footerHeight = htmlToPdfDocument.Footer.Height;

            // layout HTML in footer
            PdfHtml footerHtml = new PdfHtml(5, 5, @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic"">
                            Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>", null);

            footerHtml.FitDestHeight = true;
            htmlToPdfDocument.Footer.Layout(footerHtml);

            if (m_formCollection["checkBoxDisplayPageNumbersInFooter"].Count > 0)
            {
                if (m_formCollection["checkBoxPageNumbersInHtml"].Count == 0)
                {
                    // add page numbering in a text element
                    System.Drawing.Font pageNumberingFont = new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"),
                                                                                    8, System.Drawing.GraphicsUnit.Point);
                    PdfText pageNumberingText = new PdfText(5, footerHeight - 12, "Page {CrtPage} of {PageCount}", pageNumberingFont);
                    pageNumberingText.HorizontalAlign = PdfTextHAlign.Center;
                    pageNumberingText.EmbedSystemFont = true;
                    pageNumberingText.ForeColor       = System.Drawing.Color.DarkGreen;
                    htmlToPdfDocument.Footer.Layout(pageNumberingText);
                }
                else
                {
                    // add page numbers in HTML - more flexible but less efficient than text version
                    PdfHtmlWithPlaceHolders htmlWithPageNumbers = new PdfHtmlWithPlaceHolders(5, footerHeight - 20,
                                                                                              "Page <span style=\"font-size: 16px; color: blue; font-style: italic; font-weight: bold\">{CrtPage}</span> of <span style=\"font-size: 16px; color: green; font-weight: bold\">{PageCount}</span>", null);
                    htmlToPdfDocument.Footer.Layout(htmlWithPageNumbers);
                }
            }

            string   footerImageFile = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo.png";
            PdfImage logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40, System.Drawing.Image.FromFile(footerImageFile));

            htmlToPdfDocument.Footer.Layout(logoFooterImage);

            // create a border for footer
            PdfRectangle borderRectangle = new PdfRectangle(1, 1, footerWidth - 2, footerHeight - 2);

            borderRectangle.LineStyle.LineWidth = 0.5f;
            borderRectangle.ForeColor           = System.Drawing.Color.DarkGreen;
            htmlToPdfDocument.Footer.Layout(borderRectangle);
        }
Пример #3
0
        private void SetFooter(PdfDocumentControl htmlToPdfDocument, string undercarriageUrl)
        {
            // enable footer display
            htmlToPdfDocument.Footer.Enabled = true;

            // set footer height
            htmlToPdfDocument.Footer.Height = 20;

            // set footer background color
            htmlToPdfDocument.Footer.BackgroundColor = System.Drawing.Color.White;
        }
Пример #4
0
        private void SetFooter(PdfDocumentControl htmlToPdfDocument)
        {
            // enable footer display
            htmlToPdfDocument.Footer.Enabled = checkBoxAddFooter.Checked;

            if (!htmlToPdfDocument.Footer.Enabled)
            {
                return;
            }

            // set footer height
            htmlToPdfDocument.Footer.Height = 50;

            // set footer background color
            htmlToPdfDocument.Footer.BackgroundColor = System.Drawing.Color.WhiteSmoke;

            float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                                 htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

            float footerWidth  = pdfPageWidth - htmlToPdfDocument.Margins.Left - htmlToPdfDocument.Margins.Right;
            float footerHeight = htmlToPdfDocument.Footer.Height;

            // layout HTML in footer
            PdfHtml footerHtml = new PdfHtml(5, 5, @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic"">
                            Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>", null);

            footerHtml.FitDestHeight = true;
            footerHtml.FontEmbedding = checkBoxFontEmbedding.Checked;
            htmlToPdfDocument.Footer.Layout(footerHtml);

            // add page numbering
            System.Drawing.Font pageNumberingFont = new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"),
                                                                            8, System.Drawing.GraphicsUnit.Point);
            PdfText pageNumberingText = new PdfText(5, footerHeight - 12, "Page {CrtPage} of {PageCount}", pageNumberingFont);

            pageNumberingText.HorizontalAlign = PdfTextHAlign.Center;
            pageNumberingText.EmbedSystemFont = true;
            pageNumberingText.ForeColor       = System.Drawing.Color.DarkGreen;
            htmlToPdfDocument.Footer.Layout(pageNumberingText);

            string   footerImageFile = Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo.png";
            PdfImage logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40, System.Drawing.Image.FromFile(footerImageFile));

            htmlToPdfDocument.Footer.Layout(logoFooterImage);

            // create a border for footer
            PdfRectangle borderRectangle = new PdfRectangle(1, 1, footerWidth - 2, footerHeight - 2);

            borderRectangle.LineStyle.LineWidth = 0.5f;
            borderRectangle.ForeColor           = System.Drawing.Color.DarkGreen;
            htmlToPdfDocument.Footer.Layout(borderRectangle);
        }
Пример #5
0
        private static void _setFooter(PdfDocumentControl objPdf, string logoFooterPath, string objFooterHtml,
                                       bool enableRectangleFooterBorder, int footerHeight = 50)
        {
            if (objFooterHtml == null)
            {
                throw new ArgumentNullException("objFooterHtml");
            }
            objPdf.Footer.Enabled         = true; //if (!objPDF.Footer.Enabled) return;
            objPdf.Footer.Height          = footerHeight;
            objPdf.Footer.BackgroundColor = Color.WhiteSmoke;
            var pdfPageWidth = objPdf.PageOrientation == PdfPageOrientation.Portrait
                ? objPdf.PageSize.Width
                : objPdf.PageSize.Height;
            var footerWidth = pdfPageWidth - objPdf.Margins.Left - objPdf.Margins.Right;

            var footerHtml = new PdfHtml(5, 5, objFooterHtml, null)
            {
                FitDestHeight = true
            };

            objPdf.Footer.Layout(footerHtml);
            //footerHtml.FontEmbedding = enableFontEmbedding;
            var pageNumberingFont = new Font(new FontFamily("Times New Roman"), 8, GraphicsUnit.Point);
            var pageNumberingText = new PdfText(5, footerHeight - 12, "Page {CrtPage} of {PageCount}", pageNumberingFont)
            {
                HorizontalAlign = PdfTextHAlign.Right,
                EmbedSystemFont = true,
                ForeColor       = Color.DarkGreen
            };

            objPdf.Footer.Layout(pageNumberingText);
            if (logoFooterPath.Length > 5)
            {
                var logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40, Image.FromFile(logoFooterPath));
                objPdf.Footer.Layout(logoFooterImage);
            }

            if (!enableRectangleFooterBorder)
            {
                return;
            }

            var borderRectangle = new PdfRectangle(1, 1, footerWidth - 2, footerHeight - 2)
            {
                LineStyle = { LineWidth = 0.5f },
                ForeColor = Color.DarkGreen
            };

            objPdf.Footer.Layout(borderRectangle);
        }
Пример #6
0
        /// <summary>
        /// updates the html header based on html content
        /// </summary>
        /// <param name="pdfDocumentControl"></param>
        /// <param name="headerHtml"></param>
        /// <param name="baseUri"></param>
        /// <param name="templateOption"></param>
        private void SetHeader(PdfDocumentControl pdfDocumentControl, string headerHtml, string baseUri, TemplateOption templateOption = null)
        {
            PdfHtml headerPdfHtml = new PdfHtml(headerHtml, baseUri);

            pdfDocumentControl.Header.Enabled = true;
            float pdfPageWidth = 0, headerWidth = 0, headerHeight = 0;

            if (templateOption != null)
            {
                if (templateOption.HeaderHeight.HasValue)
                {
                    pdfDocumentControl.Header.Height = templateOption.HeaderHeight.Value;
                }

                pdfPageWidth = pdfDocumentControl.PageOrientation == PdfPageOrientation.Portrait ?
                               pdfDocumentControl.PageSize.Width : pdfDocumentControl.PageSize.Height;

                headerWidth  = pdfPageWidth - pdfDocumentControl.Margins.Left - pdfDocumentControl.Margins.Right;
                headerHeight = pdfDocumentControl.Header.Height;

                PdfLine leftLine  = new PdfLine(new System.Drawing.PointF(leftStartXPoint, 10), new System.Drawing.PointF(leftStartXPoint, headerHeight));
                PdfLine rightLine = new PdfLine(new System.Drawing.PointF((float)(headerWidth - 2.5), 10), new System.Drawing.PointF((float)(headerWidth - 2.5), headerHeight));
                PdfLine topLine   = new PdfLine(new System.Drawing.PointF(leftStartXPoint, 10), new System.Drawing.PointF((float)(headerWidth - 2.5), 10));

                //Border Color for the PDF
                if (!string.IsNullOrEmpty(templateOption.PageMargin.Color))
                {
                    leftLine.ForeColor  = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    leftLine.BackColor  = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    rightLine.ForeColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    rightLine.BackColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    topLine.ForeColor   = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    topLine.BackColor   = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                }

                pdfDocumentControl.Header.Layout(leftLine);
                pdfDocumentControl.Header.Layout(rightLine);
                pdfDocumentControl.Header.Layout(topLine);
            }
            // add page numbering in a text element
            System.Drawing.Font pageNumberingFont = new System.Drawing.Font(new System.Drawing.FontFamily("Times New Roman"), 8, System.Drawing.GraphicsUnit.Point);
            PdfText             pageNumberingText = new PdfText(headerWidth - 60, 0, "Page {CrtPage} of {PageCount}", pageNumberingFont);

            pageNumberingText.EmbedSystemFont = true;
            pdfDocumentControl.Header.Layout(pageNumberingText);
            pdfDocumentControl.Header.Layout(headerPdfHtml);
        }
        private void SetHeader(PdfDocumentControl htmlToPdfDocument, string fileType)
        {
            // enable header display
            htmlToPdfDocument.Header.Enabled = true;

            // set header height
            htmlToPdfDocument.Header.Height = 95;
            if (fileType == "PHStudyReport")
            {
                float pdfPageWidth =
                    htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                    htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

                float headerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left
                                    - htmlToPdfDocument.Margins.Right;
                float headerHeight = htmlToPdfDocument.Header.Height;

                // set header background color
                //htmlToPdfDocument.Header.BackgroundColor = System.Drawing.Color.WhiteSmoke;


                string   headerImageFile1 = HttpContext.Current.Server.MapPath(Utility.GetAPPSettingKey("ImageFolder") + "PHStudyReport/DrxLogo.jpg");
                PdfImage logoHeaderImage1 = new PdfImage(0, 45, 150, System.Drawing.Image.FromFile(headerImageFile1));
                htmlToPdfDocument.Header.Layout(logoHeaderImage1);

                string   headerImageFile2 = HttpContext.Current.Server.MapPath(Utility.GetAPPSettingKey("ImageFolder") + "PHStudyReport/LeadHunterLogo.jpg");
                PdfImage logoHeaderImage2 = new PdfImage(340, 45, 150, System.Drawing.Image.FromFile(headerImageFile2));
                htmlToPdfDocument.Header.Layout(logoHeaderImage2);

                // layout HTML in header
                //            PdfHtml headerHtml = new PdfHtml(5, 5,
                //                    @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic"">
                //                    Powered by </span><a href=""http://www.DiscoverX.com"">DiscoverX</a>",
                //                    null);
                //            headerHtml.FitDestHeight = true;
                //            htmlToPdfDocument.Header.Layout(headerHtml);

                // create a border for header


                //PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);
                //borderRectangle.LineStyle.LineWidth = 0.5f;
                //borderRectangle.ForeColor = System.Drawing.Color.Navy;
                //htmlToPdfDocument.Header.Layout(borderRectangle);
            }
        }
Пример #8
0
        private void SetHeader(PdfDocumentControl htmlToPdfDocument)
        {
            // enable header display
            htmlToPdfDocument.Header.Enabled = checkBoxAddHeader.Checked;

            if (!htmlToPdfDocument.Header.Enabled)
            {
                return;
            }

            // set header height
            htmlToPdfDocument.Header.Height = 50;

            float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                                 htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

            float headerWidth  = pdfPageWidth - htmlToPdfDocument.Margins.Left - htmlToPdfDocument.Margins.Right;
            float headerHeight = htmlToPdfDocument.Header.Height;

            // set header background color
            htmlToPdfDocument.Header.BackgroundColor = System.Drawing.Color.WhiteSmoke;

            string   headerImageFile = Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo.png";
            PdfImage logoHeaderImage = new PdfImage(5, 5, 40, System.Drawing.Image.FromFile(headerImageFile));

            htmlToPdfDocument.Header.Layout(logoHeaderImage);

            // layout HTML in header
            PdfHtml headerHtml = new PdfHtml(50, 5, @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic"">
                            Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>", null);

            headerHtml.FitDestHeight = true;
            headerHtml.FontEmbedding = checkBoxFontEmbedding.Checked;
            htmlToPdfDocument.Header.Layout(headerHtml);

            // create a border for header

            PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);

            borderRectangle.LineStyle.LineWidth = 0.5f;
            borderRectangle.ForeColor           = System.Drawing.Color.Navy;
            htmlToPdfDocument.Header.Layout(borderRectangle);
        }
Пример #9
0
        /// <summary>
        /// Updates the footer based on html content
        /// </summary>
        /// <param name="pdfDocumentControl"></param>
        /// <param name="footerHtml"></param>
        /// <param name="baseUri"></param>
        /// <param name="templateOption"></param>
        private void SetFooter(PdfDocumentControl pdfDocumentControl, string footerHtml, string baseUri, TemplateOption templateOption = null)
        {
            PdfHtml footerPdfHtml = new PdfHtml(footerHtml, baseUri);

            pdfDocumentControl.Footer.Enabled = true;
            if (templateOption != null)
            {
                if (templateOption.FooterHeight.HasValue)
                {
                    pdfDocumentControl.Footer.Height = templateOption.FooterHeight.Value;
                }

                if (templateOption.PageMargin != null)
                {
                    PageBorder pageBorder = templateOption.PageMargin;

                    float pdfPageWidth = pdfDocumentControl.PageOrientation == PdfPageOrientation.Portrait ?
                                         pdfDocumentControl.PageSize.Width : pdfDocumentControl.PageSize.Height;

                    float footerWidth  = pdfPageWidth - pdfDocumentControl.Margins.Left - pdfDocumentControl.Margins.Right;
                    float footerHeight = pdfDocumentControl.Footer.Height;

                    PdfLine leftLine   = new PdfLine(new System.Drawing.PointF(leftStartXPoint, 0), new System.Drawing.PointF(leftStartXPoint, footerHeight));
                    PdfLine rightLine  = new PdfLine(new System.Drawing.PointF((float)(footerWidth - 2.5), 0), new System.Drawing.PointF((float)(footerWidth - 2.5), footerHeight));
                    PdfLine bottomLine = new PdfLine(new System.Drawing.PointF(leftStartXPoint, footerHeight), new System.Drawing.PointF((float)(footerWidth - 2.5), footerHeight));

                    //Border Color for the PDF
                    if (!string.IsNullOrEmpty(templateOption.PageMargin.Color))
                    {
                        leftLine.ForeColor   = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                        leftLine.BackColor   = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                        rightLine.ForeColor  = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                        rightLine.BackColor  = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                        bottomLine.ForeColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                        bottomLine.BackColor = System.Drawing.Color.FromName(templateOption.PageMargin.Color);
                    }
                    pdfDocumentControl.Footer.Layout(leftLine);
                    pdfDocumentControl.Footer.Layout(rightLine);
                    pdfDocumentControl.Footer.Layout(bottomLine);
                }
            }
            pdfDocumentControl.Footer.Layout(footerPdfHtml);
        }
Пример #10
0
        private static void _setHeader(PdfDocumentControl objPdf, string logoHeaderPath, string objHeaderHtml,
                                       bool enableRectangleHeaderBorder, int headerHeight = 50)
        {
            if (objHeaderHtml == null)
            {
                throw new ArgumentNullException("objHeaderHtml");
            }
            objPdf.Header.Enabled = true; //  if (!objPDF.Header.Enabled) return;
            objPdf.Header.Height  = headerHeight;
            var pdfPageWidth = objPdf.PageOrientation == PdfPageOrientation.Portrait
                ? objPdf.PageSize.Width
                : objPdf.PageSize.Height;
            var headerWidth = pdfPageWidth - objPdf.Margins.Left - objPdf.Margins.Right;

            // float headerHeight = objPDF.Header.Height;
            objPdf.Header.BackgroundColor = Color.WhiteSmoke;
            if (logoHeaderPath.Length > 5)
            {
                var logoHeaderImage = new PdfImage(5, 5, 40, Image.FromFile(logoHeaderPath));
                objPdf.Header.Layout(logoHeaderImage);
            }

            /* @"<span style=""color:Navy; font-family:Times New Roman; font-style:italic"">
             *          Quickly Create High Quality PDFs with </span><a href=""http://www.hiqpdf.com"">HiQPdf</a>",*/
            var headerHtml = new PdfHtml(50, 5, objHeaderHtml, null)
            {
                FitDestHeight = true
            };

            objPdf.Header.Layout(headerHtml); //headerHtml.FontEmbedding = true;
            if (!enableRectangleHeaderBorder)
            {
                return;
            }
            var borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2)
            {
                LineStyle = { LineWidth = 0.5f },
                ForeColor = Color.Navy
            };

            objPdf.Header.Layout(borderRectangle);
        }
 //private void SetHeader(PdfDocumentControl htmlToPdfDocument, header header)
 //{
 //    // enable header display
 //    htmlToPdfDocument.Header.Enabled = true;
 //    // set header height
 //    htmlToPdfDocument.Header.Height = header.height;
 //    float pdfPageWidth =
 //        htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
 //                htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;
 //    float headerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left
 //                - htmlToPdfDocument.Margins.Right;
 //    float headerHeight = htmlToPdfDocument.Header.Height;
 //    PdfHtml headerHtml = new PdfHtml(0, 0, header.url);
 //    headerHtml.FitDestHeight = true;
 //    htmlToPdfDocument.Header.Layout(headerHtml);
 //    //PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);
 //    //borderRectangle.LineStyle.LineWidth = 0.5f;
 //    ////borderRectangle.ForeColor = System.Drawing.Color.Navy;
 //    //htmlToPdfDocument.Header.Layout(borderRectangle);
 //}
 //private void SetHeader(PdfDocumentControl htmlToPdfDocument, headerHtml header)
 //{
 //    // enable header display
 //    htmlToPdfDocument.Header.Enabled = true;
 //    // set header height
 //    htmlToPdfDocument.Header.Height = header.height;
 //    float pdfPageWidth =
 //        htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
 //                htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;
 //    float headerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left
 //                - htmlToPdfDocument.Margins.Right;
 //    float headerHeight = htmlToPdfDocument.Header.Height;
 //    PdfHtml headerHtml = new PdfHtml(0, 0, header.html, "");
 //    headerHtml.FitDestHeight = true;
 //    htmlToPdfDocument.Header.Layout(headerHtml);
 //    //PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);
 //    //borderRectangle.LineStyle.LineWidth = 0.5f;
 //    ////borderRectangle.ForeColor = System.Drawing.Color.Navy;
 //    //htmlToPdfDocument.Header.Layout(borderRectangle);
 //}
 private void SetHeader(PdfDocumentControl htmlToPdfDocument)
 {
     // enable header display
     htmlToPdfDocument.Header.Enabled = true;
     // set header height
     htmlToPdfDocument.Header.Height = 50;
     float pdfPageWidth =
         htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                 htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;
     float headerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left
                 - htmlToPdfDocument.Margins.Right;
     float headerHeight = htmlToPdfDocument.Header.Height;
     PdfHtml headerHtml = new PdfHtml(0, 0, "http://localhost:1579/Html/Header");
     headerHtml.FitDestHeight = true;
     htmlToPdfDocument.Header.Layout(headerHtml);
     //PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);
     //borderRectangle.LineStyle.LineWidth = 0.5f;
     ////borderRectangle.ForeColor = System.Drawing.Color.Navy;
     //htmlToPdfDocument.Header.Layout(borderRectangle);
 }
        private void SetFooter(PdfDocumentControl htmlToPdfDocument)
        {
            // enable footer display
            htmlToPdfDocument.Footer.Enabled = true;

            // set footer height
            htmlToPdfDocument.Footer.Height = 15;
            // set footer background color
            htmlToPdfDocument.Footer.BackgroundColor = System.Drawing.Color.WhiteSmoke;

            float pdfPageWidth = htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                    htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

            float footerWidth = pdfPageWidth - htmlToPdfDocument.Margins.Left -
                        htmlToPdfDocument.Margins.Right;
            float footerHeight = htmlToPdfDocument.Footer.Height;

            // layout HTML in footer
            if (String.IsNullOrEmpty(TituloSistema)) TituloSistema = "";
            if (String.IsNullOrEmpty(PiePagina)) PiePagina = "{0} {1} {2}";
            if (String.IsNullOrEmpty(NombreCompleto)) NombreCompleto = "";
            PdfHtml footerHtml = new PdfHtml(5, 0,
                    String.Format(PiePagina, TituloSistema, NombreCompleto, DateTime.Now), null);
            footerHtml.FitDestHeight = true;
            htmlToPdfDocument.Footer.Layout(footerHtml);

            // add page numbering
            System.Drawing.Font pageNumberingFont =
                            new System.Drawing.Font(
                            new System.Drawing.FontFamily("Times New Roman"),
                            7, System.Drawing.GraphicsUnit.Point);
            PdfText pageNumberingText = new PdfText(footerWidth - 100, 6,
                            "Página {CrtPage} de {PageCount}", pageNumberingFont);
            pageNumberingText.HorizontalAlign = PdfTextHAlign.Center;
            pageNumberingText.EmbedSystemFont = true;
            pageNumberingText.ForeColor = System.Drawing.Color.Gray;
            htmlToPdfDocument.Footer.Layout(pageNumberingText);
        }
        private void SetFooter(PdfDocumentControl htmlToPdfDocument, string fileType = "PriceList")
        {
            // enable footer display
            htmlToPdfDocument.Footer.Enabled = true;

            // set footer height
            htmlToPdfDocument.Footer.Height = 45;

            // set footer background color
            //htmlToPdfDocument.Footer.BackgroundColor = System.Drawing.Color.WhiteSmoke;

            float pdfPageWidth =
                htmlToPdfDocument.PageOrientation == PdfPageOrientation.Portrait ?
                htmlToPdfDocument.PageSize.Width : htmlToPdfDocument.PageSize.Height;

            float footerWidth  = pdfPageWidth - htmlToPdfDocument.Margins.Left - htmlToPdfDocument.Margins.Right;
            float footerHeight = htmlToPdfDocument.Footer.Height;



            Font pageNumberingFont =
                new Font(new System.Drawing.FontFamily("Verdana"),
                         8, System.Drawing.GraphicsUnit.Point);

            if (fileType == "PHStudyReport")
            {
                htmlToPdfDocument.Footer.Layout(new PdfHtml(0, 10, "<a href=\"http://www.discoverx.com\" style=\"font-family:Arial; font-size:16px; color:black; text-decoration:none\">http://www.discoverx.com</a>", null));
            }
            else
            {
                string   logoImageFile = HttpContext.Current.Server.MapPath(Utility.GetAPPSettingKey("ImageFolder") + "PDFCover/DRx_logo_2013.png");
                PdfImage logoImage     = new PdfImage(5, 5, 40, Image.FromFile(logoImageFile));
                htmlToPdfDocument.Footer.Layout(logoImage);
                htmlToPdfDocument.Footer.Layout(new PdfHtml(0, 10, "<a href=\"http://www.discoverx.com\" style=\"font-family:Verdana; font-size:9px; color:black; text-decoration:none\">http://www.discoverx.com</a>", null));
            }
            string footerStr = string.Empty;

            if (fileType == "PriceList")
            {
                footerStr = PRICE_LIST_FOOTER;
            }
            else if (fileType == "TargetList")
            {
                footerStr = TARGET_LIST_FOOTER;
            }
            else if (fileType == "PHStudyReport")
            {
                footerStr = PHSTUDY_REPORT_FOOTER;
            }

            // layout HTML in footer
            //footerHtml.FitDestHeight = true;
            PdfText centerText = new PdfText(5, 10,
                                             footerStr, pageNumberingFont);

            centerText.HorizontalAlign = PdfTextHAlign.Center;
            centerText.EmbedSystemFont = true;
            centerText.ForeColor       = System.Drawing.Color.Black;
            htmlToPdfDocument.Footer.Layout(centerText);
            //htmlToPdfDocument.Footer.Layout(new PdfHtml(200, 5, footerStr, null));

            PdfText rightText;

            if (fileType == "PHStudyReport")
            {
                rightText = new PdfText(5, 10,
                                        string.Format("{0}", DateTime.Now.ToShortDateString()), pageNumberingFont);
            }
            else
            {
                rightText = new PdfText(5, 10,
                                        string.Format("Q{0} - {1}", DateTime.Now.GetQuarter(), DateTime.Now.Year), pageNumberingFont);
            }
            rightText.HorizontalAlign = PdfTextHAlign.Right;
            rightText.EmbedSystemFont = true;
            rightText.ForeColor       = System.Drawing.Color.Black;
            htmlToPdfDocument.Footer.Layout(rightText);
            //htmlToPdfDocument.Footer.Layout(new PdfHtml(500, 5, 80, 6, footerStr, null));

            // add page numbering in a text element

            PdfText pageNumberingText = new PdfText(5, footerHeight - 25,
                                                    "{CrtPage}", pageNumberingFont);

            pageNumberingText.HorizontalAlign = PdfTextHAlign.Center;
            pageNumberingText.EmbedSystemFont = true;
            pageNumberingText.ForeColor       = System.Drawing.Color.Black;
            htmlToPdfDocument.Footer.Layout(pageNumberingText);

            /*
             * string footerImageFile = Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo.png";
             * PdfImage logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40,
             *          System.Drawing.Image.FromFile(footerImageFile));
             * htmlToPdfDocument.Footer.Layout(logoFooterImage);
             */

            /*
             * // create a border for footer
             * PdfRectangle borderRectangle = new PdfRectangle(1, 1, footerWidth - 2, footerHeight - 2);
             * borderRectangle.LineStyle.LineWidth = 0.5f;
             * borderRectangle.ForeColor = System.Drawing.Color.DarkGreen;
             * htmlToPdfDocument.Footer.Layout(borderRectangle);
             */
        }