Beispiel #1
0
        private static PDFFlowContent BuildInvoiceInfoSection(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold)
        {
            PDFAnsiTrueTypeFont labelFont = new PDFAnsiTrueTypeFont(verdanaBold);

            labelFont.Size = 12;
            PDFAnsiTrueTypeFont contentFont = new PDFAnsiTrueTypeFont(verdana);

            contentFont.Size = 12;

            PDFFlowTableContent invoiceInfoTable = new PDFFlowTableContent(2);

            invoiceInfoTable.Columns[0].Width = 120;
            invoiceInfoTable.Columns[0].WidthIsRelativeToTable            = false;
            (invoiceInfoTable.DefaultCell as PDFFlowTableStringCell).Font = contentFont;
            PDFFlowTableRow row = invoiceInfoTable.Rows.AddRowWithCells(" ", " ");

            row = invoiceInfoTable.Rows.AddRowWithCells("Date", "15 March 2016");
            (row.Cells[0] as PDFFlowTableStringCell).Font = labelFont;
            row = invoiceInfoTable.Rows.AddRowWithCells("Invoice number:", "1234567890");
            (row.Cells[0] as PDFFlowTableStringCell).Font = labelFont;
            row = invoiceInfoTable.Rows.AddRowWithCells("Currency:", "USD (US Dollars)");
            (row.Cells[0] as PDFFlowTableStringCell).Font = labelFont;

            return(invoiceInfoTable);
        }
Beispiel #2
0
        private static PDFFlowContent BuildCountriesList(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold, Stream data)
        {
            PDFAnsiTrueTypeFont textFont = new PDFAnsiTrueTypeFont(verdana);

            textFont.Size = 10;

            PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdanaBold);

            headerFont.Size = 12;

            PDFFlowTableContent countriesTable = new PDFFlowTableContent(2);

            countriesTable.Border       = new PDFPen(PDFRgbColor.Black, 0.5);
            countriesTable.MinRowHeight = 15;
            (countriesTable.DefaultCell as PDFFlowTableStringCell).Font = textFont;
            countriesTable.Columns[0].VerticalAlign   = PDFGraphicAlign.Center;
            countriesTable.Columns[1].VerticalAlign   = PDFGraphicAlign.Center;
            countriesTable.Columns[1].HorizontalAlign = PDFGraphicAlign.Far;

            string          continent = "";
            long            total     = 0;
            PDFFlowTableRow row       = null;
            StreamReader    sr        = new StreamReader(data);
            string          line      = sr.ReadLine();

            while (line != null)
            {
                string[] items = line.Split('|');
                long     pop   = long.Parse(items[2], System.Globalization.CultureInfo.InvariantCulture);
                total = total + pop;

                if (continent != items[0])
                {
                    // Add group footer
                    if (continent != "")
                    {
                        row = countriesTable.Rows.AddRowWithCells("Total population for " + continent + ": " + total.ToString("#,##0"));
                        row.Cells[0].ColSpan         = 2;
                        row.Cells[0].HorizontalAlign = PDFGraphicAlign.Far;
                        (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;
                    }
                    continent = items[0];
                    total     = 0;

                    // Add group header
                    row = countriesTable.Rows.AddRowWithCells(continent);
                    row.Cells[0].ColSpan = 2;
                    row.Background       = new PDFBrush(PDFRgbColor.LightGray);
                    (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;
                }
                row  = countriesTable.Rows.AddRowWithCells(items[1], pop.ToString("#,##0"));
                line = sr.ReadLine();
            }
            row = countriesTable.Rows.AddRowWithCells("Total population for " + continent + ": " + total.ToString("#,##0"));
            row.Cells[0].ColSpan         = 2;
            row.Cells[0].HorizontalAlign = PDFGraphicAlign.Far;
            (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;

            return(countriesTable);
        }
Beispiel #3
0
        private static PDFFlowContent BuildInvoiceItemsSection(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold)
        {
            PDFAnsiTrueTypeFont labelFont = new PDFAnsiTrueTypeFont(verdanaBold);

            labelFont.Size = 12;
            PDFAnsiTrueTypeFont contentFont = new PDFAnsiTrueTypeFont(verdana);

            contentFont.Size = 12;

            PDFFlowTableContent invoiceInfoTable = new PDFFlowTableContent(5);

            invoiceInfoTable.MinRowHeight                                 = 20;
            invoiceInfoTable.Columns[0].VerticalAlign                     = PDFGraphicAlign.Center;
            invoiceInfoTable.Columns[0].Width                             = 250;
            invoiceInfoTable.Columns[0].WidthIsRelativeToTable            = false;
            invoiceInfoTable.Columns[1].HorizontalAlign                   = PDFGraphicAlign.Far;
            invoiceInfoTable.Columns[1].VerticalAlign                     = PDFGraphicAlign.Center;
            invoiceInfoTable.Columns[1].Width                             = 50;
            invoiceInfoTable.Columns[1].WidthIsRelativeToTable            = false;
            invoiceInfoTable.Columns[2].VerticalAlign                     = PDFGraphicAlign.Center;
            invoiceInfoTable.Columns[2].HorizontalAlign                   = PDFGraphicAlign.Far;
            invoiceInfoTable.Columns[2].Width                             = 80;
            invoiceInfoTable.Columns[2].WidthIsRelativeToTable            = false;
            invoiceInfoTable.Columns[3].HorizontalAlign                   = PDFGraphicAlign.Far;
            invoiceInfoTable.Columns[3].VerticalAlign                     = PDFGraphicAlign.Center;
            invoiceInfoTable.Columns[3].Width                             = 80;
            invoiceInfoTable.Columns[3].WidthIsRelativeToTable            = false;
            invoiceInfoTable.Columns[4].HorizontalAlign                   = PDFGraphicAlign.Far;
            invoiceInfoTable.Columns[4].VerticalAlign                     = PDFGraphicAlign.Center;
            invoiceInfoTable.Columns[4].Width                             = 80;
            invoiceInfoTable.Columns[4].WidthIsRelativeToTable            = false;
            (invoiceInfoTable.DefaultCell as PDFFlowTableStringCell).Font = contentFont;

            PDFFlowTableRow row = invoiceInfoTable.Rows.AddRowWithCells("Description", "Qty", "Price", "Total", "VAT/Tax");

            for (int i = 0; i < row.Cells.Count; i++)
            {
                (row.Cells[i] as PDFFlowTableStringCell).Font  = labelFont;
                (row.Cells[i] as PDFFlowTableStringCell).Color = new PDFBrush(PDFRgbColor.White);
            }
            row.Background = new PDFBrush(PDFRgbColor.Black);
            row            = invoiceInfoTable.Rows.AddRowWithCells("Sample green item", "1", "100.00", "100.00", "20.00");
            row.Background = new PDFBrush(PDFRgbColor.LightGray);
            row            = invoiceInfoTable.Rows.AddRowWithCells("Big pink box", "3", "250.00", "750.00", "150.00");
            row            = invoiceInfoTable.Rows.AddRowWithCells("Yellow glass bowl", "2", "200.00", "400.00", "80.00");
            row.Background = new PDFBrush(PDFRgbColor.LightGray);
            row            = invoiceInfoTable.Rows.AddRowWithCells("Total", "", "", "1250.00", "250.00");
            row            = invoiceInfoTable.Rows.AddRowWithCells("Total (including VAT/Tax)", "", "", "1500.00", "");
            (row.Cells[0] as PDFFlowTableStringCell).Font = labelFont;
            (row.Cells[3] as PDFFlowTableStringCell).Font = labelFont;

            return(invoiceInfoTable);
        }
Beispiel #4
0
        private static PDFFlowContent BuildHeader(PDFAnsiTrueTypeFont verdanaBold)
        {
            PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdanaBold);

            headerFont.Size = 16;

            PDFFlowTableContent headerTable = new PDFFlowTableContent(1);
            PDFFlowTableRow     row         = headerTable.Rows.AddRowWithCells("Continents, countries and populations");

            (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;
            row.Cells[0].HorizontalAlign = PDFGraphicAlign.Center;
            row.MinHeight = 40;

            return(headerTable);
        }
Beispiel #5
0
        private static PDFFlowContent BuildHeader(PDFAnsiTrueTypeFont verdana, PDFImage logoImage)
        {
            PDFFlowTableContent headerTable = new PDFFlowTableContent(2);
            PDFFlowTableRow     row         = headerTable.Rows.AddRowWithCells("Invoice", logoImage);

            PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdana);

            headerFont.Size = 36;
            (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;
            row.Cells[0].VerticalAlign   = PDFGraphicAlign.Center;
            row.Cells[1].HorizontalAlign = PDFGraphicAlign.Far;
            (row.Cells[1] as PDFFlowTableImageCell).ImageWidth = 135;

            return(headerTable);
        }
        private void Document_PageCompleted(object sender, PDFFlowPageEventArgs e)
        {
            currentPage++;

            PDFFlowDocument document = (PDFFlowDocument)sender;

            PDFFlowTableContent mainHeaderTable = document.HeadersFooters.MainHeader.Content[0] as PDFFlowTableContent;

            (mainHeaderTable.Rows[0].Cells[0] as PDFFlowTableStringCell).Content = string.Format("Page {0}", currentPage);
            PDFFlowTableContent evenPagesHeaderTable = document.HeadersFooters.EvenPagesHeader.Content[0] as PDFFlowTableContent;

            (evenPagesHeaderTable.Rows[0].Cells[0] as PDFFlowTableStringCell).Content = string.Format("Page {0}", currentPage);

            PDFFlowTableContent mainFooterTable = document.HeadersFooters.MainFooter.Content[0] as PDFFlowTableContent;

            (mainFooterTable.Rows[0].Cells[0] as PDFFlowTableStringCell).Content = string.Format("Page {0}", currentPage);
            PDFFlowTableContent evenPagesFooterTable = document.HeadersFooters.EvenPagesFooter.Content[0] as PDFFlowTableContent;

            (evenPagesFooterTable.Rows[0].Cells[0] as PDFFlowTableStringCell).Content = string.Format("Page {0}", currentPage);
        }
        private void CreateHeadersAndFooters(PDFFlowDocument document, PDFAnsiTrueTypeFont verdana)
        {
            PDFFlowDocumentHeader mainHeader = new PDFFlowDocumentHeader();

            mainHeader.TopMargin = 24;
            PDFFlowTableContent mainHeaderTable = new PDFFlowTableContent(1);

            mainHeaderTable.Rows.AddRowWithCells("Page");
            mainHeaderTable.Rows[0].MinHeight = 15;
            PDFFlowTableStringCell mainHeaderTableCell = mainHeaderTable.Rows[0].Cells[0] as PDFFlowTableStringCell;

            mainHeaderTableCell.Font            = new PDFAnsiTrueTypeFont(verdana);
            mainHeaderTableCell.Font.Size       = 8;
            mainHeaderTableCell.HorizontalAlign = PDFGraphicAlign.Far;
            mainHeaderTableCell.VerticalAlign   = PDFGraphicAlign.Center;
            mainHeaderTableCell.Borders         = new PDFFlowContentBorders();
            mainHeaderTableCell.Borders.Bottom  = new PDFPen(PDFRgbColor.Black, 1);
            mainHeader.Content.Add(mainHeaderTable);
            document.HeadersFooters.MainHeader = mainHeader;

            PDFFlowDocumentHeader evenPagesHeader = new PDFFlowDocumentHeader();

            evenPagesHeader.TopMargin = 24;
            PDFFlowTableContent evenPagesHeaderTable = new PDFFlowTableContent(1);

            evenPagesHeaderTable.Rows.AddRowWithCells("Page");
            evenPagesHeaderTable.Rows[0].MinHeight = 15;
            PDFFlowTableStringCell evenPagesHeaderTableCell = evenPagesHeaderTable.Rows[0].Cells[0] as PDFFlowTableStringCell;

            evenPagesHeaderTableCell.Font            = new PDFAnsiTrueTypeFont(verdana);
            evenPagesHeaderTableCell.Font.Size       = 8;
            evenPagesHeaderTableCell.HorizontalAlign = PDFGraphicAlign.Near;
            evenPagesHeaderTableCell.VerticalAlign   = PDFGraphicAlign.Center;
            evenPagesHeaderTableCell.Borders         = new PDFFlowContentBorders();
            evenPagesHeaderTableCell.Borders.Bottom  = new PDFPen(PDFRgbColor.Black, 1);
            evenPagesHeader.Content.Add(evenPagesHeaderTable);
            document.HeadersFooters.EvenPagesHeader = evenPagesHeader;

            document.HeadersFooters.FirstPageHeader = null;

            PDFFlowDocumentFooter mainFooter = new PDFFlowDocumentFooter();

            mainFooter.BottomMargin = 24;
            PDFFlowTableContent mainFooterTable = new PDFFlowTableContent(1);

            mainFooterTable.Rows.AddRowWithCells("Page");
            mainFooterTable.Rows[0].MinHeight = 15;
            PDFFlowTableStringCell mainFooterTableCell = mainFooterTable.Rows[0].Cells[0] as PDFFlowTableStringCell;

            mainFooterTableCell.Font            = new PDFAnsiTrueTypeFont(verdana);
            mainFooterTableCell.Font.Size       = 8;
            mainFooterTableCell.HorizontalAlign = PDFGraphicAlign.Far;
            mainFooterTableCell.VerticalAlign   = PDFGraphicAlign.Center;
            mainFooterTableCell.Borders         = new PDFFlowContentBorders();
            mainFooterTableCell.Borders.Top     = new PDFPen(PDFRgbColor.Black, 1);
            mainFooter.Content.Add(mainFooterTable);
            document.HeadersFooters.MainFooter = mainFooter;

            PDFFlowDocumentFooter evenPagesFooter = new PDFFlowDocumentFooter();

            evenPagesFooter.BottomMargin = 24;
            PDFFlowTableContent evenPagesFooterTable = new PDFFlowTableContent(1);

            evenPagesFooterTable.Rows.AddRowWithCells("Page");
            evenPagesFooterTable.Rows[0].MinHeight = 15;
            PDFFlowTableStringCell evenPagesFooterTableCell = evenPagesFooterTable.Rows[0].Cells[0] as PDFFlowTableStringCell;

            evenPagesFooterTableCell.Font            = new PDFAnsiTrueTypeFont(verdana);
            evenPagesFooterTableCell.Font.Size       = 8;
            evenPagesFooterTableCell.HorizontalAlign = PDFGraphicAlign.Near;
            evenPagesFooterTableCell.VerticalAlign   = PDFGraphicAlign.Center;
            evenPagesFooterTableCell.Borders         = new PDFFlowContentBorders();
            evenPagesFooterTableCell.Borders.Top     = new PDFPen(PDFRgbColor.Black, 1);
            evenPagesFooter.Content.Add(evenPagesFooterTable);
            document.HeadersFooters.EvenPagesFooter = evenPagesFooter;

            document.HeadersFooters.FirstPageFooter = null;
        }
Beispiel #8
0
        private static PDFFlowContent BuildAttendantsList(PDFAnsiTrueTypeFont verdana, PDFAnsiTrueTypeFont verdanaBold, Stream data)
        {
            PDFAnsiTrueTypeFont textFont = new PDFAnsiTrueTypeFont(verdana);

            textFont.Size = 10;

            PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(verdanaBold);

            headerFont.Size = 12;

            PDFFlowTableContent attendantsTable = new PDFFlowTableContent(5);

            attendantsTable.Border       = new PDFPen(PDFRgbColor.Black, 0.5);
            attendantsTable.MinRowHeight = 15;
            (attendantsTable.DefaultCell as PDFFlowTableStringCell).Font = textFont;
            attendantsTable.Columns[0].VerticalAlign          = PDFGraphicAlign.Center;
            attendantsTable.Columns[0].Width                  = 120;
            attendantsTable.Columns[0].WidthIsRelativeToTable = false;
            attendantsTable.Columns[1].VerticalAlign          = PDFGraphicAlign.Center;
            attendantsTable.Columns[1].Width                  = 210;
            attendantsTable.Columns[1].WidthIsRelativeToTable = false;
            attendantsTable.Columns[2].VerticalAlign          = PDFGraphicAlign.Center;
            attendantsTable.Columns[2].Width                  = 100;
            attendantsTable.Columns[2].WidthIsRelativeToTable = false;
            attendantsTable.Columns[3].VerticalAlign          = PDFGraphicAlign.Center;
            attendantsTable.Columns[3].Width                  = 190;
            attendantsTable.Columns[3].WidthIsRelativeToTable = false;
            attendantsTable.Columns[4].VerticalAlign          = PDFGraphicAlign.Center;
            attendantsTable.Columns[4].Width                  = 130;
            attendantsTable.Columns[4].WidthIsRelativeToTable = false;

            PDFFlowTableRow row = attendantsTable.Rows.AddRowWithCells("Name", "Email", "Phone", "Company", "Country");

            for (int i = 0; i < row.Cells.Count; i++)
            {
                (row.Cells[i] as PDFFlowTableStringCell).Font  = headerFont;
                (row.Cells[i] as PDFFlowTableStringCell).Color = new PDFBrush(PDFRgbColor.White);
                row.Cells[i].HorizontalAlign = PDFGraphicAlign.Center;
            }
            row.Background = new PDFBrush(PDFRgbColor.Black);

            int          counter             = 0;
            PDFBrush     alternateBackground = new PDFBrush(PDFRgbColor.LightGray);
            StreamReader sr   = new StreamReader(data);
            string       line = sr.ReadLine();

            while (line != null)
            {
                string[] items = line.Split('|');

                row  = attendantsTable.Rows.AddRowWithCells(items);
                line = sr.ReadLine();

                if (counter % 2 == 0)
                {
                    row.Background = alternateBackground;
                }
                counter++;
            }

            return(attendantsTable);
        }
Beispiel #9
0
        /// <summary>
        /// Main method for running the sample.
        /// </summary>
        public static SampleOutputInfo[] Run(Stream verdanaFontStream)
        {
            PDFAnsiTrueTypeFont textFont   = new PDFAnsiTrueTypeFont(verdanaFontStream, 10, true);
            PDFAnsiTrueTypeFont headerFont = new PDFAnsiTrueTypeFont(textFont);

            headerFont.Size = 16;

            PDFFlowDocument document = new PDFFlowDocument();

            PDFFlowTableContent headerTable = new PDFFlowTableContent(1);
            PDFFlowTableRow     row         = headerTable.Rows.AddRowWithCells("Store sales by year");

            (row.Cells[0] as PDFFlowTableStringCell).Font = headerFont;
            row.Cells[0].HorizontalAlign = PDFGraphicAlign.Center;
            row.MinHeight = 40;
            document.AddContent(headerTable);

            PDFFlowTableContent itemsTable = new PDFFlowTableContent(4);

            (itemsTable.DefaultCell as PDFFlowTableStringCell).Font = textFont;
            itemsTable.Border                     = new PDFPen(PDFRgbColor.Black, 0.5);
            itemsTable.MinRowHeight               = 15;
            itemsTable.Columns[2].VerticalAlign   = PDFGraphicAlign.Center;
            itemsTable.Columns[3].VerticalAlign   = PDFGraphicAlign.Center;
            itemsTable.Columns[3].HorizontalAlign = PDFGraphicAlign.Far;

            row = itemsTable.Rows.AddRowWithCells("Tablets", "iPad Air 2", "2013", "213,554");
            row.Cells[0].RowSpan = 12;
            row.Cells[1].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "123,443");
            itemsTable.Rows.AddRowWithCells("2015", "64,443");
            row = itemsTable.Rows.AddRowWithCells("iPad Pro", "2013", "342,443");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "56,332");
            itemsTable.Rows.AddRowWithCells("2015", "765,231");
            row = itemsTable.Rows.AddRowWithCells("Nexus 7", "2013", "432,541");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "213,871");
            itemsTable.Rows.AddRowWithCells("2015", "112,332");
            row = itemsTable.Rows.AddRowWithCells("Nexus 9", "2013", "342,434");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "231,778");
            itemsTable.Rows.AddRowWithCells("2015", "119,324");

            row = itemsTable.Rows.AddRowWithCells("Smartphones", "Samsung Galaxy S5", "2013", "1,543,321");
            row.Cells[0].RowSpan = 12;
            row.Cells[1].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "1,435,875");
            itemsTable.Rows.AddRowWithCells("2015", "1,876,324");
            row = itemsTable.Rows.AddRowWithCells("Samsung Galaxy S6", "2013", "1,432,134");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "1,232,432");
            itemsTable.Rows.AddRowWithCells("2015", "1,765,112");
            row = itemsTable.Rows.AddRowWithCells("iPhone 6", "2013", "1,433,665");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "2,443,245");
            itemsTable.Rows.AddRowWithCells("2015", "1,656,334");
            row = itemsTable.Rows.AddRowWithCells("iPhone 6 Plus", "2013", "994,123");
            row.Cells[0].RowSpan = 3;
            itemsTable.Rows.AddRowWithCells("2014", "443,546");
            itemsTable.Rows.AddRowWithCells("2015", "765,342");

            document.AddContent(itemsTable);

            SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "tablecellspans.pdf") };
            return(output);
        }