Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
0
        ////////////////////////////////////////////////////////////////////
        // Create charting examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void CreateBookList()
        {
            // Add new page
            Page = new PdfPage(Document);

            // Add contents to page
            Contents = new PdfContents(Page);

            PdfFont TitleFont  = PdfFont.CreatePdfFont(Document, "Verdana", FontStyle.Bold);
            PdfFont AuthorFont = PdfFont.CreatePdfFont(Document, "Verdana", FontStyle.Italic);

            // create stock table
            PdfTable BookList = new PdfTable(Page, Contents, NormalFont, 9.0);

            // divide columns width in proportion to following values
            BookList.SetColumnWidth(1.0, 2.5, 1.2, 1.0, 0.5, 0.6, 1.2);
            // event handlers
            BookList.TableStartEvent     += BookListTableStart;
            BookList.TableEndEvent       += BookListTableEnd;
            BookList.CustomDrawCellEvent += BookListDrawCellEvent;

            // set display header at the top of each additional page
            BookList.HeaderOnEachPage = true;

            // make some changes to default header style
            BookList.DefaultHeaderStyle.Alignment              = ContentAlignment.MiddleCenter;
            BookList.DefaultHeaderStyle.FontSize               = 9.0;
            BookList.DefaultHeaderStyle.MultiLineText          = true;
            BookList.DefaultHeaderStyle.TextBoxTextJustify     = TextBoxJustify.Center;
            BookList.DefaultHeaderStyle.BackgroundColor        = Color.Blue;
            BookList.DefaultHeaderStyle.ForegroundColor        = Color.LightCyan;
            BookList.DefaultHeaderStyle.TextBoxLineBreakFactor = 0.2;

            // headers
            BookList.Header[0].Value = "Book Cover";
            BookList.Header[1].Value = "Book Title and Authors";
            BookList.Header[2].Value = "Date\nPublished";
            BookList.Header[3].Value = "Type";
            BookList.Header[4].Value = "In\nStock";
            BookList.Header[5].Value = "Price";
            BookList.Header[6].Value = "Weblink";

            // default cell style
            BookList.DefaultCellStyle.Alignment = ContentAlignment.MiddleCenter;

            // create private style for type column
            BookList.Cell[3].Style = BookList.CellStyle;
            BookList.Cell[3].Style.RaiseCustomDrawCellEvent = true;

            // create private style for in stock column
            BookList.Cell[4].Style           = BookList.CellStyle;
            BookList.Cell[4].Style.Format    = "#,##0";
            BookList.Cell[4].Style.Alignment = ContentAlignment.MiddleRight;

            // create private style for price column
            BookList.Cell[5].Style           = BookList.CellStyle;
            BookList.Cell[5].Style.Format    = "#,##0.00";
            BookList.Cell[5].Style.Alignment = ContentAlignment.MiddleRight;

            // book list text file
            StreamReader Reader = new StreamReader("BookList.txt");

            // loop for records
            for (;;)
            {
                // read one line
                String TextLine = Reader.ReadLine();
                if (TextLine == null)
                {
                    break;
                }

                // split to fields (must be 8 fields)
                String[] Fld = TextLine.Split(new Char[] { '\t' });
                if (Fld.Length != 8)
                {
                    continue;
                }

                // book cover
                BookList.Cell[0].Value = new PdfImage(Document, Fld[6]);

                // note create text box set Value field
                TextBox Box = BookList.Cell[1].CreateTextBox();
                Box.AddText(TitleFont, 10.0, Color.DarkBlue, Fld[0]);
                Box.AddText(NormalFont, 8.0, Color.Black, ", Author(s): ");
                Box.AddText(AuthorFont, 9.0, Color.DarkRed, Fld[2]);

                // date, type in-stock and price
                BookList.Cell[2].Value = Fld[1];
                BookList.Cell[3].Value = Fld[3];
                BookList.Cell[4].Value = Int32.Parse(Fld[5]);
                BookList.Cell[5].Value = Double.Parse(Fld[4], NFI.PeriodDecSep);

                // QRCode and web link
                BookList.Cell[6].Value   = new PdfQRCode(Document, Fld[7], ErrorCorrection.M);
                BookList.Cell[6].WebLink = Fld[7];

                // other examples of interactive features
                //BookList.Cell[6].AnnotAction = new AnnotWebLink(Fld[7]);
                //BookList.Cell[6].AnnotAction = new AnnotLinkAction("Chapter7");
                //PdfDisplayMedia Omega = new PdfDisplayMedia(PdfEmbeddedFile.CreateEmbeddedFile(Document, "Omega.mp4"));
                //BookList.Cell[6].AnnotAction = new AnnotDisplayMedia(Omega);
                //PdfDisplayMedia RingSound = new PdfDisplayMedia(PdfEmbeddedFile.CreateEmbeddedFile(Document, "Ring01.wav"));
                //BookList.Cell[6].AnnotAction = new AnnotDisplayMedia(RingSound);
                //PdfEmbeddedFile EmbeddedFile = PdfEmbeddedFile.CreateEmbeddedFile(Document, "BookList.txt");
                //BookList.Cell[6].AnnotAction = new AnnotFileAttachment(EmbeddedFile, FileAttachIcon.NoIcon);

                // draw it
                BookList.DrawRow();
            }

            // close book list
            BookList.Close();

            // exit
            return;
        }
Пример #4
0
        ////////////////////////////////////////////////////////////////////
        // Create textbox overflow example
        ////////////////////////////////////////////////////////////////////

        public void TestOverflow()
        {
            // Add new page
            Page = new PdfPage(Document);

            // Add contents to page
            Contents = new PdfContents(Page);

            // create table
            PdfTable Table = new PdfTable(Page, Contents, NormalFont, 9.0);

            // Commit
            Table.CommitToPdfFile     = true;
            Table.CommitGCCollectFreq = 1;

            // divide columns width in proportion to following values
            Table.SetColumnWidth(1.0, 2.75, 2.75);

            Table.Header[0].Value = "Column 1";
            Table.Header[1].Value = "Column 2";
            Table.Header[2].Value = "Column 3";

            Table.Cell[1].Style = Table.CellStyle;
            Table.Cell[1].Style.MultiLineText         = true;
            Table.Cell[1].Style.TextBoxPageBreakLines = 4;

            Table.Cell[2].Style = Table.CellStyle;
            Table.Cell[2].Style.MultiLineText         = true;
            Table.Cell[2].Style.TextBoxPageBreakLines = 8;

            Int32[] Lines1 = { 40, 90, 20 };
            Int32[] Lines2 = { 20, 50, 70 };

            for (Int32 Row = 0; Row < 3; Row++)
            {
                Table.Cell[0].Value = String.Format("Row {0}", Row + 1);

                StringBuilder Text1 = new StringBuilder();
                for (Int32 Line = 0; Line < Lines1[Row % 3]; Line++)
                {
                    Text1.AppendFormat("Line {0}\r\n", Line + 1);
                }
                Table.Cell[1].Value = Text1.ToString();

                StringBuilder Text2 = new StringBuilder();
                for (Int32 Line = 0; Line < Lines2[Row % 3]; Line++)
                {
                    Text2.AppendFormat("Line {0}\r\n", Line + 1);
                }
                Table.Cell[2].Value = Text2.ToString();

                Table.DrawRow();

                // DEBUG
                //Trace.Write(String.Format("Total Memory: {0}", GC.GetTotalMemory(false)));
            }

            Table.Close();

            // exit
            return;
        }
Пример #5
0
        ////////////////////////////////////////////////////////////////////
        // Create charting examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void CreateStockTable()
        {
            const Int32 ColDate   = 0;
            const Int32 ColOpen   = 1;
            const Int32 ColHigh   = 2;
            const Int32 ColLow    = 3;
            const Int32 ColClose  = 4;
            const Int32 ColVolume = 5;

            // Add new page
            Page = new PdfPage(Document);

            // Add contents to page
            Contents = new PdfContents(Page);

            // create stock table
            PdfTable StockTable = new PdfTable(Page, Contents, NormalFont, 9.0);

            // divide columns width in proportion to following values
            StockTable.SetColumnWidth(1.2, 1.0, 1.0, 1.0, 1.0, 1.2);

            // set all borders
            StockTable.Borders.SetAllBorders(0.012, Color.DarkGray, 0.0025, Color.DarkGray);

            // make some changes to default header style
            StockTable.DefaultHeaderStyle.Alignment = ContentAlignment.BottomRight;

            // create private style for header first column
            StockTable.Header[ColDate].Style           = StockTable.HeaderStyle;
            StockTable.Header[ColDate].Style.Alignment = ContentAlignment.MiddleLeft;

            StockTable.Header[ColDate].Value   = "Date";
            StockTable.Header[ColOpen].Value   = "Open";
            StockTable.Header[ColHigh].Value   = "High";
            StockTable.Header[ColLow].Value    = "Low";
            StockTable.Header[ColClose].Value  = "Close";
            StockTable.Header[ColVolume].Value = "Volume";

            // make some changes to default cell style
            StockTable.DefaultCellStyle.Alignment = ContentAlignment.MiddleRight;
            StockTable.DefaultCellStyle.Format    = "#,##0.00";

            // create private style for date column
            StockTable.Cell[ColDate].Style           = StockTable.CellStyle;
            StockTable.Cell[ColDate].Style.Alignment = ContentAlignment.MiddleLeft;
            StockTable.Cell[ColDate].Style.Format    = null;

            // create private styles for volumn column
            PdfTableStyle GoingUpStyle = StockTable.CellStyle;

            GoingUpStyle.BackgroundColor = Color.LightGreen;
            GoingUpStyle.Format          = "#,##0";
            PdfTableStyle GoingDownStyle = StockTable.CellStyle;

            GoingDownStyle.BackgroundColor = Color.LightPink;
            GoingDownStyle.Format          = "#,##0";

            // open stock daily price
            // takem from Yahoo Financial
            StreamReader Reader = new StreamReader("SP500.csv");

            // ignore header
            Reader.ReadLine();

            // read all daily prices
            for (;;)
            {
                String TextLine = Reader.ReadLine();
                if (TextLine == null)
                {
                    break;
                }

                String[] Fld = TextLine.Split(new Char[] { ',' });

                StockTable.Cell[ColDate].Value   = Fld[ColDate];
                StockTable.Cell[ColOpen].Value   = Double.Parse(Fld[ColOpen], NFI.PeriodDecSep);
                StockTable.Cell[ColHigh].Value   = Double.Parse(Fld[ColHigh], NFI.PeriodDecSep);
                StockTable.Cell[ColLow].Value    = Double.Parse(Fld[ColLow], NFI.PeriodDecSep);
                StockTable.Cell[ColClose].Value  = Double.Parse(Fld[ColClose], NFI.PeriodDecSep);
                StockTable.Cell[ColVolume].Value = Int32.Parse(Fld[ColVolume]);
                StockTable.Cell[ColVolume].Style = (Double)StockTable.Cell[ColClose].Value >= (Double)StockTable.Cell[ColOpen].Value ? GoingUpStyle : GoingDownStyle;
                StockTable.DrawRow();
            }

            StockTable.Close();

            // exit
            return;
        }
Пример #6
0
        private double Summary(double left, double top, double bottom, double right, double fontSize,
                               IEnumerable <DataServices> daneUslugas)
        {
            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 - 0.31, bottom, right, top)
            };
            var array = new[] { 3.5, 3, 3, 3.5 };

            table.SetColumnWidth(array);

            table.Borders.ClearAllBorders();
            table.Borders.SetAllBorders(frameWidth, frameWidth);


            var margin = new PdfRectangle(marginHor + 0.27, marginVer);

            table.DefaultHeaderStyle.Margin          = margin;
            table.DefaultHeaderStyle.BackgroundColor = Color.LightGray;
            table.DefaultHeaderStyle.Font            = _arialBold;
            table.DefaultHeaderStyle.Alignment       = ContentAlignment.TopCenter;

            var dataServiceses = daneUslugas.ToList();
            var firstService   = dataServiceses.FirstOrDefault();

            if (firstService != null)
            {
                table.Header[0].Value = ToCurrency(firstService.ValueNetto);
                table.Header[1].Value = firstService.VatRate;
                table.Header[2].Value = ToCurrency(firstService.ValueVat);
                table.Header[3].Value = ToCurrency(firstService.ValueBrutto);
            }

            table.DefaultCellStyle.Margin = margin;

            for (var i = 0; i < array.Length; i++)
            {
                table.Cell[i].Style = table.CellStyle;
                table.Cell[i].Style.MultiLineText = false;
                table.Cell[i].Style.Alignment     = ContentAlignment.MiddleCenter;
                table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;
            }

            var z = 0;

            foreach (var item in dataServiceses)
            {
                if (z == 0)
                {
                    z++;
                    continue;
                }

                table.Cell[0].Value = ToCurrency(item.ValueNetto);
                table.Cell[1].Value = item.VatRate;
                table.Cell[2].Value = ToCurrency(item.ValueVat);
                table.Cell[3].Value = ToCurrency(item.ValueBrutto);
                table.DrawRow();
            }

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

            table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
Пример #7
0
        private double TabelaDaneFaktura(double left, double top, double bottom, double right, double fontSize,
                                         IEnumerable <DataServices> dataServices)
        {
            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)
            };
            var array = new[] { 1, 9.5, 1.5, 2.5, 2.5, 3.5, 3, 3, 3.5 };

            table.SetColumnWidth(array);

            table.Borders.ClearAllBorders();
            table.Borders.SetAllBorders(frameWidth, frameWidth);


            var margin = new PdfRectangle(marginHor, marginVer);

            table.DefaultHeaderStyle.Margin          = margin;
            table.DefaultHeaderStyle.BackgroundColor = Color.LightGray;
            table.DefaultHeaderStyle.Font            = _arialBold;
            table.DefaultHeaderStyle.MultiLineText   = true;
            table.DefaultHeaderStyle.Alignment       = ContentAlignment.TopCenter;

            table.Header[0].Value = DictionaryMain.KolumnaLp;
            table.Header[1].Value = DictionaryMain.KolumnaTowar;
            table.Header[2].Value = DictionaryMain.KolumnaJm;
            table.Header[3].Value = DictionaryMain.KolumnaIlosc;
            table.Header[4].Value = DictionaryMain.KolumnaCenaNetto;
            table.Header[5].Value = DictionaryMain.KolumnaWartoscNetto;
            table.Header[6].Value = DictionaryMain.KolumnaStawkaVat;
            table.Header[7].Value = DictionaryMain.KolumnaKwotaVat;
            table.Header[8].Value = DictionaryMain.KolumnaWartoscBrutto;

            table.DefaultCellStyle.Margin = margin;

            for (var i = 0; i < array.Length; i++)
            {
                table.Cell[i].Style = table.CellStyle;
                table.Cell[i].Style.MultiLineText = false;
                table.Cell[i].Style.Alignment     = ContentAlignment.MiddleCenter;
                table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;
            }

            foreach (var item in dataServices)
            {
                table.Cell[0].Value = item.RecordId;
                table.Cell[1].Value = item.CaptionRecord;
                table.Cell[2].Value = item.KindAmount;
                table.Cell[3].Value = item.Amount;
                table.Cell[4].Value = ToCurrency(item.AmountNetto);

                table.Cell[5].Value = ToCurrency(item.ValueNetto);
                table.Cell[6].Value = item.VatRate;
                table.Cell[7].Value = ToCurrency(item.ValueVat);
                table.Cell[8].Value = ToCurrency(item.ValueBrutto);
                table.DrawRow();
            }

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

            table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
        ////////////////////////////////////////////////////////////////////
        // Draw example of order form
        ////////////////////////////////////////////////////////////////////

        private static void DrawBankInformation(CustomerInformation customer)
        {
            // Define constants to make the code readable
            const Double LEFT       = 6.3;
            const Double TOP        = 19.5;
            const Double BOTTOM     = 17.3;
            const Double RIGHT      = 6.3 + 15.39;
            const Double FONT_SIZE  = 10;
            const Double MARGIN_HOR = 0.04;
            const Double MARGIN_VER = 0.04;

            // preset content
            string[,] content = new string[, ] {
                { "BSB Number:  ", "980200" },
                { "Swift Code:  ", "BKCHAU2AXXX" },
                { "Bank Name:  ", "Bank of China (Australia) Ltd" }
            };


            // column widths
            Double colWidthTitle  = ArialNormal.TextWidth(FONT_SIZE, "Account Name:  ") + 2.0 * MARGIN_HOR;
            Double colWidthDetail = ArialNormal.TextWidth(FONT_SIZE, "A very very very long name example and may be longer") + 2.0 * MARGIN_HOR;

            // define table
            PdfTable Table = new PdfTable(Page, Contents, ArialNormal, FONT_SIZE);

            Table.TableArea = new PdfRectangle(LEFT, BOTTOM, RIGHT, TOP);
            Table.SetColumnWidth(new Double[] { colWidthTitle, colWidthDetail });

            // define borders
            Table.Borders.ClearAllBorders();

            // margin
            PdfRectangle Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER);

            // default header style
            Table.DefaultHeaderStyle.Margin          = Margin;
            Table.DefaultHeaderStyle.BackgroundColor = Color.White;
            Table.DefaultHeaderStyle.Alignment       = ContentAlignment.MiddleLeft;

            // table heading
            Table.Header[0].Value = "Account Name:  ";
            Table.Header[1].Value = customer.GetName().ToUpper();

            // account type style
            Table.DefaultCellStyle.Margin = Margin;

            // loop for all items
            for (int i = 0; i < content.GetLength(0); i++)
            {
                for (int j = 0; j < content.GetLength(1); j++)
                {
                    Table.Cell[j].Value = content[i, j];
                }
                Table.DrawRow();
            }
            Table.Close();

            // save graphics state
            Contents.SaveGraphicsState();

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Пример #9
0
        ////////////////////////////////////////////////////////////////////
        // Create charting examples PDF document
        ////////////////////////////////////////////////////////////////////

        public void CreateBookList()
        {
            // Add new page
            Page = new PdfPage(Document);

            // Add contents to page
            Contents = new PdfContents(Page);

            PdfFont TitleFont  = new PdfFont(Document, "Verdana", FontStyle.Bold);
            PdfFont AuthorFont = new PdfFont(Document, "Verdana", FontStyle.Italic);

            // create stock table
            PdfTable BookList = new PdfTable(Page, Contents, NormalFont, 9.0);

            // divide columns width in proportion to following values
            BookList.SetColumnWidth(1.0, 2.5, 1.2, 1.0, 0.5, 0.6, 1.2);

            // event handlers
            BookList.TableStartEvent += BookListTableStart;
            BookList.TableEndEvent   += BookListTableEnd;

            // set display header at the top of each additional page
            BookList.HeaderOnEachPage = true;

            // headers
            BookList.Header[0].Value = "Book Cover";
            BookList.Header[1].Value = "Book Title and Authors";
            BookList.Header[2].Value = "Date\nPublished";
            BookList.Header[3].Value = "Type";
            BookList.Header[4].Value = "In\nStock";
            BookList.Header[5].Value = "Price";
            BookList.Header[6].Value = "Weblink";

            // make some changes to default header style
            BookList.DefaultHeaderStyle.Alignment          = ContentAlignment.MiddleCenter;
            BookList.DefaultHeaderStyle.MultiLineText      = true;
            BookList.DefaultHeaderStyle.TextBoxTextJustify = TextBoxJustify.Center;

            // default cell style
            BookList.DefaultCellStyle.Alignment = ContentAlignment.MiddleCenter;

            // create private style for in stock column
            BookList.Cell[4].Style           = BookList.CellStyle;
            BookList.Cell[4].Style.Format    = "#,##0";
            BookList.Cell[4].Style.Alignment = ContentAlignment.MiddleRight;

            // create private style for price column
            BookList.Cell[5].Style           = BookList.CellStyle;
            BookList.Cell[5].Style.Format    = "#,##0.00";
            BookList.Cell[5].Style.Alignment = ContentAlignment.MiddleRight;

            // book list text file
            StreamReader Reader = new StreamReader("BookList.txt");

            // loop for records
            for (;;)
            {
                // read one line
                String TextLine = Reader.ReadLine();
                if (TextLine == null)
                {
                    break;
                }

                // split to fields (must be 8 fields)
                String[] Fld = TextLine.Split(new Char[] { '\t' });
                if (Fld.Length != 8)
                {
                    continue;
                }

                // book cover
                BookList.Cell[0].Value = new PdfImage(Document, Fld[6]);

                // note create text box set Value field
                TextBox Box = BookList.Cell[1].CreateTextBox();
                Box.AddText(TitleFont, 10.0, Color.DarkBlue, Fld[0]);
                Box.AddText(NormalFont, 8.0, Color.Black, ", Author(s): ");
                Box.AddText(AuthorFont, 9.0, Color.DarkRed, Fld[2]);

                // date, type in-stock and price
                BookList.Cell[2].Value = Fld[1];
                BookList.Cell[3].Value = Fld[3];
                BookList.Cell[4].Value = Int32.Parse(Fld[5]);
                BookList.Cell[5].Value = Double.Parse(Fld[4], NFI.PeriodDecSep);

                // QRCode and web link
                BookList.Cell[6].Value = new PdfQRCode(Document, Fld[7], ErrorCorrection.M);
//			BarcodeEAN13 Barcode1 = new BarcodeEAN13("1234567890128");
//			BookList.Cell[6].Value = Barcode1;
//			BookList.Cell[6].Style.BarcodeBarWidth = 0.01;
//			BookList.Cell[6].Style.BarcodeHeight = 0.5;
                BookList.Cell[6].WebLink = Fld[7];

                // draw it
                BookList.DrawRow();
            }

            // close book list
            BookList.Close();

            // exit
            return;
        }
Пример #10
0
        private double Summary(double LEFT, double TOP, double BOTTOM, double RIGHT, double FONT_SIZE,
                               IEnumerable <DaneUsluga> daneUslugas)
        {
            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 - 0.31, BOTTOM, RIGHT, TOP)
            };
            var array = new[] { 3.5, 3, 3, 3.5 };

            Table.SetColumnWidth(array);

            Table.Borders.ClearAllBorders();
            Table.Borders.SetAllBorders(FRAME_WIDTH, FRAME_WIDTH);


            var Margin = new PdfRectangle(MARGIN_HOR + 0.27, MARGIN_VER);

            Table.DefaultHeaderStyle.Margin          = Margin;
            Table.DefaultHeaderStyle.BackgroundColor = Color.LightGray;
            Table.DefaultHeaderStyle.Font            = _arialBold;
            Table.DefaultHeaderStyle.Alignment       = ContentAlignment.TopCenter;

            var enumerable = daneUslugas.ToList();

            Table.Header[0].Value = enumerable.First().WartoscNetto.ToCurrency();
            Table.Header[1].Value = enumerable.First().StawkaVat;
            Table.Header[2].Value = enumerable.First().KwotaVat.ToCurrency();
            Table.Header[3].Value = enumerable.First().WartoscBrutto.ToCurrency();

            Table.DefaultCellStyle.Margin = Margin;

            for (var i = 0; i < array.Length; i++)
            {
                Table.Cell[i].Style = Table.CellStyle;
                Table.Cell[i].Style.MultiLineText = false;
                Table.Cell[i].Style.Alignment     = ContentAlignment.MiddleCenter;
                Table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;
            }

            var z = 0;

            foreach (var item in enumerable)
            {
                if (z == 0)
                {
                    z++;
                    continue;
                }

                Table.Cell[0].Value = item.WartoscNetto.ToCurrency();
                Table.Cell[1].Value = item.StawkaVat;
                Table.Cell[2].Value = item.KwotaVat.ToCurrency();
                Table.Cell[3].Value = item.WartoscBrutto.ToCurrency();
                Table.DrawRow();
            }

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

            Table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
Пример #11
0
        private double TabelaDaneFaktura(double LEFT, double TOP, double BOTTOM, double RIGHT, double FONT_SIZE,
                                         IEnumerable <DaneUsluga> daneUslugas)
        {
            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)
            };
            var array = new[] { 1, 9.5, 1.5, 2.5, 2.5, 3.5, 3, 3, 3.5 };

            Table.SetColumnWidth(array);

            Table.Borders.ClearAllBorders();
            Table.Borders.SetAllBorders(FRAME_WIDTH, FRAME_WIDTH);


            var Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER);

            Table.DefaultHeaderStyle.Margin          = Margin;
            Table.DefaultHeaderStyle.BackgroundColor = Color.LightGray;
            Table.DefaultHeaderStyle.Font            = _arialBold;
            Table.DefaultHeaderStyle.MultiLineText   = true;
            Table.DefaultHeaderStyle.Alignment       = ContentAlignment.TopCenter;

            Table.Header[0].Value = DictionaryMain.KolumnaLp;
            Table.Header[1].Value = DictionaryMain.KolumnaTowar;
            Table.Header[2].Value = DictionaryMain.KolumnaJm;
            Table.Header[3].Value = DictionaryMain.KolumnaIlosc;
            Table.Header[4].Value = DictionaryMain.KolumnaCenaNetto;
            Table.Header[5].Value = DictionaryMain.KolumnaWartoscNetto;
            Table.Header[6].Value = DictionaryMain.KolumnaStawkaVat;
            Table.Header[7].Value = DictionaryMain.KolumnaKwotaVat;
            Table.Header[8].Value = DictionaryMain.KolumnaWartoscBrutto;

            Table.DefaultCellStyle.Margin = Margin;

            for (var i = 0; i < array.Length; i++)
            {
                Table.Cell[i].Style = Table.CellStyle;
                Table.Cell[i].Style.MultiLineText = false;
                Table.Cell[i].Style.Alignment     = ContentAlignment.MiddleCenter;
                Table.CellStyle.TextDrawStyle     = DrawStyle.Superscript;
            }

            foreach (var item in daneUslugas)
            {
                Table.Cell[0].Value = item.LpTabela;
                Table.Cell[1].Value = item.OpisTabela;
                Table.Cell[2].Value = item.Rodzajilosc;
                Table.Cell[3].Value = item.Ilosc;
                Table.Cell[4].Value = item.CenaNetto.ToCurrency();

                Table.Cell[5].Value = item.WartoscNetto.ToCurrency();
                Table.Cell[6].Value = item.StawkaVat;
                Table.Cell[7].Value = item.KwotaVat.ToCurrency();
                Table.Cell[8].Value = item.WartoscBrutto.ToCurrency();
                Table.DrawRow();
            }

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

            Table.Close();

            PdfContents.SaveGraphicsState();
            PdfContents.RestoreGraphicsState();
            return(positionLast);
        }
        private static void DrawGroupContact()
        {
            // Define constants
            const Double LEFT       = 1.3;
            const Double TOP        = 4.5;
            const Double BOTTOM     = 1;
            const Double RIGHT      = 1.3 + 18.39;
            const Double FONT_SIZE  = 8;
            const Double MARGIN_HOR = 0.04;
            const Double MARGIN_VER = 0.04;

            BranchInfo branch = new BranchInfo(Branch.Banking);

            string[,] branchContact = branch.GetFullDataSet();
            int numOfBranches = branchContact.GetLength(0);
            int numOfColumns  = (numOfBranches + 1) / 2;

            // column widths
            Double colWidth = 18.39 / numOfColumns;


            // define table
            PdfTable Table = new PdfTable(Page, Contents, ArialNormal, FONT_SIZE);

            Table.TableArea = new PdfRectangle(LEFT, BOTTOM, RIGHT, TOP);
            Table.SetColumnWidth(Enumerable.Repeat(colWidth, numOfColumns).ToArray());

            // define borders
            Table.Borders.ClearAllBorders();

            // margin
            PdfRectangle Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER);

            // account type style
            Table.DefaultCellStyle.Margin = Margin;

            for (int i = 0; i < 2 * 4; i++)
            {
                int index = i % 4;
                int startBranchIndex;
                if (i < 4)
                {
                    startBranchIndex = 0;
                }
                else
                {
                    startBranchIndex = numOfColumns;
                }
                int cell = 0;
                for (int j = startBranchIndex; j < startBranchIndex + numOfColumns; j++)
                {
                    Table.Cell[cell].Value = branchContact[j, index];
                    cell++;
                }
                Table.DrawRow();
                if (i == 3)
                {
                    Table.DrawRow();    //Draw 2 extra rows as spacer
                    Table.DrawRow();
                }
            }

            Table.Close();

            // save graphics state
            Contents.SaveGraphicsState();

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
        private static void DrawAccountInformationForm(List <Account> accountList)
        {
            // Define constants to make the code readable
            const Double LEFT        = 1.3;
            const Double TOP         = 16.5;
            const Double BOTTOM      = 10.3;
            const Double RIGHT       = 1.3 + 18.39;
            const Double FONT_SIZE   = 10;
            const Double MARGIN_HOR  = 0.04;
            const Double MARGIN_VER  = 0.04;
            const Double FRAME_WIDTH = 0.015;

            // column widths
            Double colWidthType        = ArialNormal.TextWidth(FONT_SIZE, "Overseas Student Account") + 2.0 * MARGIN_HOR;
            Double colWidthCcy         = ArialNormal.TextWidth(FONT_SIZE, "AUD") + 2.0 * MARGIN_HOR;
            Double colWidthLongNumber  = ArialNormal.TextWidth(FONT_SIZE, "  International Transfer  ") + 2.0 * MARGIN_HOR;
            Double colWidthShortNumber = ArialNormal.TextWidth(FONT_SIZE, "  Domestic Transfer  ") + 2.0 * MARGIN_HOR;


            // define table
            PdfTable Table = new PdfTable(Page, Contents, ArialNormal, FONT_SIZE);

            Table.TableArea = new PdfRectangle(LEFT, BOTTOM, RIGHT, TOP);
            Table.SetColumnWidth(new Double[] { colWidthType, colWidthCcy, colWidthLongNumber, colWidthShortNumber });

            // define borders
            Table.Borders.ClearAllBorders();
            Table.Borders.SetCellHorBorder(FRAME_WIDTH);
            Table.Borders.SetHeaderHorBorder(FRAME_WIDTH);
            Table.Borders.SetTopBorder(FRAME_WIDTH);
            Table.Borders.SetBottomBorder(FRAME_WIDTH);


            // margin
            PdfRectangle Margin = new PdfRectangle(MARGIN_HOR, MARGIN_VER);

            // default header style
            Table.DefaultHeaderStyle.Margin          = Margin;
            Table.DefaultHeaderStyle.BackgroundColor = Color.White;
            Table.DefaultHeaderStyle.Alignment       = ContentAlignment.MiddleCenter;
            Table.DefaultHeaderStyle.Font            = ArialBold;

            // table heading
            Table.Header[0].Value = "Account Type";
            Table.Header[1].Value = "CCY";
            Table.Header[2].Value = "International Transfer";
            Table.Header[3].Value = "Domestic Transfer";

            // account type style
            Table.DefaultCellStyle.Margin = Margin;

            // description column style
            for (int i = 0; i < 4; i++)
            {
                Table.Cell[i].Style = Table.CellStyle;
                Table.Cell[i].Style.MultiLineText = false;
                Table.Cell[i].Style.Alignment     = ContentAlignment.MiddleCenter;
            }

            // loop for all items
            foreach (Account account in accountList)
            {
                List <string> accountInfo = account.GetAccountInfo();
                for (int i = 0; i < 4; i++)
                {
                    Table.Cell[i].Value = accountInfo[i];
                }
                Table.DrawRow();
            }


            Table.Close();

            // save graphics state
            Contents.SaveGraphicsState();

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Пример #14
0
        ////////////////////////////////////////////////////////////////////
        // Draw example of order form
        ////////////////////////////////////////////////////////////////////

        private void DrawBookOrderForm()
        {
            // Define constants to make the code readable
            const Double Left       = 4.35;
            const Double Top        = 4.65;
            const Double Bottom     = 1.1;
            const Double Right      = 7.4;
            const Double FontSize   = 9.0;
            const Double MarginHor  = 0.04;
            const Double MarginVer  = 0.04;
            const Double FrameWidth = 0.015;
            const Double GridWidth  = 0.01;

            // column widths
            Double ColWidthPrice = ArialNormal.TextWidth(FontSize, "9999.99") + 2.0 * MarginHor;
            Double ColWidthQty   = ArialNormal.TextWidth(FontSize, "Qty") + 2.0 * MarginHor;
            Double ColWidthDesc  = Right - Left - FrameWidth - 3 * GridWidth - 2 * ColWidthPrice - ColWidthQty;

            // define table
            PdfTable Table = new PdfTable(Page, Contents, ArialNormal, FontSize);

            Table.TableArea = new PdfRectangle(Left, Bottom, Right, Top);
            Table.SetColumnWidth(new Double[] { ColWidthDesc, ColWidthPrice, ColWidthQty, ColWidthPrice });

            // define borders
            Table.Borders.SetAllBorders(FrameWidth, GridWidth);

            // margin
            PdfRectangle Margin = new PdfRectangle(MarginHor, MarginVer);

            // default header style
            Table.DefaultHeaderStyle.Margin          = Margin;
            Table.DefaultHeaderStyle.BackgroundColor = Color.FromArgb(255, 196, 255);
            Table.DefaultHeaderStyle.Alignment       = ContentAlignment.MiddleRight;

            // private header style for description
            Table.Header[0].Style           = Table.HeaderStyle;
            Table.Header[0].Style.Alignment = ContentAlignment.MiddleLeft;

            // table heading
            Table.Header[0].Value = "Description";
            Table.Header[1].Value = "Price";
            Table.Header[2].Value = "Qty";
            Table.Header[3].Value = "Total";

            // default style
            Table.DefaultCellStyle.Margin = Margin;

            // description column style
            Table.Cell[0].Style = Table.CellStyle;
            Table.Cell[0].Style.MultiLineText = true;

            // qty column style
            Table.Cell[2].Style           = Table.CellStyle;
            Table.Cell[2].Style.Alignment = ContentAlignment.BottomRight;

            Table.DefaultCellStyle.Format    = "#,##0.00";
            Table.DefaultCellStyle.Alignment = ContentAlignment.BottomRight;

            Contents.DrawText(ArialBold, FontSize, 0.5 * (Left + Right), Top + MarginVer + Table.DefaultCellStyle.FontDescent,
                              TextJustify.Center, DrawStyle.Normal, Color.Purple, "Example of PdfTable support");

            // reset order total
            Double Total = 0;

            // loop for all items in the order
            // Order class is a atabase simulation for this example
            foreach (Order Book in Order.OrderList)
            {
                Table.Cell[0].Value = Book.Title + ". By: " + Book.Authors;
                Table.Cell[1].Value = Book.Price;
                Table.Cell[2].Value = Book.Qty;
                Table.Cell[3].Value = Book.Total;
                Table.DrawRow();

                // accumulate total
                Total += Book.Total;
            }
            Table.Close();

            // save graphics state
            Contents.SaveGraphicsState();

            // form line width 0.01"
            Contents.SetLineWidth(FrameWidth);
            Contents.SetLineCap(PdfLineCap.Square);

            // draw total before tax
            Double[] ColumnPosition = Table.ColumnPosition;
            Double   TotalDesc      = ColumnPosition[3] - MarginHor;
            Double   TotalValue     = ColumnPosition[4] - MarginHor;
            Double   PosY           = Table.RowTopPosition - 2.0 * MarginVer - Table.DefaultCellStyle.FontAscent;

            Contents.DrawText(ArialNormal, FontSize, TotalDesc, PosY, TextJustify.Right, "Total before tax");
            Contents.DrawText(ArialNormal, FontSize, TotalValue, PosY, TextJustify.Right, Total.ToString("#.00"));

            // draw tax (Ontario Canada HST)
            PosY -= Table.DefaultCellStyle.FontLineSpacing;
            Contents.DrawText(ArialNormal, FontSize, TotalDesc, PosY, TextJustify.Right, "Tax (13%)");
            Double Tax = Math.Round(0.13 * Total, 2, MidpointRounding.AwayFromZero);

            Contents.DrawText(ArialNormal, FontSize, TotalValue, PosY, TextJustify.Right, Tax.ToString("#.00"));

            // draw total line
            PosY -= Table.DefaultCellStyle.FontDescent + 0.5 * MarginVer;
            Contents.DrawLine(ColumnPosition[3], PosY, ColumnPosition[4], PosY);

            // draw final total
            PosY -= Table.DefaultCellStyle.FontAscent + 0.5 * MarginVer;
            Contents.DrawText(ArialNormal, FontSize, TotalDesc, PosY, TextJustify.Right, "Total payable");
            Total += Tax;
            Contents.DrawText(ArialNormal, FontSize, TotalValue, PosY, TextJustify.Right, Total.ToString("#.00"));

            PosY -= Table.DefaultCellStyle.FontDescent + MarginVer;
            Contents.DrawLine(ColumnPosition[0], Table.RowTopPosition, ColumnPosition[0], PosY);
            Contents.DrawLine(ColumnPosition[0], PosY, ColumnPosition[4], PosY);
            Contents.DrawLine(ColumnPosition[4], Table.RowTopPosition, ColumnPosition[4], PosY);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
Пример #15
0
        private double CreateTable(List <TableData> dt, double left, double right, double fontSize, double top,
                                   double bottom, bool withHeader, ContentAlignment ca)
        {
            const double marginHor = 0.04;
            const double marginVer = 0.04;

            var firstElement   = dt.FirstOrDefault();
            var colWidthTitle  = ArialNormal.TextWidth(fontSize, firstElement.LeftSide) + 2.0 * marginHor;
            var colWidthDetail = ArialNormal.TextWidth(fontSize, firstElement.RightSide) + 2.0 * marginHor;

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

            table.SetColumnWidth(array);

            table.Borders.ClearAllBorders();

            var margin = new PdfRectangle(marginHor, marginVer);

            table.DefaultHeaderStyle.Margin          = margin;
            table.DefaultHeaderStyle.BackgroundColor = Color.White;
            table.DefaultHeaderStyle.Alignment       = ca;


            table.DefaultCellStyle.Margin = margin;
            if (withHeader)
            {
                table.Header[0].Style.FontSize = 12;
                table.Header[0].Style.Font     = _arialBold;
                table.Header[0].Value          = firstElement.LeftSide;
                table.Header[1].Value          = firstElement.RightSide;
                table.Header[0].Style.FontSize = 12;
                table.Header[0].Style.Font     = _arialBold;
                table.Header[1].Style.FontSize = 12;
                table.Header[1].Style.Font     = _arialBold;
            }

            var i = 0;

            foreach (var item in dt)
            {
                if (withHeader && i == 0)
                {
                    i++;
                    continue;
                }

                table.Cell[0].Value = item.LeftSide;
                table.Cell[1].Value = item.RightSide;
                table.DrawRow();
            }

            var lastRowPosition = table.RowPosition[table.RowNumber];

            table.Close();

            PdfContents.SaveGraphicsState();

            PdfContents.RestoreGraphicsState();
            return(lastRowPosition);
        }
Пример #16
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();
        }
Пример #17
0
        public FileInfo CreateOfferDocument(Offer offer, bool asOrder = false, bool withPreview = true)
        {
            ResetVars();
            myOffer = offer;
            PdfDocument  doc;
            PdfPage      page;
            PdfContents  content;
            PdfImage     img;
            double       lineSpacing;
            double       descent;
            const double fontSize = 10.0;
            bool         isOffer  = (this.myOffer.Bestellkennzeichen | asOrder);

            string fullName = Path.Combine(CatalistRegistry.Application.OfferFilePath, offer.OfferId + ".pdf");

            doc       = new PdfDocument(PaperType.A4, false, UnitOfMeasure.mm, fullName);
            doc.Debug = false;
            page      = new PdfPage(doc);
            content   = new PdfContents(page);
            content.SetLineWidth(0.03);

            fontDefault    = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Regular, true);
            myFontBold     = new PdfFont(doc, "Calibri", System.Drawing.FontStyle.Bold, true);
            fontFooter     = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Regular, true);
            fontFooterBold = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true);
            fontPriceTotal = new PdfFont(doc, "Calibri Light", System.Drawing.FontStyle.Bold, true);

            lineSpacing = fontDefault.LineSpacing(fontSize);
            descent     = fontDefault.Descent(fontSize);

            // Header
            string imagePath = Path.Combine(CatalistRegistry.Application.PicturePath, "briefkopf.png");

            img = new PdfImage(doc, imagePath);
            content.DrawImage(img, 5, pageHeight - 27.9 - 5, 199.6, 27.4);
            content.DrawLine(xLeftMargin - 5, pageHeight - 27.9 - 5 - 2, xRightMargin + 5, pageHeight - 27.9 - 5 - 2);

            string absender = @"Cut & Print Media GmbH & Co. KG · Osterheide 9 · 49124 Georgsmarienhütte";

            content.DrawText(fontDefault, fontSize - 4, 18, pageHeight - 49.5, absender);
            content.DrawLine(18, pageHeight - 50.5, 84.5, pageHeight - 50.5, 0.1);
            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 55, offer.Customer.CompanyName1);
            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 65, offer.Customer.Street);
            string zipCity = string.Format("{0} {1}", offer.Customer.ZipCode, offer.Customer.City);

            content.DrawText(fontDefault, fontSize + 2, 18, pageHeight - 71, zipCity);

            string vorgang = isOffer ? "Bestellung" : "Angebot";

            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 55, "Kunden-Nr.:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 55, offer.CustomerId.Substring(0, 5));
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 60, vorgang + " Nr.:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 60, offer.OfferId);
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 65, "Datum:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 65, offer.ChangeDate.ToShortDateString());
            content.DrawText(fontDefault, fontSize + 2, xVLine3 + 5, pageHeight - 70, "Bearbeitet von:");
            content.DrawText(fontDefault, fontSize + 2, xVLine5 - 13, pageHeight - 70, offer.ChangeUser);

            content.DrawText(myFontBold, fontSize + 2, 10, pageHeight - 96.5, vorgang + " " + offer.OfferId);

            var table = new PdfTable(page, content, fontDefault, 9);

            table.TableStartEvent += tab_TableStartEvent;
            table.TableEndEvent   += tab_TableEndEvent;
            table.TableArea        = new PdfRectangle(10D, 35D, 200D, pageHeight - 40);
            table.RowTopPosition   = pageHeight - 100D;           // 10cm vom oberen Rand
            table.SetColumnWidth(9D, 34D, 86D, 13D, 19D, 19D);
            table.HeaderOnEachPage = true;

            table.Header[colPos].Style           = table.HeaderStyle;
            table.Header[colPos].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colPos].Value           = "Pos.";

            table.Header[colArtNr].Value  = "Artikel-Nr.";
            table.Header[colArtBez].Value = "Artikelbezeichnung";

            table.Header[colMenge].Style           = table.HeaderStyle;
            table.Header[colMenge].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colMenge].Value           = "Menge";

            table.Header[colPreis].Style           = table.HeaderStyle;
            table.Header[colPreis].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colPreis].Value           = "Einzelpreis";

            table.Header[colGesamt].Style           = table.HeaderStyle;
            table.Header[colGesamt].Style.Alignment = System.Drawing.ContentAlignment.MiddleRight;
            table.Header[colGesamt].Value           = "Gesamtpreis";

            table.DefaultHeaderStyle.Font          = myFontBold;
            table.DefaultHeaderStyle.Alignment     = System.Drawing.ContentAlignment.TopLeft;
            table.DefaultHeaderStyle.MultiLineText = false;

            table.DefaultCellStyle.Font      = fontDefault;
            table.DefaultCellStyle.FontSize  = 9;
            table.DefaultCellStyle.Alignment = System.Drawing.ContentAlignment.TopLeft;

            table.Cell[colPos].Style           = table.CellStyle;
            table.Cell[colPos].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colArtNr].Style = table.CellStyle;
            table.Cell[colArtNr].Style.TextBoxTextJustify = TextBoxJustify.Left;

            table.Cell[colArtBez].Style = table.CellStyle;
            table.Cell[colArtBez].Style.TextBoxTextJustify = TextBoxJustify.Left;

            table.Cell[colMenge].Style           = table.CellStyle;
            table.Cell[colMenge].Style.Format    = "#,##0";
            table.Cell[colMenge].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colPreis].Style           = table.CellStyle;
            table.Cell[colPreis].Style.Format    = "#,##0.00";
            table.Cell[colPreis].Style.Alignment = System.Drawing.ContentAlignment.TopRight;

            table.Cell[colGesamt].Style = table.CellStyle;
            table.Cell[colGesamt].Style.ForegroundColor = System.Drawing.Color.DarkRed;
            table.Cell[colGesamt].Style.Format          = "#,##0.00";
            table.Cell[colGesamt].Style.Alignment       = System.Drawing.ContentAlignment.TopRight;

            int dCount = offer.OfferDetails.Count;

            for (int i = 0; i < dCount; i++)
            {
                lastRow |= i == dCount - 1;

                table.Cell[colPos].Value   = offer.OfferDetails[i].Position;
                table.Cell[colArtNr].Value = offer.OfferDetails[i].Artikelnummer;
                TextBox txtBezeichnung = table.Cell[colArtBez].CreateTextBox();
                txtBezeichnung.AddText(myFontBold, 9, offer.OfferDetails[i].Artikelname);
                if (!isOffer)
                {
                    txtBezeichnung.AddText(fontDefault, 9, string.Format("\n\n{0}", offer.OfferDetails[i].Artikeltext.Replace("\t", " ")));
                }
                table.Cell[colMenge].Value = string.Format("{0:#,##0} {1}", offer.OfferDetails[i].Menge, offer.OfferDetails[i].Einheit);

                if (!isOffer)
                {
                    table.Cell[colPreis].Value  = offer.OfferDetails[i].Kundenpreis;
                    table.Cell[colGesamt].Value = offer.OfferDetails[i].Zeilensumme;
                    zwischenSumme += offer.OfferDetails[i].Zeilensumme;
                }
                else
                {
                    table.Cell[colPreis].Value  = "-";
                    table.Cell[colGesamt].Value = "-";
                }
                table.DrawRow(offer.OfferDetails[i].NeueSeite);
            }
            table.Close();

            try
            {
                doc.CreateFile();
                if (File.Exists(fullName) && withPreview)
                {
                    // Datei in das lokale TEMP Verzeichnis kopieren
                    var    temp            = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                    string prefix          = asOrder ? "B" : "A";
                    var    tempFilename    = string.Format("{0}{1}.pdf", prefix, DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss"));
                    var    tempFileAndPath = Path.Combine(temp, tempFilename);
                    File.Copy(fullName, tempFileAndPath);
                    var proc = new Process();
                    proc.StartInfo = new ProcessStartInfo(tempFileAndPath);
                    proc.Start();
                }

                return(new FileInfo(fullName));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }