Пример #1
0
        private void btnExportarPDF_Click(object sender, EventArgs e)
        {
            if (dgvMaterias.Rows.Count == 0)
            {
                MessageBox.Show("Sin datos por EXPORTAR", "Aviso", MessageBoxButtons.OK);
            }
            else
            {
                PdfDocument pdf   = new PdfDocument();
                PdfPageBase page  = pdf.Pages.Add();
                PdfTable    table = new PdfTable();
                table.DataSource       = dgvMaterias.DataSource;
                table.Style.ShowHeader = true;

                PdfImage image  = PdfImage.FromFile(Path.Combine(System.IO.Path.GetFullPath(@"..\..\"), "Resources\\reporte.jpeg"));
                float    width  = image.Width * 0.75f;
                float    height = image.Height * 0.75f;
                float    x      = (page.Canvas.ClientSize.Width - width) / 2;
                page.Canvas.DrawImage(image, x, 60, width, height);

                table.Style.CellPadding = 2;
                PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
                tableLayout.Break     = PdfLayoutBreakType.FitElement;
                tableLayout.Layout    = PdfLayoutType.Paginate;
                table.BeginRowLayout += new BeginRowLayoutEventHandler(BeginRowLayout);
                table.Draw(page, new RectangleF(10, 30, 500, 700), tableLayout);


                pdf.SaveToFile("C:\\Users\\AbelFH\\Desktop\\Horarios-Asignados.pdf");
                MessageBox.Show("PDF generado exitosamente", "Aviso", MessageBoxButtons.OK);
            }
        }
Пример #2
0
        public static void PrintPDF(DataTable dt, string path)
        {
            //新建PDF文档
            Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
            //添加页面
            PdfPageBase page = pdf.Pages.Add();
            //创建表格
            PdfTable table = new PdfTable();

            //将DataGridView的数据导入到表格
            table.DataSource = dt;

            //显示表头(默认为不显示)
            table.Style.ShowHeader = true;

            //设置单元格内容与边框的间距
            table.Style.CellPadding = 2;

            //设置表格的布局 (超过一页自动将表格续写到下一页)
            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();

            tableLayout.Break  = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;

            //添加自定义事件
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

            //将表格绘制到页面并指定绘制的位置和范围
            table.Draw(page, new RectangleF(10, 50, 300, 300), tableLayout);

            pdf.SaveToFile(path);
            File.Open(path, FileMode.Open);
        }
Пример #3
0
        private PdfLayoutResult DrawOrderItems(PdfPageBase page, DataTable orderItems, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));

            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            table.Style.BorderPen   = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.MediumTurquoise;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.PaleTurquoise;
            table.Style.AlternateStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Teal;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource       = orderItems;
            for (int i = 2; i < table.Columns.Count; i++)
            {
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();

            tableLayout.Break  = PdfLayoutBreakType.FitPage;
            tableLayout.Layout = PdfLayoutType.Paginate;

            return(table.Draw(page, new PointF(0, y), tableLayout));
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.<br>
            PdfDocument doc = new PdfDocument();
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;
            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            float       y    = 10;
            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            String[] data
                =
                {
                "Name;Capital;Continent;Area;Population",
                "Argentina;Buenos Aires;South America;2777815;32300003",
                "Bolivia;La Paz;South America;1098575;7300000",
                "Brazil;Brasilia;South America;8511196;150400000",
                "Canada;Ottawa;North America;9976147;26500000",
                };
            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfTable table = new PdfTable();

            table.Style.CellPadding    = 2;
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader     = true;
            table.DataSource           = dataSource;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            y = y + result.Bounds.Height + 5;
            PdfBrush        brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 9f));

            page.Canvas.DrawString(String.Format("* {0} countries in the list.", data.Length - 1), font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("SimpleTable.pdf");
        }
Пример #5
0
        static void PdfWithTable()
        {
            // Table
            PdfTable table = new PdfTable(
                style: TableStyle.OnlyRowsBordered,
                fitToDocument: true);

            // THead
            table.THead.Add(new PdfTableHeaderCell("Nummer", Alignment.Left, 2.0));
            table.THead.Add(new PdfTableHeaderCell("Name", Alignment.Left, 4.0));
            table.THead.Add(new PdfTableHeaderCell("Position", Alignment.Left, 2.0));
            table.THead.Add(new PdfTableHeaderCell("GP", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("G", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("A", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("PTS", Alignment.Center, 2.0));
            table.THead.Add(new PdfTableHeaderCell("PIM", Alignment.Center, 2.0));

            // TBody
            PdfTableRow row = new PdfTableRow();

            row.Add(new PdfTableCell("1"));
            row.Add(new PdfTableCell("Aebischer David"));
            row.Add(new PdfTableCell("Goalkeeper"));
            row.Add(new PdfTableCell("65"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("0"));
            row.Add(new PdfTableCell("14"));

            table.TBody.Add(row);

            row = new PdfTableRow();

            row.Add(new PdfTableCell("1"));
            row.Add(new PdfTableCell("Aeschlimann Jean-Jaques"));
            row.Add(new PdfTableCell("Forwarder"));
            row.Add(new PdfTableCell("120"));
            row.Add(new PdfTableCell("20"));
            row.Add(new PdfTableCell("15"));
            row.Add(new PdfTableCell("35"));
            row.Add(new PdfTableCell("24"));

            table.TBody.Add(row);

            IPdfTemplate template = new PdfTemplateWithHeaderAndHeading();

            template.Define(
                title: "U20 Junior National Team 2 2 2 2 2 2 2 2 2 2",
                author: "Doc Author",
                subject: "PLAYER STATISTICS - Season 2014 / 2015",
                keywords: "Doc Keywords",
                absolutePathToPdfTemplate: @"D:\DEVELOPMENT\GIT\OPTEN Solutions\tools\Pdf\pdf_template.pdf");

            template.Elements.Add(table);

            // Create
            template.SaveOnDisk(@"C:\Users\cfrei\Desktop\" + template.FileName());
        }
Пример #6
0
        void tab_TableStartEvent(PdfTable Table, double TableStartPos)
        {
            pageNumber += 1;
            string aOrb = myOffer.Bestellkennzeichen ? "Bestellung " : "Angebot CPM, Nr. ";

            if (pageNumber > 1)
            {
                Table.Contents.DrawText(fontDefault, 8D, xLeftMargin, TableStartPos + 3, aOrb + myOffer.OfferId);
            }
            Table.Contents.DrawText(fontDefault, 8D, xPage, TableStartPos + 3, "Seite " + pageNumber);
        }
Пример #7
0
        private void BookListTableStart
        (
            PdfTable BookList,
            Double TableStartPos
        )
        {
            Double PosX = 0.5 * (BookList.TableArea.Left + BookList.TableArea.Right);
            Double PosY = TableStartPos + TableTitleFont.Descent(16.0) + 0.05;

            BookList.Contents.DrawText(TableTitleFont, 16.0, PosX, PosY, TextJustify.Center, DrawStyle.Normal, Color.Chocolate, "Book List PdfTable Example");
            return;
        }
Пример #8
0
        private void BookListTableEnd
        (
            PdfTable BookList,
            Double TableEndPos
        )
        {
            Double PosX = BookList.TableArea.Left;
            Double PosY = TableEndPos - TableTitleFont.Ascent(12.0) - 0.05;

            BookList.Contents.DrawText(TableTitleFont, 12.0, PosX, PosY, TextJustify.Left, DrawStyle.Normal, Color.Chocolate, "Either scan the Web link or click the area for more info.");
            return;
        }
        public static void pdfsettings()
        {
            path = @"C:\Users\Public\Documents\RadianLabs\ReliefText\TeacherID-" + al5[relindex] + "_Date-" + date + "_Relief.pdf";
            PdfUnitConvertor uc   = new PdfUnitConvertor();;
            PdfMargins       marg = new PdfMargins();;
            PdfPageBase      page;
            PdfDocument      pdfd;
            float            y = 10;
            PdfBrush         bru;
            PdfTrueTypeFont  fon;
            PdfStringFormat  format;

            pdfd        = new PdfDocument();
            marg.Top    = uc.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            marg.Bottom = marg.Top;
            marg.Left   = uc.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            marg.Right  = marg.Left;
            page        = pdfd.Pages.Add(PdfPageSize.A4, marg);
            bru         = PdfBrushes.Black;
            fon         = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            format      = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString(textname, fon, bru, page.Canvas.ClientSize.Width / 2, y, format);
            y = y + fon.MeasureString(textname, format).Height;
            y = y + 5;
            String[]   pdfdata    = { "Period;Class", "One;" + relprinter[0] + "", "Two;" + relprinter[1] + "", "Three;" + relprinter[2] + "", "Four;" + relprinter[3] + "", "Five;" + relprinter[4] + "", "Six;" + relprinter[5] + "", "Seven;" + relprinter[6] + "", "Eight;" + relprinter[7] + "" };
            String[][] dataSource = new String[pdfdata.Length][];
            for (i = 0; i < pdfdata.Length; i++)
            {
                dataSource[i] = pdfdata[i].Split(';');
            }
            PdfTable pdftable = new PdfTable();

            pdftable.Style.CellPadding    = 2;
            pdftable.Style.HeaderSource   = PdfHeaderSource.Rows;
            pdftable.Style.HeaderRowCount = 1;
            pdftable.Style.ShowHeader     = true;
            pdftable.DataSource           = dataSource;
            PdfLayoutResult pdfresult = pdftable.Draw(page, new PointF(0, y));
            PdfBrush        bru2      = PdfBrushes.Gray;
            PdfTrueTypeFont fon2      = new PdfTrueTypeFont(new Font("Arial", 9f));

            page.Canvas.DrawString(String.Format("{0}", pdfdata.Length - 1), fon2, bru2, 5, y);
            try
            {
                pdfd.SaveToFile(path);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            pdfd.Close();
        }
        private void DrawPage(PdfPageBase page)
        {
            float y = 10;

            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Category Sales by Year", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Category Sales by Year", format1).Height;
            y = y + 5;

            String[][] data
                =
                {
                new String[] { "Category Name",  "1994 Sale Amount", "1995 Sale Amount", "1996 Sale Amount" },
                new String[] { "Beverages",      "38,487.20",        "102,479.46",       "126,901.53"       },
                new String[] { "Condiments",     "16,402.95",        "51,041.83",        "38,602.31"        },
                new String[] { "Confections",    "23,812.90",        "79,752.25",        "63,792.07"        },
                new String[] { "Dairy Products", "30,027.79",        "116,495.45",       "87,984.05"        },
                new String[] { "Grains/Cereals", "7,313.92",         "53,823.48",        "34,607.19"        },
                new String[] { "Meat/Poultry",   "19,856.86",        "77,164.75",        "66,000.75"        },
                new String[] { "Produce",        "10,694.96",        "45,973.69",        "43,315.93"        },
                new String[] { "Seafood",        "16,247.77",        "64,195.51",        "50,818.46"        }
                };

            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            table.Style.BorderPen   = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource       = data;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            y = y + result.Bounds.Height + 5;

            PdfBrush        brush2 = PdfBrushes.LightGray;
            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 9f));

            page.Canvas.DrawString("* All data from NorthWind", font2, brush2, 5, y);
        }
Пример #11
0
        private void AddTablaPrincipal(PdfPage page)
        {
            var dataTable = new DataTable();

            dataTable.Columns.Add(PDF_Resources.Header_Parametro);
            dataTable.Columns.Add(PDF_Resources.Header_Puntaje);
            dataTable.Columns.Add(PDF_Resources.Header_Percentil);
            dataTable.Columns.Add(PDF_Resources.Header_Orientacion);

            int rows    = datos.TNotaciones.Parametros.Length;
            int columns = dataTable.Columns.Count;

            PdfTable myPdfTable = pdfDocument.NewTable(Function_Library.FontTexto11, rows, columns, 3);

            var str_orientacion = new[]
            {
                datos.Orientaciones.O_indice_atencion_total,
                //datos.O_Error_estandar_IA,
                datos.Orientaciones.O_Aciertos,
                datos.Orientaciones.O_Omision,
                datos.Orientaciones.O_Comision,
                datos.Orientaciones.O_TR,
                datos.Orientaciones.O_ErrorTR,
                datos.Orientaciones.O_d,
                datos.Orientaciones.O_C
            };

            for (int i = 0; i < datos.TNotaciones.Parametros.Length; i++)
            {
                DataRow row = dataTable.NewRow();
                row[PDF_Resources.Header_Parametro]   = datos.TNotaciones.Parametros[i];
                row[PDF_Resources.Header_Puntaje]     = FunctionLibrary.ShowDouble(datos.Puntuaciones[i]);
                row[PDF_Resources.Header_Percentil]   = (i >= 6 && i <= 7) ? string.Empty : FunctionLibrary.ShowDouble(datos.TNotaciones[i]);
                row[PDF_Resources.Header_Orientacion] = str_orientacion[i];
                dataTable.Rows.Add(row);
            }

            myPdfTable.ImportDataTable(dataTable);
            myPdfTable.HeadersRow.SetColors(Color.Black, Color.FromArgb(229, 229, 229));
            myPdfTable.SetColors(Color.Black, Color.White);
            myPdfTable.SetBorders(Color.Black, 1, BorderType.CompleteGrid);
            myPdfTable.SetColumnsWidth(new[] { 35, 12, 12, 41 });
            myPdfTable.SetContentAlignment(ContentAlignment.TopLeft);
            myPdfTable.HeadersRow[0].SetContent(string.Empty);
            myPdfTable.Columns[0].SetBackgroundColor(Color.FromArgb(242, 242, 242));
            PdfTablePage newPdfTablePage = myPdfTable.CreateTablePage(new PdfArea(pdfDocument, 80, 480, 450, 420));

            page.Add(newPdfTablePage);
        }
Пример #12
0
        private PdfLayoutResult DrawPart(PdfPageBase page, DataTable parts, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            DataRow         row   = parts.Rows[index];

            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[2][];
            data[0] = new String[parts.Columns.Count];
            for (int i = 0; i < parts.Columns.Count; i++)
            {
                data[0][i] = parts.Columns[i].ColumnName;
            }
            data[1] = row.ItemArray;

            PdfTable table = new PdfTable();

            table.Style.CellPadding = 2;
            table.Style.BorderPen   = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.GreenYellow;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 9f));
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.ForestGreen;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource       = data;

            float width
                = page.Canvas.ClientSize.Width
                  - (table.Columns.Count + 1) * table.Style.BorderPen.Width;

            for (int i = 0; i < table.Columns.Count; i++)
            {
                table.Columns[i].Width = i == 1 ? width * 0.35f : width * 0.13f;
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();

            tableLayout.Break  = PdfLayoutBreakType.FitPage;
            tableLayout.Layout = PdfLayoutType.Paginate;

            return(table.Draw(page, new PointF(0, y), tableLayout));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a Pdf documemt
            PdfDocument doc  = new PdfDocument();
            PdfPageBase page = doc.Pages.Add();

            //Create a table
            PdfTable      table = new PdfTable();
            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);

            table.Style.BorderPen = new PdfPen(brush, 0.5f);
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.HeaderSource             = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount           = 1;
            table.Style.ShowHeader = true;

            PdfTrueTypeFont fontHeader = new PdfTrueTypeFont(new Font("Arial", 14f));

            table.Style.HeaderStyle.Font            = fontHeader;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;

            PdfTrueTypeFont fontBody = new PdfTrueTypeFont(new Font("Arial", 12f));

            table.Style.AlternateStyle.Font = fontBody;
            table.Style.AlternateStyle.Font = fontBody;
            table.DataSource = GetData();

            foreach (PdfColumn column in table.Columns)
            {
                column.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            }

            //Set the row height
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

            //Draw an image in a cell
            table.EndCellLayout += new EndCellLayoutEventHandler(table_EndCellLayout);

            //Draw the table in the page
            table.Draw(page, new PointF(0, 100));

            //Save the Pdf document
            doc.SaveToFile("AddImageinATableCell_out.pdf", FileFormat.PDF);

            //Launch the Pdf file
            PDFDocumentViewer("AddImageinATableCell_out.pdf");
        }
Пример #14
0
        protected PdfLayoutResult buildPdfLines(PdfPageBase page, List<LineItem> list, string category, float y)
        {
            PdfFont helv14 = new PdfFont(PdfFontFamily.Helvetica, 14f);
            PdfFont helv12 = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfFont helv11 = new PdfFont(PdfFontFamily.Helvetica, 11f);

            PdfTable LinesTable = new PdfTable();
            LinesTable.Style.CellPadding = 1;
            LinesTable.Style.DefaultStyle.Font = helv11;

            List<string> data = new List<string>();
            double subtotal = 0;

            if(category == "Recurring")
                data.Add("Product;Part Number;Monthly Rate;Quantity;Price");
            else
                data.Add("Product;Part Number;Unit Price;Quantity;Price");
            foreach (LineItem line in list)
            {
                data.Add(line.Product.Name + ";" + line.Product.PartNumber + ";$" + line.Product.Price + ";" + line.Quantity + ";$" + line.Total);
                subtotal += line.Total;
            } data.Add(";;; Subtotal: ;$" + subtotal.ToString());

            string[][] dataSource = new string[data.Count][];
            for (int i = 0; i < data.Count; i++)
                dataSource[i] = data[i].Split(';');

            LinesTable.DataSource = dataSource;

            LinesTable.BeginRowLayout += new BeginRowLayoutEventHandler(LinesTable_BeginRowLayout);

            LinesTable.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            LinesTable.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            LinesTable.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            LinesTable.Columns[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);

            float width = page.Canvas.ClientSize.Width;
            for (int i = 0; i < LinesTable.Columns.Count; i++)
            {
                if (i == 0)
                    LinesTable.Columns[i].Width = width * .1f * width;
                else
                    LinesTable.Columns[i].Width = width * .045f * width;
            }

            return LinesTable.Draw(page, new PointF(0, y));
        }
Пример #15
0
        private void RazemWTym(double left, double top, double bottom, double fontSize)
        {
            var tableLeft = new PdfTable(_page, PdfContents, ArialNormal, fontSize)
            {
                TableArea = new PdfRectangle(left - 3, bottom, left - 0.5, top)
            };

            tableLeft.SetColumnWidth(2.5);
            tableLeft.DefaultHeaderStyle.Alignment       = ContentAlignment.MiddleRight;
            tableLeft.DefaultHeaderStyle.BackgroundColor = Color.Transparent;
            tableLeft.Header[0].Value         = DictionaryMain.SummaRazem;
            tableLeft.Cell[0].Style.Alignment = ContentAlignment.MiddleRight;
            tableLeft.Cell[0].Value           = DictionaryMain.SummaWTym;
            tableLeft.DrawRow();
            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
        }
Пример #16
0
        private void RazemWTym(double LEFT, double TOP, double BOTTOM, double FONT_SIZE)
        {
            var TableLeft = new PdfTable(_page, PdfContents, _arialNormal, FONT_SIZE)
            {
                TableArea = new PdfRectangle(LEFT - 3, BOTTOM, LEFT - 0.5, TOP)
            };

            TableLeft.SetColumnWidth(2.5);
            TableLeft.DefaultHeaderStyle.Alignment       = ContentAlignment.MiddleRight;
            TableLeft.DefaultHeaderStyle.BackgroundColor = Color.Transparent;
            TableLeft.Header[0].Value         = DictionaryMain.SummaRazem;
            TableLeft.Cell[0].Style.Alignment = ContentAlignment.MiddleRight;
            TableLeft.Cell[0].Value           = DictionaryMain.SummaWTym;
            TableLeft.DrawRow();
            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
        }
Пример #17
0
        public TableRenderer(PdfTable table)
        {
            _table = table;
            _left  = table.Left;
            _top   = table.Top;

            _linePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = _table.BorderWidth,
            };

            foreach (var row in table.Rows)
            {
                _rowRenderer.Add(new RowRenderer(row));
            }
        }
Пример #18
0
        private void DrawPage(PdfPageBase page)
        {
            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Category Sales by Year", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Category Sales by Year", format1).Height;
            y = y + 5;

            String[][] data
                = {
                    new String[]{"Category Name", "1994 Sale Amount", "1995 Sale Amount", "1996 Sale Amount"},
                    new String[]{"Beverages", "38,487.20", "102,479.46", "126,901.53"},
                    new String[]{"Condiments", "16,402.95", "51,041.83", "38,602.31"},
                    new String[]{"Confections", "23,812.90", "79,752.25", "63,792.07"},
                    new String[]{"Dairy Products", "30,027.79", "116,495.45", "87,984.05"},
                    new String[]{"Grains/Cereals", "7,313.92", "53,823.48", "34,607.19"},
                    new String[]{"Meat/Poultry", "19,856.86", "77,164.75", "66,000.75"},
                    new String[]{"Produce", "10,694.96", "45,973.69", "43,315.93"},
                    new String[]{"Seafood", "16,247.77", "64,195.51", "50,818.46"}
                };

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource = data;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.LightGray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString("* All data from NorthWind", font2, brush2, 5, y);
        }
Пример #19
0
        private double RamkiEnd(double left, double top, double bottom, double right, double fontSize, string tekst)
        {
            const double marginHor  = 0.04;
            const double marginVer  = 0.04;
            const double frameWidth = 0.015;

            var table = new PdfTable(_page, PdfContents, ArialNormal, fontSize)
            {
                TableArea = new PdfRectangle(left, bottom, right, top)
            };

            table.SetColumnWidth(12);

            table.Borders.ClearAllBorders();
            table.Borders.SetFrame(frameWidth);

            var margin = new PdfRectangle(marginHor, marginVer);

            table.DefaultCellStyle.Margin = margin;

            table.Cell[0].Style = table.CellStyle;
            table.Cell[0].Style.MultiLineText = false;
            table.Cell[0].Style.Alignment     = ContentAlignment.MiddleCenter;
            table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;

            table.Cell[0].Value = string.Empty;
            table.DrawRow();
            table.Cell[0].Value = string.Empty;
            table.DrawRow();
            table.Cell[0].Value = string.Empty;
            table.DrawRow();
            table.Cell[0].Value = string.Empty;
            table.DrawRow();
            table.Cell[0].Value = tekst;
            table.DrawRow();

            var positionLast = table.RowPosition[table.RowNumber] - table.RowHeight;

            table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
Пример #20
0
        private double RamkiEnd(double LEFT, double TOP, double BOTTOM, double RIGHT, double FONT_SIZE, string tekst)
        {
            const double MARGIN_HOR  = 0.04;
            const double MARGIN_VER  = 0.04;
            const double FRAME_WIDTH = 0.015;

            var Table = new PdfTable(_page, PdfContents, _arialNormal, FONT_SIZE)
            {
                TableArea = new PdfRectangle(LEFT, BOTTOM, RIGHT, TOP)
            };

            Table.SetColumnWidth(12);

            Table.Borders.ClearAllBorders();
            Table.Borders.SetFrame(FRAME_WIDTH);

            var Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER);

            Table.DefaultCellStyle.Margin = Margin;

            Table.Cell[0].Style = Table.CellStyle;
            Table.Cell[0].Style.MultiLineText = false;
            Table.Cell[0].Style.Alignment     = ContentAlignment.MiddleCenter;
            Table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;

            Table.Cell[0].Value = string.Empty;
            Table.DrawRow();
            Table.Cell[0].Value = string.Empty;
            Table.DrawRow();
            Table.Cell[0].Value = string.Empty;
            Table.DrawRow();
            Table.Cell[0].Value = string.Empty;
            Table.DrawRow();
            Table.Cell[0].Value = tekst;
            Table.DrawRow();

            var positionLast = Table.RowPosition[Table.RowNumber] - Table.RowHeight;

            Table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
Пример #21
0
 void tab_TableEndEvent(PdfTable Table, double TableEndPos)
 {
     lastPosition = TableEndPos;
     if (!lastRow)
     {
         if (!myOffer.Bestellkennzeichen)
         {
             DrawSubtotal(Table.Contents);
         }
     }
     else
     {
         if (!myOffer.Bestellkennzeichen)
         {
             DrawSummary(Table.Contents, myOffer);
         }
     }
     DrawFooter(Table.Contents, fontFooter);
 }
Пример #22
0
        // draw cell event handler
        private bool BookListDrawCellEvent(PdfTable Table, PdfTableCell Cell)
        {
            Table.Contents.SaveGraphicsState();
            if ((string)Cell.Value == "Paperback")
            {
                Table.Contents.SetColorNonStroking(Color.LightCyan);
            }
            else
            {
                Table.Contents.SetColorNonStroking(Color.LightPink);
            }
            double PosX   = Cell.ClientLeft;
            double PosY   = 0.5 * (Cell.ClientBottom + Cell.ClientTop) - Cell.Style.FontLineSpacing;
            double Width  = Cell.ClientRight - Cell.ClientLeft;
            double Height = 2.0 * Cell.Style.FontLineSpacing;

            Table.Contents.DrawRoundedRectangle(PosX, PosY, Width, Height, 0.25, PaintOp.Fill);
            Table.Contents.RestoreGraphicsState();;
            return(false);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PdfTemplateInvoice" /> class.
 /// </summary>
 /// <param name="invoiceNumber">The invoice number.</param>
 /// <param name="invoiceTitle">The invoice title.</param>
 /// <param name="companyAddress">The company address.</param>
 /// <param name="billingAddressTitle">The billing address title.</param>
 /// <param name="billingAddress">The billing address.</param>
 /// <param name="invoiceDetails">The invoice details.</param>
 /// <param name="invoiceSummary">The invoice summary.</param>
 /// <param name="details">The details (paragraphs after table).</param>
 /// <param name="absolutePathToPdfTemplate">The absolute template path.</param>
 public PdfTemplateInvoice(
     string invoiceNumber,
     string invoiceTitle,
     IEnumerable <TextLine> companyAddress,
     string billingAddressTitle,
     IEnumerable <TextLine> billingAddress,
     PdfTable invoiceDetails,
     PdfTable invoiceSummary,
     IEnumerable <TextLine> details   = null,
     string absolutePathToPdfTemplate = null)
     : base()
 {
     _invoiceNumber       = invoiceNumber;
     _invoiceTitle        = invoiceTitle;
     _companyAddress      = companyAddress;
     _billingAddressTitle = billingAddressTitle;
     _billingAddress      = billingAddress;
     _invoiceDetails      = invoiceDetails;
     _invoiceSummary      = invoiceSummary;
     _details             = details;
 }
Пример #24
0
        public bool PrintPdf(PdfSection sec, string name, string[] dataset)
        {
            float y     = 10;
            bool  check = true;

            if (dataset.Length != 1)
            {
                page = sec.Pages.Add();
                try
                {
                    page.Canvas.DrawString(name, font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
                    y += font1.MeasureString("Country List", format1).Height;
                    y += 5;
                    String[][] dataSource = new String[dataset.Length][];
                    for (int i = 0; i < dataset.Length; i++)
                    {
                        dataSource[i] = dataset[i].Split(';');
                    }
                    PdfTable table = new PdfTable();
                    table.Style.CellPadding = 2;
                    table.Style.BorderPen   = new PdfPen(brush1, 0.75f);
                    table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
                    table.Style.HeaderSource             = PdfHeaderSource.Rows;
                    table.Style.HeaderRowCount           = 1;
                    table.Style.ShowHeader = true;
                    table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
                    table.DataSource = dataSource;
                    foreach (PdfColumn column in table.Columns)
                    {
                        column.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    table.Draw(page, new PointF(0, y));
                }
                catch
                {
                    check = false;
                }
            }
            return(check);
        }
Пример #25
0
        /// <summary>
        /// Instantiates a new PdfTable setting the default specs.
        /// </summary>
        /// <param name="DefaultFont"></param>
        /// <param name="Rows"></param>
        /// <param name="Columns"></param>
        /// <param name="CellPadding"></param>
        /// <returns></returns>
        public PdfTable NewTable(Font DefaultFont, int Rows, int Columns, double CellPadding)
        {
            if (Rows <= 0)
            {
                throw new Exception("Rows must be grater than zero.");
            }
            if (Columns <= 0)
            {
                throw new Exception("Columns must be grater than zero.");
            }
            if (CellPadding < 0)
            {
                throw new Exception("CellPadding must be non-negative.");
            }
            PdfTable pt = new PdfTable(this, ContentAlignment.TopCenter, DefaultFont, Color.Black, Rows
                                       , Columns, CellPadding);

            pt.header = new PdfTable(this, ContentAlignment.MiddleCenter, DefaultFont, Color.Black, 1
                                     , Columns, CellPadding);

            return(pt);
        }
Пример #26
0
        public void MakeSimpleTable()
        {
            PdfGeneratedDocument doc   = new PdfGeneratedDocument();
            PdfGeneratedPage     page  = doc.AddPage(PdfDefaultPages.Letter);
            PdfTable             table = new PdfTable(new PdfBounds(72, 300, 400, 400), "Arial", 12);

            table.HeaderFontName = "Arial Bold Italic";
            table.BorderStyle    = PdfTableBorderStyle.Grid;
            table.Columns.Add(new PdfTableColumn("Name", "Person", 120, PdfTextAlignment.Center,
                                                 8, 8));
            table.Columns.Add(new PdfTableColumn("Age", "Age", 60, PdfTextAlignment.Center, 8,
                                                 8));
            table.Columns.Add(new PdfTableColumn("Color", "Favorite Color", 0,
                                                 PdfTextAlignment.Center, 8, 8));
            List <Person> people = new List <Person>()
            {
                new Person()
                {
                    Name = "John", Age = 15, Color = "Orange"
                },
                new Person()
                {
                    Name = "Emily", Age = 37, Color = "Blue"
                },
                new Person()
                {
                    Name = "Philippe", Age = 19, Color = "Green"
                },
                new Person()
                {
                    Name = "Jill", Age = 23, Color = "Ochre"
                }
            };

            table.AddRows(people.GetEnumerator());
            table.Fill(doc.Resources.Fonts);
            page.DrawingList.Add(table);
            doc.Save("basictable.pdf");
        }
Пример #27
0
        private PdfLayoutResult DrawPDFTable(string title, float y, PdfPageBase page, string dataName)
        {
            //Draw Title
            PdfBrush        brush  = PdfBrushes.Black;
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);
            string          title1 = title;

            page.Canvas.DrawString(title1, font, brush, page.Canvas.ClientSize.Width / 2, y, format);
            y = y + font.MeasureString(title1, format).Height;
            y = y + 10;

            //Create PDF table and define table style
            PdfTable table = new PdfTable();

            table.Style.CellPadding = 3;
            table.Style.BorderPen   = new PdfPen(brush, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.DefaultStyle.StringFormat    = format;
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle.StringFormat    = format;
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 14f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = format;
            table.Style.ShowHeader = true;

            //Fill data in table
            table.DataSource = GetData(dataName);

            //Draw the table on Pdf page
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            return(result);
        }
        private void DrawTableInHeaderFooter(PdfDocument doc)
        {
            String[] data
                =
                {
                "Column1;Column2",
                "Spire.PDF for .NET;Spire.PDF for JAVA",
                };
            float    y     = 20;
            PdfBrush brush = PdfBrushes.Black;

            foreach (PdfPageBase page in doc.Pages)
            {
                String[][] dataSource
                    = new String[data.Length][];
                for (int i = 0; i < data.Length; i++)
                {
                    dataSource[i] = data[i].Split(';');
                }
                //Create Pdf table
                PdfTable table = new PdfTable();
                table.Style.CellPadding = 2;
                table.Style.BorderPen   = new PdfPen(brush, 0.1f);
                table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
                table.Style.HeaderSource             = PdfHeaderSource.Rows;
                table.Style.HeaderRowCount           = 1;
                table.Style.ShowHeader = true;
                table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
                table.DataSource = dataSource;
                foreach (PdfColumn column in table.Columns)
                {
                    column.StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                }
                //Draw the table on page
                table.Draw(page, new PointF(0, y));
            }
        }
Пример #29
0
        private void PDFBtn_Click(object sender, EventArgs e)
        {
            Bunifu.UI.WinForms.BunifuButton.BunifuButton btn           = (Bunifu.UI.WinForms.BunifuButton.BunifuButton)sender;
            Bunifu.Framework.UI.BunifuCustomDataGrid     PDF_dataTable = this.Controls.Find($"{btn.Name.Split('_')[1]}", true).FirstOrDefault() as Bunifu.Framework.UI.BunifuCustomDataGrid;

            if (PDFSaveDialog.ShowDialog() == DialogResult.OK)
            {
                //create a pdf document
                PdfDocument pdf = new PdfDocument();
                //add a page
                PdfPageBase page = pdf.Pages.Add();

                //create a table
                PdfTable table = new PdfTable();

                //export datagridview to table
                table.DataSource = PDF_dataTable.DataSource;

                //show header
                table.Style.ShowHeader = true;

                //set cell padding
                table.Style.CellPadding = 2;

                //set table layout
                PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
                tableLayout.Break     = PdfLayoutBreakType.FitElement;
                tableLayout.Layout    = PdfLayoutType.Paginate;
                table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

                //draw table to pdf page
                table.Draw(page, new RectangleF(10, 50, 500, 500), tableLayout);

                pdf.SaveToFile(PDFSaveDialog.FileName);
            }
        }
Пример #30
0
        private static void DrawTable(DataTable dt)
        {
            PdfTable table = new PdfTable
            {
                DataSource = dt
            };

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat
            {
                Break  = PdfLayoutBreakType.FitPage,
                Layout = PdfLayoutType.Paginate
            };

            table.Style.CellPadding                 = 2;
            table.Style.BorderPen                   = new PdfPen(Color.Transparent);
            table.Style.DefaultStyle.Font           = pageFont;
            table.Style.AlternateStyle.Font         = pageFont;
            table.Style.HeaderSource                = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Transparent;
            table.Style.HeaderStyle.Font            = pageFontBold;
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader                  = true;
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout); //ensures cells are transparent as well

            //Draw table
            try
            {
                currentTableLayout = table.Draw(currentPage, new PointF(GetLeftPage(), currentY), tableLayout);
                currentY          += currentTableLayout.Bounds.Height;
            }
            catch (PdfTableException)
            {
                currentPage = document.Pages.Add();
                DrawTable(dt);
            }
        }
Пример #31
0
        /// <summary>
        /// Add a table to the current page
        /// </summary>
        /// <param name="table"></param>
        public void AddTable(Table table)
        {
            this.checkBuilderState();

            PdfTable pdfTable = new PdfTable(this.page, this.contents);

            // calculate table area relative to the page dimensions and current page position
            double left   = this.documentOptions.MarginLeft;
            double bottom = this.documentOptions.MarginBottom;
            double right  = (this.page.Width / this.page.ScaleFactor) - this.documentOptions.MarginRight;
            double top    = this.pagePosition.Y;

            pdfTable.TableArea = new PdfRectangle(left, bottom, right, top);

            // set table columns widths
            if (table.Options.ColumnWidths == null)
            {
                table.Options.ColumnWidths = new List <double>();
                foreach (var cell in table.HeaderRow.Cells)
                {
                    // by default all column widths will be same size
                    table.Options.ColumnWidths.Add(1.0);
                }
            }
            pdfTable.SetColumnWidth(table.Options.ColumnWidths.ToArray());

            // set border widths and colors
            double borderHeaderWidth     = table.Options.BorderHeader.BorderWidth / this.document.ScaleFactor;
            double borderTopWidth        = table.Options.BorderTop.BorderWidth / this.document.ScaleFactor;
            double borderBottomWidth     = table.Options.BorderBottom.BorderWidth / this.document.ScaleFactor;
            double borderHorizontalWidth = table.Options.BorderHorizontal.BorderWidth / this.document.ScaleFactor;
            double borderVerticalWidth   = table.Options.BorderVertical.BorderWidth / this.document.ScaleFactor;

            pdfTable.Borders.ClearAllBorders();

            if (borderHeaderWidth > 0.0)
            {
                pdfTable.Borders.HeaderHorBorder.Set(borderHeaderWidth, table.Options.BorderHeader.BorderColor);
            }

            if (borderTopWidth > 0.0)
            {
                pdfTable.Borders.TopBorder.Set(borderTopWidth, table.Options.BorderTop.BorderColor);
            }

            if (borderBottomWidth > 0.0)
            {
                pdfTable.Borders.BottomBorder.Set(borderBottomWidth, table.Options.BorderBottom.BorderColor);
            }

            if (borderHorizontalWidth > 0.0)
            {
                pdfTable.Borders.CellHorBorder.Set(borderHorizontalWidth, table.Options.BorderHorizontal.BorderColor);
            }

            if (borderVerticalWidth > 0.0)
            {
                // vertical border lines
                pdfTable.Borders.HeaderVertBorder[0].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
                pdfTable.Borders.CellVertBorder[0].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
                for (int Index = 1; Index < pdfTable.Columns; Index++)
                {
                    pdfTable.Borders.HeaderVertBorder[Index].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
                    pdfTable.Borders.CellVertBorder[Index].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
                }
                pdfTable.Borders.HeaderVertBorder[pdfTable.Columns].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
                pdfTable.Borders.CellVertBorder[pdfTable.Columns].Set(borderVerticalWidth, table.Options.BorderVertical.BorderColor);
            }

            // default header styles
            pdfTable.DefaultHeaderStyle.TextBoxTextJustify = TextBoxJustify.Left;
            pdfTable.DefaultHeaderStyle.Alignment          = ContentAlignment.BottomLeft;
            pdfTable.DefaultHeaderStyle.BackgroundColor    = Color.Transparent;
            //pdfTable.DefaultHeaderStyle.MultiLineText = true;
            pdfTable.DefaultHeaderStyle.TextBoxLineBreakFactor = 0.2;

            // default cell styles
            pdfTable.DefaultCellStyle.TextBoxTextJustify = TextBoxJustify.Left;
            pdfTable.DefaultCellStyle.Alignment          = ContentAlignment.BottomLeft;
            pdfTable.DefaultCellStyle.BackgroundColor    = Color.Transparent;
            //pdfTable.DefaultCellStyle.MultiLineText = true;
            pdfTable.DefaultCellStyle.TextBoxLineBreakFactor = 0.2;
            //pdfTable.DefaultCellStyle.MinHeight = 2.0;

            // header columns
            for (int index = 0; index < table.Options.ColumnWidths.Count; index++)
            {
                var cell = table.HeaderRow.Cells[index];

                pdfTable.Header[index].Style = new PdfTableStyle()
                {
                    Font            = this.getPdfFont(cell.Options.FontOptions),
                    FontSize        = cell.Options.FontOptions.FontSize,
                    Alignment       = Helpers.Convert.ToContentAlignment(cell.Options.TextAlignment),
                    ForegroundColor = cell.Options.FontOptions.FontColor,
                    BackgroundColor = cell.Options.BackgroundColor,
                    Margin          = new PdfRectangle(cell.Options.CellPadding)
                };

                pdfTable.Header[index].Type  = CellType.Text;
                pdfTable.Header[index].Value = cell.Text;
            }

            // rows
            foreach (var row in table.Rows)
            {
                for (int index = 0; index < table.Options.ColumnWidths.Count; index++)
                {
                    var cell = row.Cells[index];

                    pdfTable.Cell[index].Style = new PdfTableStyle()
                    {
                        Font            = this.getPdfFont(cell.Options.FontOptions),
                        Alignment       = Helpers.Convert.ToContentAlignment(cell.Options.TextAlignment),
                        FontSize        = cell.Options.FontOptions.FontSize,
                        ForegroundColor = cell.Options.FontOptions.FontColor,
                        BackgroundColor = cell.Options.BackgroundColor,
                        Margin          = new PdfRectangle(cell.Options.CellPadding)
                    };

                    pdfTable.Cell[index].Type       = CellType.Text;
                    pdfTable.Cell[index].Value      = cell.Text;
                    pdfTable.Cell[index].CellHeight = 10.0 / this.document.ScaleFactor;
                }

                pdfTable.DrawRow();
            }

            pdfTable.Close();
        }
Пример #32
0
        // Generates document
        public static void Generate(ILogger logger, YesNo useTestMode = YesNo.No)
        {
            #region Initialize timer
            var sw = new Stopwatch();
            sw.Start();
            #endregion

            #region page-1

            var page1 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-1.pdf"
            };

            // Inserts report title
            page1.Replace(new ReplaceText(
                              new WithTextObject
            {
                Text           = "#TITLE#",
                NewText        = "Lorem ipsum",
                UseTestMode    = useTestMode,
                TextOffset     = PointF.Empty,
                Style          = TextStylesTable["ReportTitle"],
                ReplaceOptions = ReplaceTextOptions.AccordingToMargins
            }));


            // Inserts bar-chart image
            using (var barGraph = PdfImage.FromFile("~/Resources/Sample-04/Images/bar-chart.png"))
            {
                page1.Replace(new ReplaceText(
                                  new WithImageObject
                {
                    Text           = "#BAR-CHART#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Default"],
                    ReplaceOptions = ReplaceTextOptions.AccordingToMargins,
                    Image          = barGraph
                }));
            }

            #endregion

            #region page-2

            var page2 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-2.pdf"
            };

            // Inserts html table
            page2.Replace(new ReplaceText(
                              new WithTableObject
            {
                Text           = "#DATA-TABLE#",
                UseTestMode    = useTestMode,
                TableOffset    = PointF.Empty,
                Style          = PdfTableStyle.Default,
                ReplaceOptions = ReplaceTextOptions.FromPositionToRightMargin,
                Table          = PdfTable.CreateFromHtml(GenerateHtmlDatatable())
            }));

            #endregion

            #region page-3

            var page3 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-3.pdf"
            };

            #endregion

            #region page-4

            var page4 = new PdfInput
            {
                AutoUpdateChanges = true,
                Input             = "~/Resources/Sample-04/file-sample-4.pdf"
            };

            // Inserts image
            using (var image = PdfImage.FromFile("~/Resources/Sample-04/Images/image-1.jpg"))
            {
                page4.Replace(new ReplaceText(
                                  new WithImageObject
                {
                    Text           = "#IMAGE1#",
                    UseTestMode    = useTestMode,
                    ImageOffset    = PointF.Empty,
                    Style          = ImagesStylesTable["Center"],
                    ReplaceOptions = ReplaceTextOptions.AccordingToMargins,
                    Image          = image
                }));
            }

            #endregion

            #region merge

            // Defines global text replacements to replace > header text
            var globalReplacements = new GlobalReplacementsCollection
            {
                new WithTextObject
                {
                    Text           = "#HEADER-TEXT#",
                    NewText        = "Report Name - Lorem ipsum dolor",
                    Style          = TextStylesTable["Header"],
                    ReplaceOptions = ReplaceTextOptions.FromLeftMarginToNextElement,
                    UseTestMode    = useTestMode,
                    TextOffset     = PointF.Empty
                }
            };

            var files = new PdfObject(new PdfObjectConfig {
                GlobalReplacements = globalReplacements
            })
            {
                Items = new List <PdfInput>
                {
                    new PdfInput {
                        Index = 0, Input = page1
                    },
                    new PdfInput {
                        Index = 1, Input = page2
                    },
                    new PdfInput {
                        Index = 2, Input = page3
                    },
                    new PdfInput {
                        Index = 3, Input = page4
                    },
                }
            };

            var mergeResult = files.TryMergeInputs();
            if (!mergeResult.Success)
            {
                logger.Info("   > Error creating output merge result");
                logger.Info($"     > Error: {mergeResult.Errors.AsMessages().ToStringBuilder()}");
                return;
            }

            #endregion

            #region save

            // Saves merged result to disk
            var saveResult = mergeResult.Result.Action(new SaveToFile {
                OutputPath = "~/Output/Sample04/Sample-04"
            });
            var ts = sw.Elapsed;
            sw.Stop();

            if (!saveResult.Success)
            {
                logger.Info("   > Error while saving to disk");
                logger.Info($"     > Error: {saveResult.Errors.AsMessages().ToStringBuilder()}");
                logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");
                return;
            }

            logger.Info("   > Saved to disk correctly");
            logger.Info("     > Path: ~/Output/Sample04/Sample-04.pdf");
            logger.Info($"   > Elapsed time: { ts.Hours:00}:{ ts.Minutes:00}:{ ts.Seconds:00}.{ ts.Milliseconds / 10:00}");

            #endregion
        }
Пример #33
0
        protected void PDFQuote(Object source, EventArgs e)
        {
            //demos: http://www.e-iceblue.com/Tutorials/Spire.PDF/Demos.html //had to add permissions to IIS Express Folder for Network Users. Wont export more than 10 pages on free version.

            SaveQuote();

            var filename = PdfFileName.Value;
            if (filename == "CANCELDONOTMAKE") return;

            PdfDocument pdf = new PdfDocument();
            PdfPageBase page = pdf.Pages.Add();
                float pageWidth = page.Canvas.ClientSize.Width;
                float y = 0;

            //formatting helpers
            PdfStringFormat centered = new PdfStringFormat(PdfTextAlignment.Center);
            PdfStringFormat rightAlign = new PdfStringFormat(PdfTextAlignment.Right);
            PdfFont helv24 = new PdfFont(PdfFontFamily.Helvetica, 24f, PdfFontStyle.Bold);
            PdfFont helv20 = new PdfFont(PdfFontFamily.Helvetica, 20f, PdfFontStyle.Bold);
            PdfFont helv16 = new PdfFont(PdfFontFamily.Helvetica, 16f, PdfFontStyle.Bold);
            PdfFont helv14 = new PdfFont(PdfFontFamily.Helvetica, 14f);
            PdfFont helv12 = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfFont helv12Bold = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            PdfFont helv11 = new PdfFont(PdfFontFamily.Helvetica, 11f);
            PdfFont helv9Ital = new PdfFont(PdfFontFamily.Helvetica, 9f, PdfFontStyle.Italic);
            PdfFont helv8  = new PdfFont(PdfFontFamily.Helvetica, 8f);
            PdfBrush black = new PdfSolidBrush(Color.Black);
            SizeF size;

            string brand = "Texas Digital Systems, Inc.";
            string address = "400 Technology Parkway  College Station, TX 77845";
            string contact = "(979) 693-9378 Voice  (979) 764-8650 Fax";
            string title = "Proposal Summary";

            //HEADER
            page.Canvas.DrawString(brand, helv24, new PdfSolidBrush(Color.Black), pageWidth/2, y, centered);
                size = helv24.MeasureString(brand);
                y += size.Height + 1;
            page.Canvas.DrawString(address, helv12, black, pageWidth/2, y, centered);
                size = helv12.MeasureString(address);
                y += size.Height + 1;
            page.Canvas.DrawString(contact, helv12, black, pageWidth / 2, y, centered);
                size = helv12.MeasureString(contact);
                y += size.Height + 1;
            page.Canvas.DrawString("By: " + quote.Owner, helv12, black, 0, y);
            page.Canvas.DrawString(quote.Email, helv12, black, pageWidth, y, rightAlign);
            size = helv12.MeasureString(contact);
            y += size.Height + 1;
            page.Canvas.DrawString("Date: " + quote.Date, helv12, black, 0, y);
            page.Canvas.DrawString("PN: " + quote.PhoneNumber, helv12, black, pageWidth, y, rightAlign);
                size = helv12.MeasureString(quote.Owner);
                y += size.Height + 5;
            page.Canvas.DrawString(title, helv20, black, pageWidth / 2, y, centered);
                size = helv20.MeasureString(title);
                y += size.Height + 5;

            //ADDRESS TABLE
            PdfTable addressTable = new PdfTable();
            addressTable.Style.CellPadding = 1;
            addressTable.Style.BorderPen = new PdfPen(PdfBrushes.Black, .5f);

            string[] addressData
                = {
                      ";Customer Address;Billing Address;Shipping Address",
                      "Contact;"+quote.Customer.Contact+";"+quote.Billing.Contact+";"+quote.Shipping.Contact,
                      "Company;"+quote.Customer.Company+";"+quote.Billing.Company+";"+quote.Shipping.Company,
                      "Address1;"+quote.Customer.Address1+";"+quote.Billing.Address1+";"+quote.Shipping.Address1,
                      "Address2;"+quote.Customer.Address2+";"+quote.Billing.Address2+";"+quote.Shipping.Address2,
                      "City/State/Zip;"+quote.Customer.CityState+";"+quote.Billing.CityState+";"+quote.Shipping.CityState,
                      "Phone;"+quote.Customer.Phone+";"+quote.Billing.Phone+";"+quote.Shipping.Phone,
                      "Fax;"+quote.Customer.Fax+";"+quote.Billing.Fax+";"+quote.Shipping.Fax,
                      "Email;"+quote.Customer.Email+";"+quote.Billing.Email+";"+quote.Shipping.Email
                  };

            string[][] addressDataSource = new string[addressData.Length][];
            for (int i = 0; i < addressData.Length; i++)
                addressDataSource[i] = addressData[i].Split(';');

            addressTable.DataSource = addressDataSource;
            float width = page.Canvas.ClientSize.Width - (addressTable.Columns.Count + 1) * addressTable.Style.BorderPen.Width;
            for (int i = 0; i < addressTable.Columns.Count; i++)
            {
                if(i==0)
                    addressTable.Columns[i].Width = width * .12f * width;
                else
                    addressTable.Columns[i].Width = width * .2f * width;
            }
            addressTable.BeginRowLayout += new BeginRowLayoutEventHandler(addressTable_BeginRowLayout);

            PdfLayoutResult addressResult = addressTable.Draw(page, new PointF(0, y));
            y += addressResult.Bounds.Height + 5;

            //QUOTE DETAILS
            PdfTable detailsTable = new PdfTable();
            detailsTable.Style.CellPadding = 1;
            detailsTable.Style.BorderPen = new PdfPen(PdfBrushes.Black, .5f);
            detailsTable.Style.DefaultStyle.Font = helv11;
            detailsTable.Style.DefaultStyle.StringFormat = centered;
            width = page.Canvas.ClientSize.Width - (detailsTable.Columns.Count + 1) * detailsTable.Style.BorderPen.Width;

            //converting t/f to y/n
            string NewLocation, Dealer, TaxExempt;
            if (quote.NewLocation) NewLocation = "Yes";
                else NewLocation = "No";
            if (quote.Dealer) Dealer = "Yes";
                else Dealer = "No";
            if (quote.TaxExempt == "exempt") TaxExempt = "Yes";
                else TaxExempt = "No";

            string[] detailsData
                = {
                      "Source: ;"+quote.Source+";Source Specific: ;"+quote.SpecificSource+";No. Of Locations: ;"+quote.LocationCount,
                      "POS Provider: ;"+quote.POSProvidor+";Install Date: ;"+quote.InstallDate+";Business Unit: ;"+quote.BusinessUnit,
                      "New Location: ;"+NewLocation+";Dealer: ;"+Dealer+";Tax Exempt: ;"+TaxExempt
                  };

            string[][] detailsDataSource = new string[detailsData.Length][];
            for (int i = 0; i < detailsData.Length; i++)
                detailsDataSource[i] = detailsData[i].Split(';');

            detailsTable.DataSource = detailsDataSource;
            for (int i = 0; i < detailsTable.Columns.Count; i++)
            {
                if (i %2 != 0)
                    detailsTable.Columns[i].Width = width * .05f * width;
                else
                    detailsTable.Columns[i].Width = width * .08f * width;
            }

            PdfLayoutResult detailsResult = detailsTable.Draw(page, new PointF(0, y));
            y += detailsResult.Bounds.Height + 5;

            //QUOTE LINES
            if(quote.linesHW.Count > 0)
            {
                page.Canvas.DrawString("Hardware", helv16, black, pageWidth / 2, y, centered);
                    size = helv14.MeasureString("Hardware");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesHW,"Hardware", y)).Bounds.Height + 2;
            }

            if(quote.linesSW.Count > 0)
            {
                page.Canvas.DrawString("Software", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Software & Maintenance");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesSW,"Software", y)).Bounds.Height + 2;
            }

            if(quote.linesCC.Count > 0)
            {
                page.Canvas.DrawString("Content", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Content");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesCC,"Content", y)).Bounds.Height + 2;
            }

            if(quote.linesInst.Count > 0)
            {
                page.Canvas.DrawString("Installation", helv16, black, pageWidth / 2, y, centered);
                    size = helv16.MeasureString("Installation");
                    y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesInst, "Installation", y)).Bounds.Height + 2;
            }

            if (quote.linesRec.Count > 0)
            {
                page.Canvas.DrawString("Recurring", helv16, black, pageWidth / 2, y, centered);
                size = helv16.MeasureString("Recurring");
                y += size.Height + 2;
                y += (buildPdfLines(page, quote.linesRec, "Recurring", y)).Bounds.Height + 2;
            }

            bool FreightExists = false; if (quote.Freight > 0) FreightExists = true;
            bool SalesTaxExists = false; if (quote.SalesTax > 0) SalesTaxExists = true;
            double GrandTotal = quote.GetGrandTotal();

            //NOTES
            if (quote.ExternalNotes.Length > 0)
            {
                string notes = quote.ExternalNotes;
                PdfStringLayouter layouter = new PdfStringLayouter();
                PdfStringFormat format = new PdfStringFormat();
                format.LineSpacing = helv11.Size * 1.5f;

                PdfStringLayoutResult result = layouter.Layout(notes, helv11, format, new SizeF(pageWidth, y));

                page.Canvas.DrawString("Notes", helv14, black, pageWidth / 2, y, centered);
                size = helv14.MeasureString("LULZ");
                y += size.Height + 2;

                foreach (LineInfo line in result.Lines)
                {
                    page.Canvas.DrawString(line.Text, helv11, black, 0, y, format);
                    y = y + result.LineHeight;
                }

            }

            y += 5;
            page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, y), new PointF(pageWidth, y));
            y += 5;

            //TOTALS
            if(FreightExists || SalesTaxExists)
            {
                page.Canvas.DrawString("Subtotal: $" + GrandTotal.ToString(), helv12, black, 0, y);
            }
            if(FreightExists)
            {
                page.Canvas.DrawString("Freight: $" + quote.Freight.ToString(), helv12, black, pageWidth/4, y);
                GrandTotal += quote.Freight;
            }
            if (SalesTaxExists)
            {
                page.Canvas.DrawString("Sales Tax: $" + quote.SalesTax.ToString(), helv12, black, pageWidth / 2, y);
                GrandTotal += quote.SalesTax;
            }

            page.Canvas.DrawString("Total: $" + GrandTotal.ToString(), helv12Bold, black, pageWidth, y, rightAlign);
                size = helv12Bold.MeasureString("999999");

            y += size.Height + 5;
            page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, y), new PointF(pageWidth, y));
            y += 5;

            //FINE PRINT
            page.Canvas.DrawString("Quote is good for: " + quote.QuoteLength + " days", helv8, black, 0, y);
            page.Canvas.DrawString("F.O.B. College Station, TX", helv8, black, pageWidth / 2, y, centered);
            page.Canvas.DrawString("Payment Terms: " + quote.PaymentTerms, helv8, black, pageWidth, y, rightAlign);
                size = helv8.MeasureString("THESE WORDS DON'T MATTER");
                y += size.Height + 1;

            page.Canvas.DrawString("This is not an invoice and may not include freight and/or sales tax. An invoice will be sent upon receipt of the signed quote.", helv9Ital, black, pageWidth/2, y, centered);
                size = helv9Ital.MeasureString("ONLY DEVS WILL SEE THIS");
                y += size.Height + 10;

            page.Canvas.DrawString("Please sign to accept this quotation: ", helv8, black, 0, y);
                size = helv8.MeasureString("I CAN SAY WHATEVER I WANT");
                page.Canvas.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(150, y+size.Height), new PointF(350, y+size.Height));
                y += size.Height + 1;

            page.Canvas.DrawString("By signing I agree that I have read, understand and agree to be bound by the Texas Digital Standard Terms and Conditions Applicable to", helv8, black, 0, y);
                size = helv8.MeasureString("PAY UP GUY");
                y += size.Height + 1;

            page.Canvas.DrawString("Quotes and Purchase Orders accessible at: ", helv8, black, 0, y);
                size = helv8.MeasureString("Quotes and Purchase Orders accessible at: ");
                page.Canvas.DrawString("http://www.ncr.com/wp-content/uploads/TXDigital_Terms_and_Conditions.pdf", helv8, PdfBrushes.DarkGreen, size.Width, y);
                y += size.Height + 1;

            page.Canvas.DrawString("After signing please fax to (979) 764-8650", helv8, black, 0, y);
            page.Canvas.DrawString("Delivery ARO: 45-60 days", helv8, black, pageWidth, y, rightAlign);
                size = helv8.MeasureString("THIS ISNT THE END LOL");
                y += size.Height + 1;

            //pdf.SaveToFile(filename);
            pdf.SaveToHttpResponse(filename, Response, HttpReadType.Save);
            pdf.Close();
            System.Diagnostics.Process.Start(filename);
        }
Пример #34
0
        private PdfLayoutResult DrawOrderItems(PdfPageBase page, DataTable orderItems, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.MediumTurquoise;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.PaleTurquoise;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.Teal;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource = orderItems;
            for (int i = 2; i < table.Columns.Count; i++)
            {
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Right);
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitPage;
            tableLayout.Layout = PdfLayoutType.Paginate;

            return table.Draw(page, new PointF(0, y), tableLayout);
        }
Пример #35
0
        private String crearPDFoculto(String title, String[][] dataSource, String[] extraInfo)
        {
            //create a new pdf document
            PdfDocument pdfDoc = new PdfDocument();

            //add one blank page
            PdfPageBase page = pdfDoc.Pages.Add();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.BlueViolet;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Calibri", 13f)); ;
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString(title, font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString(title, format1).Height;
            y = y + 5;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            if (extraInfo != null)
            {
                PdfBrush brush2 = PdfBrushes.Green;
                PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
                foreach (String item in extraInfo)
                {
                    page.Canvas.DrawString(item, font2, brush2, 5, y);
                    y = y + font2.MeasureString(item, format1).Height;
                    y = y + 5;
                }
            }

            //page.Canvas.DrawString(String.Format("* {0} productos en la base de datos.", dataSource.Length - 1), font2, brush2, 5, y);
            //save the pdf document
            String filename = "data/" + title + ".pdf";
            pdfDoc.SaveToFile(@filename);
            return filename;

            //launch the pdf document
            //System.Diagnostics.Process.Start(@filename);
        }
Пример #36
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Name,Capital,Continent,Area,Population from country ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            table.Columns[0].Width = width * 0.24f * width;
            table.Columns[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[1].Width = width * 0.21f * width;
            table.Columns[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[2].Width = width * 0.24f * width;
            table.Columns[2].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[3].Width = width * 0.13f * width;
            table.Columns[3].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            table.Columns[4].Width = width * 0.18f * width;
            table.Columns[4].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString(String.Format("* {0} countries in the list.", table.Rows.Count),
                font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("DataSource.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("DataSource.pdf");
        }
Пример #37
0
        private PdfLayoutResult DrawTable(PdfPageBase page, float y)
        {
            PdfBrush brush1 = PdfBrushes.Black;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Description, OnHand, OnOrder, Cost, ListPrice from parts ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for (int i = 0; i < table.Columns.Count; i++)
            {
                if (i == 0)
                {
                    table.Columns[i].Width = width * 0.40f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    table.Columns[i].Width = width * 0.15f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
            y = result.Bounds.Bottom + 3;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* {0} parts in the list.", table.Rows.Count),
                font2, brush2, 5, y);

            return result;
        }
Пример #38
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Country List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Country List", format1).Height;
            y = y + 5;

            String[] data
                = {
                    "Name;Capital;Continent;Area;Population",
                    "Argentina;Buenos Aires;South America;2777815;32300003",
                    "Bolivia;La Paz;South America;1098575;7300000",
                    "Brazil;Brasilia;South America;8511196;150400000",
                    "Canada;Ottawa;North America;9976147;26500000",
                    "Chile;Santiago;South America;756943;13200000",
                    "Colombia;Bagota;South America;1138907;33000000",
                    "Cuba;Havana;North America;114524;10600000",
                    "Ecuador;Quito;South America;455502;10600000",
                    "El Salvador;San Salvador;North America;20865;5300000",
                    "Guyana;Georgetown;South America;214969;800000",
                    "Jamaica;Kingston;North America;11424;2500000",
                    "Mexico;Mexico City;North America;1967180;88600000",
                    "Nicaragua;Managua;North America;139000;3900000",
                    "Paraguay;Asuncion;South America;406576;4660000",
                    "Peru;Lima;South America;1285215;21600000",
                    "United States of America;Washington;North America;9363130;249200000",
                    "Uruguay;Montevideo;South America;176140;3002000",
                    "Venezuela;Caracas;South America;912047;19700000"
                };

            String[][] dataSource
                = new String[data.Length][];
            for (int i = 0; i < data.Length; i++)
            {
                dataSource[i] = data[i].Split(';');
            }

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader = true;
            table.DataSource = dataSource;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y));
            y = y + result.Bounds.Height + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            page.Canvas.DrawString(String.Format("* {0} countries in the list.", data.Length - 1),
                font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("SimpleTable.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleTable.pdf");
        }
Пример #39
0
        private PdfTable DesignPdfTable(PdfBrush brushColor)
        {
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brushColor, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.Gray;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightGray;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.White;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            return table;
        }
Пример #40
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 1;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.Style.RepeatHeader = true;
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select * from parts ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    dataTable.Columns.RemoveAt(1);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for(int i = 0; i < table.Columns.Count; i++)
            {
                if (i == 1)
                {
                    table.Columns[i].Width = width * 0.4f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    table.Columns[i].Width = width * 0.12f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
            y = result.Bounds.Bottom + 5;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* All {0} parts in the list", table.Rows.Count), 
                font2, brush2, 5, y);

            //Save pdf file.
            doc.SaveToFile("TableLayout.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("TableLayout.pdf");
        }
Пример #41
0
        public FileResult Download(int year, int id)
        {
            //Create a pdf document.<br>
            PdfDocument doc = new PdfDocument();
            Participant data = TheRace.Historical(year).Participants.Where(p => p.Startnumber == id).First();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(1f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create new page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);
            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;

            PdfFont font32b = new PdfFont(PdfFontFamily.Helvetica, 40f, PdfFontStyle.Bold); ;
            PdfFont font32 = new PdfFont(PdfFontFamily.TimesRoman, 32f, PdfFontStyle.Regular);
            PdfFont font20b = new PdfFont(PdfFontFamily.TimesRoman, 20f, PdfFontStyle.Bold);
            PdfFont font20 = new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Regular);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            format1.WordWrap = PdfWordWrapType.Word;

            //Draw the image
            PdfImage image = PdfImage.FromFile(Server.MapPath("~/Content/Images/price.jpg"));
            float width = image.Width;
            float height = image.Height;
            float x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, x, y, width, height);

            page.Canvas.DrawString(data.Splits(data.Classes[0].Id).Last().Position.ToString() + ".", font32b, brush1, x + 60, y + 50, format1);

            y = image.Height;

            page.Canvas.DrawString(data.Name, font32b, brush1, 0, y, format1);

            y = y + font32b.MeasureString(data.Name, format1).Height + 15;

            foreach (ParticipantClass c in data.Classes.Where(c => c.Official))
            {
                StringBuilder sb = new StringBuilder(c.Name);
                sb.Append(" - ");
                var res = data.Leg(c.Id, 248);
                if (res != null)
                    sb.Append(data.Leg(c.Id, 248).Position);
                sb.Append(".plass");

                page.Canvas.DrawString(sb.ToString(), font20, brush1, 0, y, format1);
                y += font20.MeasureString(sb.ToString(), format1).Height + 15;
            }

            List<String[]> splits = data.Splits(data.Classes[0].Id).Select(p => new String[] { p.Leg, p.IsSuper ? "" : p.Name, p.Time }).ToList<String[]>();
            if (splits.Count() > 0)
            {
                splits.Add(new String[] { "Totaltid", "", data.TotalTime });

                y = y + 30;

                page.Canvas.DrawString("Etappetider", font20b, brush1, 0, y, format1);
                y += font20b.MeasureString("Etappetider", format1).Height + 5;

                PdfTable table = new PdfTable();
                table.Style.BorderPen = new PdfPen(Color.Transparent);
                table.Style.DefaultStyle.TextBrush = brush1;
                table.Style.DefaultStyle.Font = font20;
                table.Style.DefaultStyle.BorderPen = new PdfPen(Color.Transparent);
                table.Style.CellPadding = 2;
                table.Style.HeaderSource = PdfHeaderSource.Rows;
                table.Style.HeaderRowCount = 0;
                table.Style.ShowHeader = false;
                table.Style.AlternateStyle = new PdfCellStyle();

                table.Style.AlternateStyle.TextBrush = brush1;
                table.Style.AlternateStyle.Font = font20;
                table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightGray;
                table.Style.AlternateStyle.BorderPen = new PdfPen(Color.Transparent);

                table.DataSource = splits.ToArray<String[]>();

                PdfLayoutResult result = table.Draw(page, new PointF(0, y));

                y = y + result.Bounds.Height + 5;

            }

            StringBuilder s = new StringBuilder("Start # ");
            s.Append(data.Startnumber.ToString());
            s.Append("    Emit # ");
            s.Append(data.EmitID.ToString());

            y += 50;

            page.Canvas.DrawString(s.ToString(), font20, brush1, page.Canvas.ClientSize.Width / 2, y, format1);

            y = page.Canvas.ClientSize.Height - 60;

            image = PdfImage.FromFile(Server.MapPath("~/Content/Images/kjeringi2016_logo-2.png"));
            width = image.Width;
            height = image.Height;
            x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, 0, y, width, height);

            image = PdfImage.FromFile(Server.MapPath("~/Content/Images/difi-logo.png"));
            width = image.Width;
            height = image.Height;
            x = page.Canvas.ClientSize.Width - width;
            page.Canvas.DrawImage(image, x, y, width, height);

            doc.SaveToFile(@"c:\temp\KjeringiOpen-" + year.ToString() + "_" + id.ToString() + ".pdf");

            return File(@"c:\temp\KjeringiOpen-" + year.ToString() + "_" + id.ToString() + ".pdf", "application/pdf");
        }
Пример #42
0
        private PdfLayoutResult DrawPart(PdfPageBase page, DataTable parts, int index, String title, float y)
        {
            //draw title
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            DataRow row = parts.Rows[index];
            page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y);
            y = y + font1.MeasureString(title).Height + 1;

            //draw table
            Object[][] data = new Object[2][];
            data[0] = new String[parts.Columns.Count];
            for (int i = 0; i < parts.Columns.Count; i++)
            {
                data[0][i] = parts.Columns[i].ColumnName;
            }
            data[1] = row.ItemArray;

            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(PdfBrushes.Black, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.GreenYellow;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f));
            table.Style.HeaderSource = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.ForestGreen;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;
            table.DataSource = data;

            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for (int i = 0; i < table.Columns.Count; i++)
            {
                table.Columns[i].Width = i == 1 ? width * 0.35f : width * 0.13f;
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitPage;
            tableLayout.Layout = PdfLayoutType.Paginate;

            return table.Draw(page, new PointF(0, y), tableLayout);
        }
Пример #43
0
        private PdfPageBase DrawPages(PdfDocument doc)
        {
            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            // Create one page
            PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin);

            float y = 10;

            //title
            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Part List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Part List", format1).Height;
            y = y + 5;

            //create data table
            PdfTable table = new PdfTable();
            table.Style.CellPadding = 2;
            table.Style.BorderPen = new PdfPen(brush1, 0.75f);
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.AlternateStyle = new PdfCellStyle();
            table.Style.AlternateStyle.BackgroundBrush = PdfBrushes.LightYellow;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.HeaderSource = PdfHeaderSource.ColumnCaptions;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.ShowHeader = true;

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                OleDbCommand command = new OleDbCommand();
                command.CommandText
                    = " select Description, OnHand, OnOrder, Cost, ListPrice from parts ";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    table.DataSourceType = PdfTableDataSourceType.TableDirect;
                    table.DataSource = dataTable;
                }
            }
            float width
                = page.Canvas.ClientSize.Width
                    - (table.Columns.Count + 1) * table.Style.BorderPen.Width;
            for (int i = 0; i < table.Columns.Count; i++)
            {
                if (i == 0)
                {
                    table.Columns[i].Width = width * 0.40f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                }
                else
                {
                    table.Columns[i].Width = width * 0.15f * width;
                    table.Columns[i].StringFormat
                        = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
                }
            }

            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();
            tableLayout.Break = PdfLayoutBreakType.FitElement;
            tableLayout.Layout = PdfLayoutType.Paginate;

            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);
            y = result.Bounds.Bottom + 3;

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            result.Page.Canvas.DrawString(String.Format("* {0} parts in the list.", table.Rows.Count),
                font2, brush2, 5, y);

            return result.Page;
        }