private void SetHeader(PdfDocument document)
        {
            if (m_formCollection["checkBoxAddHeader"].Count > 0)
            {
                return;
            }

            // create the document header
            document.CreateHeaderCanvas(50);

            // add PDF objects to the header canvas
            string   headerImageFile = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo.png";
            PdfImage logoHeaderImage = new PdfImage(5, 5, 40, System.Drawing.Image.FromFile(headerImageFile));

            document.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 = true;
            document.Header.Layout(headerHtml);

            // create a border for header
            float        headerWidth     = document.Header.Width;
            float        headerHeight    = document.Header.Height;
            PdfRectangle borderRectangle = new PdfRectangle(1, 1, headerWidth - 2, headerHeight - 2);

            borderRectangle.LineStyle.LineWidth = 0.5f;
            borderRectangle.ForeColor           = System.Drawing.Color.Navy;
            document.Header.Layout(borderRectangle);
        }
        public ActionResult ConvertToPdf(IFormCollection collection)
        {
            m_formCollection = collection;

            // create an empty PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // add a page to document
            PdfPage page1 = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(5), PdfPageOrientation.Portrait);

            try
            {
                // set the document header and footer before adding any objects to document
                SetHeader(document);
                SetFooter(document);

                // layout the HTML from URL 1
                PdfHtml html1 = new PdfHtml(collection["textBoxUrl1"]);
                html1.WaitBeforeConvert = 2;
                PdfLayoutInfo html1LayoutInfo = page1.Layout(html1);

                // determine the PDF page where to add URL 2
                PdfPage page2 = null;
                System.Drawing.PointF location2 = System.Drawing.PointF.Empty;
                if (collection["checkBoxNewPage"].Count > 0)
                {
                    // URL 2 is laid out on a new page with the selected orientation
                    page2     = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(5), GetSelectedPageOrientation());
                    location2 = System.Drawing.PointF.Empty;
                }
                else
                {
                    // URL 2 is laid out immediately after URL 1 and html1LayoutInfo
                    // gives the location where the URL 1 layout finished
                    page2     = document.Pages[html1LayoutInfo.LastPageIndex];
                    location2 = new System.Drawing.PointF(html1LayoutInfo.LastPageRectangle.X, html1LayoutInfo.LastPageRectangle.Bottom);
                }

                // layout the HTML from URL 2
                PdfHtml html2 = new PdfHtml(location2.X, location2.Y, collection["textBoxUrl2"]);
                html2.WaitBeforeConvert = 2;
                page2.Layout(html2);

                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "LayoutMultipleHtml.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 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);
        }
        private void SetFooter(PdfDocument document)
        {
            if (m_formCollection["checkBoxAddFooter"].Count > 0)
            {
                return;
            }

            //create the document footer
            document.CreateFooterCanvas(50);

            // 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 = true;
            document.Footer.Layout(footerHtml);


            float footerHeight = document.Footer.Height;
            float footerWidth  = document.Footer.Width;

            // 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;
            document.Footer.Layout(pageNumberingText);

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

            document.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;
            document.Footer.Layout(borderRectangle);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
 public PdfDocument Html2PdfDoc(string html, PdfPageSize size)
 {
     try
     {
         var document = new PdfDocument {
             SerialNumber = SERIAL_NUMBER, Security = { AllowEditContent = false, AllowCopyContent = false }
         };
         var page = document.AddPage(size, new PdfDocumentMargins(0, 0, 0, 0), PdfPageOrientation.Landscape);
         page.DisplayFooter = false;
         page.DisplayHeader = false;
         //var page = document.AddPage(new PdfPageSize(640,455), new PdfDocumentMargins(4,4, 4,4));
         var pageHtml = new PdfHtml(html, Utils.BaseUrl());
         page.Layout(pageHtml);
         return(document);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Ejemplo n.º 12
0
        void htmlToPdfConverter_PageCreatingEvent(PdfPageCreatingParams eventParams)
        {
            PdfPage pdfPage       = eventParams.PdfPage;
            int     pdfPageNumber = eventParams.PdfPageNumber;

            if (pdfPageNumber == 1)
            {
                // set the header and footer visibility in first page
                pdfPage.DisplayHeader = m_formCollection["checkBoxDisplayHeaderInFirstPage"].Count > 0;
                pdfPage.DisplayFooter = m_formCollection["checkBoxDisplayFooterInFirstPage"].Count > 0;
            }
            else if (pdfPageNumber == 2)
            {
                // set the header and footer visibility in second page
                pdfPage.DisplayHeader = m_formCollection["checkBoxDisplayHeaderInSecondPage"].Count > 0;
                pdfPage.DisplayFooter = m_formCollection["checkBoxDisplayFooterInSecondPage"].Count > 0;

                if (pdfPage.DisplayHeader && m_formCollection["checkBoxCustomizedHeaderInSecondPage"].Count > 0)
                {
                    // override the default document header in this page
                    // with a customized header of 200 points in height
                    pdfPage.CreateHeaderCanvas(200);

                    // layout a HTML document in header
                    PdfHtml htmlInHeader = new PdfHtml("http://www.hiqpdf.com");
                    htmlInHeader.FitDestHeight = true;
                    pdfPage.Header.Layout(htmlInHeader);

                    // create a border for the customized header
                    PdfRectangle borderRectangle = new PdfRectangle(0, 0, pdfPage.Header.Width - 1, pdfPage.Header.Height - 1);
                    borderRectangle.LineStyle.LineWidth = 0.5f;
                    borderRectangle.ForeColor           = System.Drawing.Color.Navy;
                    pdfPage.Header.Layout(borderRectangle);
                }
            }
        }
        private void SetFooter(PdfDocument document, string fileName = "")
        {
            //create the document footer
            document.CreateFooterCanvas(45);

            string   logoImageFile = HttpContext.Current.Server.MapPath(Utility.GetAPPSettingKey("ImageFolder") + "PDFCover/DRx_logo_2013.png");
            PdfImage logoImage     = new PdfImage(5, 5, 40, Image.FromFile(logoImageFile));

            document.Footer.Layout(logoImage);

            Font pageFooterFont =
                new Font(new System.Drawing.FontFamily("Verdana"),
                         5, System.Drawing.GraphicsUnit.Point);

            document.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 (fileName == "DRx_Price_List_")
            {
                footerStr = PRICE_LIST_FOOTER;
            }
            else if (fileName == "DRx_Target_List_")
            {
                footerStr = TARGET_LIST_FOOTER;
            }


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

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

            PdfText rightText = new PdfText(10, 15,
                                            string.Format("Q{0} - {1}", DateTime.Now.GetQuarter(), DateTime.Now.Year), pageFooterFont);

            rightText.HorizontalAlign = PdfTextHAlign.Right;
            rightText.EmbedSystemFont = true;
            rightText.ForeColor       = System.Drawing.Color.Black;
            document.Footer.Layout(rightText);
            // layout HTML in footer
            PdfHtml footerHtml = new PdfHtml(5, 5, footerStr, null);

            footerHtml.FitDestHeight = true;
            footerHtml.FontEmbedding = true;
            document.Footer.Layout(footerHtml);


            float footerHeight = document.Footer.Height;
            float footerWidth  = document.Footer.Width;

            // add page numbering
            Font pageNumberFont = new Font(new FontFamily("Verdana"), 6, GraphicsUnit.Point);
            //pageNumberingFont.Mea

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

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

            //string footerImageFile = Application.StartupPath + @"\DemoFiles\Images\HiQPdfLogo.png";
            //PdfImage logoFooterImage = new PdfImage(footerWidth - 40 - 5, 5, 40, Image.FromFile(footerImageFile));
            //document.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 = Color.DarkGreen;
            //document.Footer.Layout(borderRectangle);
        }
Ejemplo n.º 14
0
        public ActionResult CreatePdf(IFormCollection collection)
        {
            m_formCollection = collection;

            // create an empty PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set encryption mode
            document.Security.EncryptionMode = GetSelectedEncryptionMode();
            // set encryption level
            document.Security.EncryptionLevel = GetSelectedEncryptionLevel();

            // set open password
            document.Security.OpenPassword = collection["textBoxOpenPassword"];
            // set permissions password
            document.Security.PermissionsPassword = collection["textBoxPermissionsPassword"];

            // set PDF document permissions
            document.Security.AllowPrinting        = collection["checkBoxAllowPrint"].Count > 0;
            document.Security.AllowCopyContent     = collection["checkBoxAllowCopy"].Count > 0;
            document.Security.AllowEditContent     = collection["checkBoxAllowEdit"].Count > 0;
            document.Security.AllowEditAnnotations = collection["checkBoxAllowEditAnnotations"].Count > 0;
            document.Security.AllowFormFilling     = collection["checkBoxAllowFillForms"].Count > 0;

            // set a default permissions password if an open password was set without settings a permissions password
            // or if any of the permissions does not have the default value
            if (document.Security.PermissionsPassword == String.Empty &&
                (document.Security.OpenPassword != String.Empty || !IsDefaultPermission(document.Security)))
            {
                document.Security.PermissionsPassword = "******";
            }

            // add a page to document with the default size and orientation
            PdfPage page1 = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(0), PdfPageOrientation.Portrait);

            // an object to be set with HTML layout info after conversion
            PdfLayoutInfo htmlLayoutInfo = null;

            try
            {
                // create the HTML object from URL
                PdfHtml htmlObject = new PdfHtml(collection["textBoxUrl"]);

                // optionally wait an additional time before starting the conversion
                htmlObject.WaitBeforeConvert = 2;

                // layout the HTML object in PDF
                htmlLayoutInfo = page1.Layout(htmlObject);

                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "PdfDocumentSecuritySettings.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
        public ActionResult CreatePdf(IFormCollection collection)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create a page in document
            PdfPage page1 = document.AddPage();

            // set a background color for the page
            PdfRectangle backgroundRectangle = new PdfRectangle(page1.DrawableRectangle);

            backgroundRectangle.BackColor = System.Drawing.Color.WhiteSmoke;
            page1.Layout(backgroundRectangle);

            // create the true type fonts that can be used in document text
            System.Drawing.Font sysFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             pdfFont      = document.CreateFont(sysFont);
            PdfFont             pdfFontEmbed = document.CreateFont(sysFont, true);

            float crtYPos = 20;
            float crtXPos = 5;

            #region Layout transparent image

            PdfText titleTextTransImage = new PdfText(crtXPos, crtYPos,
                                                      "PNG image with alpha transparency:", pdfFontEmbed);
            titleTextTransImage.ForeColor = System.Drawing.Color.Navy;
            PdfLayoutInfo textLayoutInfo = page1.Layout(titleTextTransImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage      transparentPdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            PdfLayoutInfo imageLayoutInfo     = page1.Layout(transparentPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout resized transparent image

            PdfText titleTextTransImageResized = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is resized:", pdfFontEmbed);
            titleTextTransImageResized.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageResized);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage transparentResizedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            imageLayoutInfo = page1.Layout(transparentResizedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout rotated transparent image

            PdfText titleTextTransImageRotated = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is rotated 180 degrees counter clockwise:", pdfFontEmbed);
            titleTextTransImageRotated.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageRotated);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // rotate the PNG image with alpha transparency 180 degrees counter clockwise
            PdfImage transparentRotatedPdfImage = new PdfImage(0, 0, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            // translate the coordinates system to image location
            transparentRotatedPdfImage.SetTranslation(crtXPos, crtYPos);
            // rotate the coordinates system counter clockwise
            transparentRotatedPdfImage.SetRotationAngle(180);
            // translate back the coordinates system
            transparentRotatedPdfImage.SetTranslation(-50, -50);

            imageLayoutInfo = page1.Layout(transparentRotatedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += 50 + 10;

            #endregion

            #region Layout clipped transparent image

            PdfText titleTextTransClippedImage = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is clipped:", pdfFontEmbed);
            titleTextTransClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped PNG image with alpha transparency
            PdfImage transparentClippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            transparentClippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(transparentClippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += transparentClippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout JPEG image

            PdfText titleTextOpaqueImage = new PdfText(crtXPos, crtYPos, "The JPG image below is opaque:", pdfFontEmbed);
            titleTextOpaqueImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextOpaqueImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image
            PdfImage opaquePdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");

            imageLayoutInfo = page1.Layout(opaquePdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout clipped JPEG image

            PdfText titleTextClippedImage = new PdfText(crtXPos, crtYPos, "The JPG image below is clipped:", pdfFontEmbed);
            titleTextClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped image
            PdfImage clippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");
            clippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(clippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += clippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout a vectorial SVG image

            PdfText titleTextSvgImage = new PdfText(crtXPos, crtYPos, "Vectorial SVG image:", pdfFontEmbed);
            titleTextSvgImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextSvgImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string svgImageCode = System.IO.File.ReadAllText(m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Svg\SvgImage.svg");

            PdfHtml       svgImage      = new PdfHtml(crtXPos, crtYPos, svgImageCode, null);
            PdfLayoutInfo svgLayoutInfo = page1.Layout(svgImage);

            // advance the Y position in the PDF page
            crtYPos += svgImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            #region Layout JPEG image on multiple pages

            PdfText titleTexMultiPageImage = new PdfText(crtXPos, crtYPos, "The JPG image below is laid out on 2 pages:", pdfFontEmbed);
            titleTexMultiPageImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTexMultiPageImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image on 2 pages
            PdfImage paginatedPdfImage = new PdfImage(crtXPos, crtYPos, m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Images\HiQPdfLogo_big.jpg");

            imageLayoutInfo = page1.Layout(paginatedPdfImage);

            #endregion

            // get the last page
            PdfPage crtPage = document.Pages[imageLayoutInfo.LastPageIndex];
            crtYPos = imageLayoutInfo.LastPageRectangle.Bottom + 10;

            #region Layout the screenshot of a HTML document

            PdfText titleTextHtmlImage = new PdfText(crtXPos, crtYPos, "HTML document screenshot:", pdfFontEmbed);
            titleTextHtmlImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = crtPage.Layout(titleTextHtmlImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string htmlFile = m_hostingEnvironment.ContentRootPath + @"\wwwroot" + @"\DemoFiles\Html\Logo.Html";

            PdfHtmlImage htmlRasterImage = new PdfHtmlImage(crtXPos, crtYPos, htmlFile);
            htmlRasterImage.BrowserWidth = 400;
            PdfLayoutInfo htmlLayoutInfo = crtPage.Layout(htmlRasterImage);

            // advance the Y position in the PDF page
            crtYPos += htmlRasterImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "PdfImages.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
        public ActionResult CreatePdf(FormCollection collection)
        {
            // the path PDF document to edit
            string pdfDocumentToEdit = Server.MapPath("~") + @"\DemoFiles\Pdf\WikiPdf.pdf";

            // load the PDF document to edit
            PdfDocument document = PdfDocument.FromFile(pdfDocumentToEdit);

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            #region Add an orange border to each page of the loaded PDF document

            // add an orange border to each PDF page in the loaded PDF document
            foreach (PdfPage pdfPage in document.Pages)
            {
                float crtPdfPageWidth  = pdfPage.Size.Width;
                float crtPdfPageHeight = pdfPage.Size.Height;

                // create a PdfRectangle object
                PdfRectangle pdfRectangle = new PdfRectangle(2, 2, crtPdfPageWidth - 4, crtPdfPageHeight - 4);
                pdfRectangle.LineStyle.LineWidth = 2;
                pdfRectangle.ForeColor           = System.Drawing.Color.OrangeRed;

                // layout the rectangle in PDF page
                pdfPage.Layout(pdfRectangle);
            }

            #endregion Add an orange border to each page of the loaded PDF document

            #region Layout HTML in a canvas to be repeated on each page of the loaded PDF document

            PdfPage pdfPage1      = document.Pages[0];
            float   pdfPageWidth  = pdfPage1.Size.Width;
            float   pdfPageHeight = pdfPage1.Size.Height;

            // the width of the HTML logo in pixels
            int htmlLogoWidthPx = 400;
            // the width of the HTML logo in points
            float htmlLogoWidthPt  = PdfDpiTransform.FromPixelsToPoints(htmlLogoWidthPx);
            float htmlLogoHeightPt = 100;

            // create a canvas to be repeated in the center of each PDF page
            // the canvas is a PDF container that can contain PDF objects ( HTML, text, images, etc )
            PdfRepeatCanvas repeatedCanvas = document.CreateRepeatedCanvas(new System.Drawing.RectangleF((pdfPageWidth - htmlLogoWidthPt) / 2, (pdfPageHeight - htmlLogoHeightPt) / 2,
                                                                                                         htmlLogoWidthPt, htmlLogoHeightPt));

            // the HTML file giving the content to be placed in the repeated canvas
            string htmlFile = Server.MapPath("~") + @"\DemoFiles\Html\Logo.Html";

            // the HTML object to be laid out in repeated canvas
            PdfHtml htmlLogo = new PdfHtml(0, 0, repeatedCanvas.Width, repeatedCanvas.Height, htmlFile);
            // the browser width when rendering the HTML
            htmlLogo.BrowserWidth = htmlLogoWidthPx;
            // the HTML content will fit the destination hight which is the same with repeated canvas height
            htmlLogo.FitDestHeight = true;

            // layout the HTML object in the repeated canvas
            PdfLayoutInfo htmlLogLayoutInfo = repeatedCanvas.Layout(htmlLogo);

            #endregion Layout HTML in a canvas to be repeated on each page of the loaded PDF document

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "EditPdf.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
Ejemplo n.º 17
0
        public ActionResult CreatePdf(FormCollection collection)
        {
            // create an empty PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // add a page to document
            PdfPage page1 = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(0), PdfPageOrientation.Portrait);

            // an object to be set with HTML layout info after conversion
            PdfLayoutInfo htmlLayoutInfo = null;

            try
            {
                // create the HTML object from URL or HTML code
                PdfHtml htmlObject = null;
                if (collection["UrlOrHtmlCode"] == "radioButtonConvertUrl")
                {
                    // create from URL
                    htmlObject = new PdfHtml(collection["textBoxUrl"]);
                }
                else
                {
                    // create from HTML code
                    string htmlCode = collection["textBoxHtmlCode"];
                    string baseUrl  = collection["textBoxBaseUrl"];

                    htmlObject = new PdfHtml(htmlCode, baseUrl);
                }

                // set the HTML object start location in PDF page
                htmlObject.DestX = float.Parse(collection["textBoxDestX"]);
                htmlObject.DestY = float.Parse(collection["textBoxDestY"]);

                // set the HTML object width in PDF
                if (collection["textBoxDestWidth"].Length > 0)
                {
                    htmlObject.DestWidth = float.Parse(collection["textBoxDestWidth"]);
                }

                // set the HTML object height in PDF
                if (collection["textBoxDestHeight"].Length > 0)
                {
                    htmlObject.DestHeight = float.Parse(collection["textBoxDestHeight"]);
                }

                // optionally wait an additional time before starting the conversion
                htmlObject.WaitBeforeConvert = 2;

                // set browser width
                htmlObject.BrowserWidth = int.Parse(collection["textBoxBrowserWidth"]);

                // set browser height if specified, otherwise use the default
                if (collection["textBoxBrowserHeight"].Length > 0)
                {
                    htmlObject.BrowserHeight = int.Parse(collection["textBoxBrowserHeight"]);
                }

                // set HTML load timeout
                htmlObject.HtmlLoadedTimeout = int.Parse(collection["textBoxLoadHtmlTimeout"]);

                // layout the HTML object in PDF
                htmlLayoutInfo = page1.Layout(htmlObject);

                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                FileResult fileResult = new FileContentResult(pdfBuffer, "application/pdf");
                fileResult.FileDownloadName = "PdfHtmlObjects.pdf";

                return(fileResult);
            }
            finally
            {
                document.Close();
            }
        }
 //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);
        }
Ejemplo n.º 20
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // the path PDF document to edit
            string pdfDocumentToEdit = Server.MapPath("~") + @"\DemoFiles\Pdf\WikiPdf.pdf";

            // load the PDF document to edit
            PdfDocument document = PdfDocument.FromFile(pdfDocumentToEdit);

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            #region Add an orange border to each page of the loaded PDF document

            // add an orange border to each PDF page in the loaded PDF document
            foreach (PdfPage pdfPage in document.Pages)
            {
                float crtPdfPageWidth  = pdfPage.Size.Width;
                float crtPdfPageHeight = pdfPage.Size.Height;

                // create a PdfRectangle object
                PdfRectangle pdfRectangle = new PdfRectangle(2, 2, crtPdfPageWidth - 4, crtPdfPageHeight - 4);
                pdfRectangle.LineStyle.LineWidth = 2;
                pdfRectangle.ForeColor           = System.Drawing.Color.OrangeRed;

                // layout the rectangle in PDF page
                pdfPage.Layout(pdfRectangle);
            }

            #endregion Add an orange border to each page of the loaded PDF document

            #region Layout HTML in a canvas to be repeated on each page of the loaded PDF document

            PdfPage pdfPage1      = document.Pages[0];
            float   pdfPageWidth  = pdfPage1.Size.Width;
            float   pdfPageHeight = pdfPage1.Size.Height;

            // the width of the HTML logo in pixels
            int htmlLogoWidthPx = 400;
            // the width of the HTML logo in points
            float htmlLogoWidthPt  = PdfDpiTransform.FromPixelsToPoints(htmlLogoWidthPx);
            float htmlLogoHeightPt = 100;

            // create a canvas to be repeated in the center of each PDF page
            // the canvas is a PDF container that can contain PDF objects ( HTML, text, images, etc )
            PdfRepeatCanvas repeatedCanvas = document.CreateRepeatedCanvas(new System.Drawing.RectangleF((pdfPageWidth - htmlLogoWidthPt) / 2, (pdfPageHeight - htmlLogoHeightPt) / 2,
                                                                                                         htmlLogoWidthPt, htmlLogoHeightPt));

            // the HTML file giving the content to be placed in the repeated canvas
            string htmlFile = Server.MapPath("~") + @"\DemoFiles\Html\Logo.Html";

            // the HTML object to be laid out in repeated canvas
            PdfHtml htmlLogo = new PdfHtml(0, 0, repeatedCanvas.Width, repeatedCanvas.Height, htmlFile);
            // the browser width when rendering the HTML
            htmlLogo.BrowserWidth = htmlLogoWidthPx;
            // the HTML content will fit the destination hight which is the same with repeated canvas height
            htmlLogo.FitDestHeight = true;

            // layout the HTML object in the repeated canvas
            PdfLayoutInfo htmlLogLayoutInfo = repeatedCanvas.Layout(htmlLogo);

            #endregion Layout HTML in a canvas to be repeated on each page of the loaded PDF document

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=EditPdf.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
Ejemplo n.º 21
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // create a PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // create a page in document
            PdfPage page1 = document.AddPage();

            // set a background color for the page
            PdfRectangle backgroundRectangle = new PdfRectangle(page1.DrawableRectangle);

            backgroundRectangle.BackColor = System.Drawing.Color.WhiteSmoke;
            page1.Layout(backgroundRectangle);

            // create the true type fonts that can be used in document text
            System.Drawing.Font sysFont      = new System.Drawing.Font("Times New Roman", 10, System.Drawing.GraphicsUnit.Point);
            PdfFont             pdfFont      = document.CreateFont(sysFont);
            PdfFont             pdfFontEmbed = document.CreateFont(sysFont, true);

            float crtYPos = 20;
            float crtXPos = 5;

            #region Layout transparent image

            PdfText titleTextTransImage = new PdfText(crtXPos, crtYPos,
                                                      "PNG image with alpha transparency:", pdfFontEmbed);
            titleTextTransImage.ForeColor = System.Drawing.Color.Navy;
            PdfLayoutInfo textLayoutInfo = page1.Layout(titleTextTransImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage      transparentPdfImage = new PdfImage(crtXPos, crtYPos, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            PdfLayoutInfo imageLayoutInfo     = page1.Layout(transparentPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout resized transparent image

            PdfText titleTextTransImageResized = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is resized:", pdfFontEmbed);
            titleTextTransImageResized.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageResized);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a PNG image with alpha transparency
            PdfImage transparentResizedPdfImage = new PdfImage(crtXPos, crtYPos, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            imageLayoutInfo = page1.Layout(transparentResizedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout rotated transparent image

            PdfText titleTextTransImageRotated = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is rotated 180 degrees counter clockwise:", pdfFontEmbed);
            titleTextTransImageRotated.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransImageRotated);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // rotate the PNG image with alpha transparency 180 degrees counter clockwise
            PdfImage transparentRotatedPdfImage = new PdfImage(0, 0, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            // translate the coordinates system to image location
            transparentRotatedPdfImage.SetTranslation(crtXPos, crtYPos);
            // rotate the coordinates system counter clockwise
            transparentRotatedPdfImage.SetRotationAngle(180);
            // translate back the coordinates system
            transparentRotatedPdfImage.SetTranslation(-50, -50);

            imageLayoutInfo = page1.Layout(transparentRotatedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += 50 + 10;

            #endregion

            #region Layout clipped transparent image

            PdfText titleTextTransClippedImage = new PdfText(crtXPos, crtYPos,
                                                             "The transparent PNG image below is clipped:", pdfFontEmbed);
            titleTextTransClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextTransClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped PNG image with alpha transparency
            PdfImage transparentClippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.png");
            transparentClippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(transparentClippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += transparentClippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout JPEG image

            PdfText titleTextOpaqueImage = new PdfText(crtXPos, crtYPos, "The JPG image below is opaque:", pdfFontEmbed);
            titleTextOpaqueImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextOpaqueImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image
            PdfImage opaquePdfImage = new PdfImage(crtXPos, crtYPos, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");

            imageLayoutInfo = page1.Layout(opaquePdfImage);

            // advance the Y position in the PDF page
            crtYPos += imageLayoutInfo.LastPageRectangle.Height + 10;

            #endregion

            #region Layout clipped JPEG image

            PdfText titleTextClippedImage = new PdfText(crtXPos, crtYPos, "The JPG image below is clipped:", pdfFontEmbed);
            titleTextClippedImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextClippedImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout a clipped image
            PdfImage clippedPdfImage = new PdfImage(crtXPos, crtYPos, 50, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_small.jpg");
            clippedPdfImage.ClipRectangle = new System.Drawing.RectangleF(crtXPos, crtYPos, 50, 25);

            imageLayoutInfo = page1.Layout(clippedPdfImage);

            // advance the Y position in the PDF page
            crtYPos += clippedPdfImage.ClipRectangle.Height + 10;

            #endregion

            #region Layout a vectorial SVG image

            PdfText titleTextSvgImage = new PdfText(crtXPos, crtYPos, "Vectorial SVG image:", pdfFontEmbed);
            titleTextSvgImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTextSvgImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string svgImageCode = System.IO.File.ReadAllText(Server.MapPath("~") + @"\DemoFiles\Svg\SvgImage.svg");

            PdfHtml       svgImage      = new PdfHtml(crtXPos, crtYPos, svgImageCode, null);
            PdfLayoutInfo svgLayoutInfo = page1.Layout(svgImage);

            // advance the Y position in the PDF page
            crtYPos += svgImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            #region Layout JPEG image on multiple pages

            PdfText titleTexMultiPageImage = new PdfText(crtXPos, crtYPos, "The JPG image below is laid out on 2 pages:", pdfFontEmbed);
            titleTexMultiPageImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = page1.Layout(titleTexMultiPageImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            // layout an opaque JPG image on 2 pages
            PdfImage paginatedPdfImage = new PdfImage(crtXPos, crtYPos, Server.MapPath("~") + @"\DemoFiles\Images\HiQPdfLogo_big.jpg");

            imageLayoutInfo = page1.Layout(paginatedPdfImage);

            #endregion

            // get the last page
            PdfPage crtPage = document.Pages[imageLayoutInfo.LastPageIndex];
            crtYPos = imageLayoutInfo.LastPageRectangle.Bottom + 10;

            #region Layout the screenshot of a HTML document

            PdfText titleTextHtmlImage = new PdfText(crtXPos, crtYPos, "HTML document screenshot:", pdfFontEmbed);
            titleTextHtmlImage.ForeColor = System.Drawing.Color.Navy;
            textLayoutInfo = crtPage.Layout(titleTextHtmlImage);

            // advance the Y position in the PDF page
            crtYPos += textLayoutInfo.LastPageRectangle.Height + 10;

            string htmlFile = Server.MapPath("~") + @"\DemoFiles\Html\Logo.Html";

            PdfHtmlImage htmlRasterImage = new PdfHtmlImage(crtXPos, crtYPos, htmlFile);
            htmlRasterImage.BrowserWidth = 400;
            PdfLayoutInfo htmlLayoutInfo = crtPage.Layout(htmlRasterImage);

            // advance the Y position in the PDF page
            crtYPos += htmlRasterImage.ConversionInfo.PdfRegions[0].Rectangle.Height + 10;

            #endregion

            try
            {
                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=PdfImages.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
Ejemplo n.º 22
0
        protected void buttonCreatePdf_Click(object sender, EventArgs e)
        {
            // create an empty PDF document
            PdfDocument document = new PdfDocument();

            // set a demo serial number
            document.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // add a page to document
            PdfPage page1 = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(5), PdfPageOrientation.Portrait);

            try
            {
                // set the document header and footer before adding any objects to document
                SetHeader(document);
                SetFooter(document);

                // layout the HTML from URL 1
                PdfHtml html1 = new PdfHtml(textBoxUrl1.Text);
                html1.WaitBeforeConvert = 2;
                PdfLayoutInfo html1LayoutInfo = page1.Layout(html1);

                // determine the PDF page where to add URL 2
                PdfPage page2 = null;
                System.Drawing.PointF location2 = System.Drawing.PointF.Empty;
                if (checkBoxNewPage.Checked)
                {
                    // URL 2 is laid out on a new page with the selected orientation
                    page2     = document.AddPage(PdfPageSize.A4, new PdfDocumentMargins(5), GetSelectedPageOrientation());
                    location2 = System.Drawing.PointF.Empty;
                }
                else
                {
                    // URL 2 is laid out immediately after URL 1 and html1LayoutInfo
                    // gives the location where the URL 1 layout finished
                    page2     = document.Pages[html1LayoutInfo.LastPageIndex];
                    location2 = new System.Drawing.PointF(html1LayoutInfo.LastPageRectangle.X, html1LayoutInfo.LastPageRectangle.Bottom);
                }

                // layout the HTML from URL 2
                PdfHtml html2 = new PdfHtml(location2.X, location2.Y, textBoxUrl2.Text);
                html2.WaitBeforeConvert = 2;
                page2.Layout(html2);

                // write the PDF document to a memory buffer
                byte[] pdfBuffer = document.WriteToMemory();

                // inform the browser about the binary data format
                HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

                // let the browser know how to open the PDF document and the file name
                HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("attachment; filename=LayoutMultipleHtml.pdf; size={0}",
                                                                                            pdfBuffer.Length.ToString()));

                // write the PDF buffer to HTTP response
                HttpContext.Current.Response.BinaryWrite(pdfBuffer);

                // call End() method of HTTP response to stop ASP.NET page processing
                HttpContext.Current.Response.End();
            }
            finally
            {
                document.Close();
            }
        }
        internal void DownloadViewsToSinglePDFFile(List <ViewItem> viewList, string fileName)
        {
            String baseUrl = HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.LastIndexOf("/") + 1);

            // create an empty PDF document
            PdfDocument document = new PdfDocument();

            document.SerialNumber = Utility.GetAPPSettingKey("HiQPDFSerialNumber");

            PdfDocument documentCover = new PdfDocument();

            documentCover.SerialNumber = Utility.GetAPPSettingKey("HiQPDFSerialNumber");

            PdfDocument documentList = new PdfDocument();

            documentList.SerialNumber = Utility.GetAPPSettingKey("HiQPDFSerialNumber");

            foreach (ViewItem viewItem in viewList)
            {
                if (viewItem.display)
                {
                    PdfPage page;
                    // add a page to document
                    if (viewItem.viewName == "CoverPage" || viewItem.viewName == "ContentPage")
                    {
                        page = documentCover.AddPage(PdfPageSize.A4, new PdfDocumentMargins(0), PdfPageOrientation.Portrait);
                        //page.DisplayHeader = false;
                        //page.DisplayFooter = false;
                    }

                    else
                    {
                        page = documentList.AddPage(PdfPageSize.A4, new PdfDocumentMargins(20), PdfPageOrientation.Portrait);
                        if (viewItem.viewName != "OrderingInformation")
                        {
                            page.DisplayHeader = true;
                            page.DisplayFooter = true;

                            SetHeader(documentList, fileName);
                            SetFooter(documentList, fileName);
                        }
                        else
                        {
                            page.DisplayHeader = false;
                            page.DisplayFooter = false;
                        }
                    }

                    // layout the HTML from URL
                    PdfHtml html = new PdfHtml(baseUrl + viewItem.viewName);
                    page.Layout(html);
                }
            }

            if (documentCover.Pages.Count > 0)
            {
                document.AddDocument(documentCover);
            }

            document.AddDocument(documentList);

            DownloadPDFFile(document.WriteToMemory(), fileName + DateTime.Now.ToShortDateString().Replace("/", "_"));
        }
        private void AddSignatureFooter(PdfPage pdfPage)
        {
            pdfPage.CreateFooterCanvas(300);

            pdfPage.Footer.Layout(new PdfHtml(20, 10, "<span style=\"font-family:Verdana; font-size:14px; color:black; text-decoration:none\">This is to certify that the data contained within this report was conducted as described above.</span>", null));

            string   signImageFile = HttpContext.Current.Server.MapPath(Utility.GetAPPSettingKey("ImageFolder") + "PHStudyReport/signiture.png");
            PdfImage signImage     = new PdfImage(20, 50, 218, Image.FromFile(signImageFile));

            pdfPage.Footer.Layout(signImage);

            pdfPage.Footer.Layout(new PdfHtml(20, 260, "<p style=\"font-family:Verdana; font-size:14px; color:black; text-decoration:none\">Dr. N. W. Charter<br><br>Director, Profiling Services</p>", null));

            Font pageFooterFont =
                new Font(new System.Drawing.FontFamily("Verdana"),
                         5, System.Drawing.GraphicsUnit.Point);

            pdfPage.Footer.Layout(new PdfHtml(0, 300, "<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;


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

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

            PdfText rightText = new PdfText(10, 15,
                                            string.Format("Q{0} - {1}", DateTime.Now.GetQuarter(), DateTime.Now.Year), pageFooterFont);

            rightText.HorizontalAlign = PdfTextHAlign.Right;
            rightText.EmbedSystemFont = true;
            rightText.ForeColor       = System.Drawing.Color.Black;
            pdfPage.Footer.Layout(rightText);
            // layout HTML in footer
            PdfHtml footerHtml = new PdfHtml(5, 5, footerStr, null);

            footerHtml.FitDestHeight = true;
            footerHtml.FontEmbedding = true;
            pdfPage.Footer.Layout(footerHtml);


            float footerHeight = pdfPage.Footer.Height;
            float footerWidth  = pdfPage.Footer.Width;

            // add page numbering
            Font pageNumberFont = new Font(new FontFamily("Verdana"), 6, GraphicsUnit.Point);
            //pageNumberingFont.Mea

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

            pageNumberingText.HorizontalAlign = PdfTextHAlign.Center;
            pageNumberingText.EmbedSystemFont = true;
            pageNumberingText.ForeColor       = Color.Black;
            pdfPage.Footer.Layout(pageNumberingText);
        }