Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }