Example #1
0
        /// <summary>
        /// Creates the PDF page footer (some text at the bottom of the page).
        /// </summary>
        /// <param name="currentPageNumber">Current page number.</param>
        /// <param name="totalPageNumber">Total number of pages.</param>
        /// <returns>The PDF page footer as PDFGraphicObjects.</returns>
        public static List<PDFGraphicObject> CreateFooter(int currentPageNumber, int totalPageNumber)
        {
            List<PDFGraphicObject> objects = new List<PDFGraphicObject>();

            PDFText footer = new PDFText(PageLayout.LeftFooter, PDFWriter.DefaultFont);
            PDFTranslation mark = new PDFTranslation(
                                            footer,
                                            PageLayout.FooterLeftXPos,
                                            PageLayout.FooterYPos);
            objects.Add(mark);

            string tmp = string.Format(
                                System.Globalization.CultureInfo.InvariantCulture,
                                "Page {0} out of {1}",
                                currentPageNumber, totalPageNumber);
            footer = new PDFText(tmp, PDFWriter.DefaultFont);
            mark = new PDFTranslation(
                                footer,
                                PageLayout.GetFooterRightXPos(tmp, PDFWriter.DefaultFont),
                                PageLayout.FooterYPos);
            objects.Add(mark);

            return objects;
        }
Example #2
0
        /// <summary>
        /// Creates the PDF page header (some text at the top of the page).
        /// </summary>
        /// <returns>The PDF page header as PDFGraphicObjects.</returns>
        public static List<PDFGraphicObject> CreateHeader()
        {
            List<PDFGraphicObject> objects = new List<PDFGraphicObject>();

            PDFText header = new PDFText(PageLayout.LeftHeader, PDFWriter.DefaultFont);
            PDFTranslation mark = new PDFTranslation(
                                            header,
                                            PageLayout.HeaderLeftXPos,
                                            PageLayout.HeaderYPos);
            objects.Add(mark);

            header = new PDFText(PageLayout.RightHeader, PDFWriter.DefaultFont);
            mark = new PDFTranslation(
                                header,
                                PageLayout.GetHeaderRightXPos(PageLayout.RightHeader, PDFWriter.DefaultFont),
                                PageLayout.HeaderYPos);
            objects.Add(mark);

            return objects;
        }
Example #3
0
        /// <summary>
        /// Creates the PDF page title (some text at the top of the page).
        /// </summary>
        /// <param name="title">PDF page title.</param>
        /// <param name="xPos">PDF page title X position.</param>
        /// <param name="yPos">PDF page title Y position.</param>
        /// <returns>The PDF page title as a PDFGraphicObject.</returns>
        private static PDFGraphicObject CreatePageTitle(string title, double xPos, double yPos)
        {
            PDFText pdfTitle = new PDFText(title, PDFWriter.TitleFont);
            PDFTranslation mark = new PDFTranslation(pdfTitle, xPos, yPos);

            return mark;
        }
Example #4
0
        /// <summary>
        /// Creates the pages contained inside the PDF.
        /// </summary>
        /// 
        /// <remarks>
        /// This method contains the main PDF algorithm.
        /// It splits DataSet rows into several PDF pages.
        /// 
        /// <code>
        ///    ----------------------------
        ///    | Column 1 | Column 2 | ...
        /// y  ----------------------------
        /// ^  | Row 10   | Row 11   | ...
        /// |  | Row 20   | Row 21   | ...
        /// |  | Row 30   | Row 31   | ...
        /// |  ----------------------------
        /// 0 ----> x
        /// </code>
        /// </remarks>
        /// 
        /// <param name="data">DataSet.</param>
        /// <param name="doc">Main PDF document.</param>
        /// <param name="outlines">PDF outlines so we can add the page to the "bookmarks"/outlines.</param>
        /// <returns>The PDF pages (a list of PDFPage).</returns>
        public static PDFPages CreatePages(DataSet data, PDFDocument doc, PDFOutlines outlines)
        {
            PDFPages pages = new PDFPages();

            foreach (DataTable table in data.Tables)
            {
                PDFOutline currentOutline = null;
                if (data.Tables.Count > 1)
                {
                    // More than 1 DataTable thus lets create outlines
                    currentOutline = new PDFOutline(table.TableName);
                    doc.AddChild(currentOutline);
                    outlines.AddOutline(currentOutline);
                }

                List<PDFGraphicObject> rows = new List<PDFGraphicObject>();

                double yPos = -Table.RowHeight;

                double tableWidth = Table.GetTableWidth(table);

                // Scaling
                double scaling = (PageLayout.Width - (PageLayout.RightMargin + PageLayout.LeftMargin)) / tableWidth;
                if (scaling > 1)
                {
                    scaling = 1;
                }
                ////

                // Page title
                // FIXME this is hardcoded
                List<string> title = new List<string>();
                title.Add("TITLE");
                title.Add("title");
                title.Add(table.TableName);
                double titleHeight = title.Count * Table.RowHeight * scaling;
                ////

                for (int row = 0; row < table.Rows.Count; row++)
                {
                    double totalTableWidth = 0;

                    for (int col = 0; col < table.Columns.Count; col++)
                    {
                        double pageHeightLimit = PageLayout.Height - PageLayout.BottomMargin - PageLayout.TopMargin - titleHeight;

                        // Detects end of page
                        bool endOfPage = -(yPos - Table.RowHeight) * scaling >= pageHeightLimit;
                        if (endOfPage)
                        {
                            // Creates the page
                            List<PDFGraphicObject> columns = Table.CreateColumns(table);
                            PDFPage page = CreatePage(doc, tableWidth, columns, rows, title);
                            pages.AddPage(page);
                            ////

                            // Add the page to the outline
                            if (currentOutline != null)
                            {
                                if (currentOutline.Page == null)
                                {
                                    currentOutline.Page = page;
                                }
                            }
                            ////

                            // Don't do a Clear() on the list, instead
                            // creates a new copy of the list otherwise
                            // objects referencing this list won't have their own copy
                            rows = new List<PDFGraphicObject>();

                            yPos = -Table.RowHeight;
                        }
                        ////

                        // Create a row
                        string rowName = table.Rows[row][col].ToString();
                        PDFTextBox text = Table.CreateRow(rowName, yPos);
                        PDFTranslation translation = new PDFTranslation(text, totalTableWidth, 0);
                        rows.Add(translation);
                        ////

                        DataColumn column = table.Columns[col];
                        double columnWidth = Table.GetColumnWidth(column, table);
                        totalTableWidth += columnWidth + 2;
                    }

                    // Change Y position inside the coordinate system of PDF
                    yPos -= Table.RowHeight;
                }

                if (rows.Count > 0)
                {
                    // Creates the page
                    List<PDFGraphicObject> columns = Table.CreateColumns(table);
                    PDFPage page = CreatePage(doc, tableWidth, columns, rows, title);
                    pages.AddPage(page);
                    ////

                    // Add the page to the outlines
                    if (currentOutline != null)
                    {
                        if (currentOutline.Page == null)
                        {
                            currentOutline.Page = page;
                        }
                    }
                    ////
                }
            }

            return pages;
        }