예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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");
        }
        public void BankUdbetalingsUdskrifter(dbData3060 p_dbData3060, int lobnr)
        {
            var antal = (from c in p_dbData3060.tbltilpbs
                         where c.id == lobnr
                         select c).Count();

            if (antal == 0)
            {
                throw new Exception("101 - Der er ingen PBS forsendelse for id: " + lobnr);
            }

            var qrykrd = from k in p_dbData3060.tblMedlem
                         join h in p_dbData3060.tbloverforsel on k.Nr equals h.Nr
                         where h.tilpbsid == lobnr
                         select new
            {
                k.Nr,
                k.Navn,
                h.betalingsdato,
                h.advistekst,
                h.advisbelob,
                h.bankregnr,
                h.bankkontonr,
                h.SFaknr,
            };


            // Start loop over betalinger i tbloverforsel
            int testantal = qrykrd.Count();

            foreach (var krd in qrykrd)
            {
                //Create a pdf document.
                PdfDocument doc = new PdfDocument();

                doc.DocumentInformation.Author       = "Løbeklubben Puls 3060";
                doc.DocumentInformation.Title        = String.Format("Bankudbetaling {0}", "");
                doc.DocumentInformation.Creator      = "Medlem3060";
                doc.DocumentInformation.Subject      = String.Format("Faktura {0}", ((int)krd.SFaknr).ToString());
                doc.DocumentInformation.CreationDate = DateTime.Now;

                //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(2f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
                margin.Right  = margin.Left;

                // Create one page
                PdfPageBase page  = doc.Pages.Add(PdfPageSize.A5, margin);
                float       width = page.Canvas.ClientSize.Width;

                float y = 5;

                //title
                PdfBrush        brush1  = PdfBrushes.Black;
                PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
                PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
                string          s       = String.Format("Bankudbetaling {0}", ((int)krd.SFaknr).ToString());
                page.Canvas.DrawString(s, font1, brush1, 1, y, format1);

                y = y + 35;

                String[][] dataSource = new String[7][];
                int        i          = 0;
                String[]   datarow    = new String[2];
                datarow[0]      = "Tekst på eget kontoudtog";
                datarow[1]      = krd.advistekst;
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Navn/kendenavn";
                datarow[1]      = krd.Navn;
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Regnr";
                datarow[1]      = krd.bankregnr;
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Konto";
                datarow[1]      = krd.bankkontonr;
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Tekst til beløbsmodtager";
                datarow[1]      = krd.advistekst;
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Beløb";
                datarow[1]      = ((decimal)(krd.advisbelob)).ToString("#0.00;-#0.00");
                dataSource[i++] = datarow;

                datarow         = new String[2];
                datarow[0]      = "Betalingsdato";
                datarow[1]      = ((DateTime)krd.betalingsdato).ToShortDateString();
                dataSource[i++] = datarow;

                PdfTable table = new PdfTable();

                table.Style.CellPadding              = 5; //2;
                table.Style.HeaderSource             = PdfHeaderSource.Rows;
                table.Style.HeaderRowCount           = 0;
                table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
                table.Style.HeaderStyle.Font         = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
                table.Style.ShowHeader   = true;
                table.Style.RepeatHeader = true;
                table.DataSource         = dataSource;

                table.Columns[0].Width        = 100; // width * 0.30f * width;
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                table.Columns[1].Width        = 100; // width * 0.10f * width;
                table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);

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

                //Save pdf file.
                string BilagPath = (from r in Program.karMedlemPrivat where r.key == "BankudbetalingPath" select r.value).First();
                string BilagNavn = String.Format(@"Faktura {0}.pdf", ((int)krd.SFaknr).ToString());
                string filename  = Path.Combine(BilagPath, BilagNavn);

                doc.SaveToFile(filename);
                doc.Close();
            }
        }
예제 #5
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);
        }
예제 #6
0
        public CreatePdfTable()
        {
            // 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;

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

            // Title
            PdfBrush        brush1       = PdfBrushes.Black;
            String          fontFileName = "C:\\Fonts\\bpg_nino_mtavruli_normal.ttf";
            PdfTrueTypeFont fontTrue     = new PdfTrueTypeFont(fontFileName, 14f);
            PdfStringFormat format1      = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("დაკავებულობა", fontTrue, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + fontTrue.MeasureString("Country List", format1).Height;
            y = y + 5;

            // PDF table's data Source

            String[] data =
            {
                "დაკავებულობა;აღწერილობა;ფართი მ;დაკავებულობის დატვირთვის ფაქტორი;დ.დ.",
                "SV-4;Test;57;27.5;4",
            };

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

            // Creating Table, Setting formats

            PdfTable table = new PdfTable();

            table.Style.CellPadding       = 2;
            table.Style.HeaderSource      = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount    = 1;
            table.Style.ShowHeader        = true;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(fontFileName, 10f);
            table.Style.HeaderStyle.Font  = new PdfTrueTypeFont(fontFileName, 6f);
            table.DataSource = dataSource;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(fontFileName, 10f);
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            y = y + result.Bounds.Height + 5;
            PdfBrush        brush2    = PdfBrushes.Gray;
            PdfTrueTypeFont fontTrue3 = new PdfTrueTypeFont(fontFileName, 8f);

            page.Canvas.DrawString(String.Format("სია შეიცავს {0} ობიექტს.", data.Length - 1), fontTrue3, brush2, 5, y);

            // Save and preview

            doc.SaveToFile("TestTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("TestTable.pdf");
        }
예제 #7
0
        private void GenerateReport_Click(object sender, RoutedEventArgs e)
        {
            if (ReportType.SelectedIndex == 0)
            {
                string[] dt    = pmsutil.GetServerDateTime().Split(null);
                DateTime cDate = Convert.ToDateTime(dt[0]);
                DateTime cTime = DateTime.Parse(dt[1] + " " + dt[2]);

                PdfDocument pdfDoc = new PdfDocument();

                PdfPageBase page   = pdfDoc.Pages.Add();
                var         stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("PMS.Assets.st_raphael_logo_dark.png");
                PdfImage    logo   = PdfImage.FromStream(stream);
                float       _width = 200;
                float       height = 80;
                float       x      = (page.Canvas.ClientSize.Width - _width) / 2;
                page.Canvas.DrawImage(logo, 0, -25, _width, height);

                page.Canvas.DrawString("Peñaranda St, Legazpi Port District",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       245, 0);

                page.Canvas.DrawString("Legazpi City, Albay",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       280, 20);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 49), new PointF(530, 49));

                page.Canvas.DrawString("PMS Scheduling Module Report",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       350, 52);

                page.Canvas.DrawString("Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt"),
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 52);

                page.Canvas.DrawString("Type: " + ReportType.Text,
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       380, 90);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 70), new PointF(530, 70));

                page.Canvas.DrawString(cDate.ToString("MMMM dd, yyyy").ToUpper() + " (" + cDate.ToString("dddd").ToUpper() + ")",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 90);

                PdfTable table = new PdfTable();
                table.Style.CellPadding       = 2;
                table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.AlternateStyle      = new PdfCellStyle();
                table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.HeaderSource             = PdfHeaderSource.ColumnCaptions;
                table.Style.HeaderStyle.Font         = new PdfFont(PdfFontFamily.TimesRoman, 13f);
                table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

                table.Style.ShowHeader = true;

                table.DataSourceType = PdfTableDataSourceType.TableDirect;
                table.DataSource     = GenerateList();
                //Set the width of column
                float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);
                table.Columns[0].Width        = width * 0.24f * width;
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[1].Width        = width * 0.21f * width;
                table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[2].Width        = width * 0.24f * width;
                table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[3].Width        = width * 0.24f * width;
                table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Draw(page, new PointF(10, 120));

                string fname = "Scheduling_Report-" + ReportType.Text + "-" + DateTime.Now.ToString("MMM_dd_yyyy") + ".pdf";
                //save
                pdfDoc.SaveToFile(@"..\..\" + fname);
                //launch the pdf document
                System.Diagnostics.Process.Start(@"..\..\" + fname);
            }
            else if (ReportType.SelectedIndex == 1)
            {
                string[] dt    = pmsutil.GetServerDateTime().Split(null);
                DateTime cDate = Convert.ToDateTime(dt[0]);
                DateTime cTime = DateTime.Parse(dt[1] + " " + dt[2]);

                PdfDocument pdfDoc = new PdfDocument();

                PdfPageBase page   = pdfDoc.Pages.Add();
                var         stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("PMS.Assets.st_raphael_logo_dark.png");
                PdfImage    logo   = PdfImage.FromStream(stream);
                float       _width = 200;
                float       height = 80;
                float       x      = (page.Canvas.ClientSize.Width - _width) / 2;
                page.Canvas.DrawImage(logo, 0, -25, _width, height);

                page.Canvas.DrawString("Peñaranda St, Legazpi Port District",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       245, 0);

                page.Canvas.DrawString("Legazpi City, Albay",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       280, 20);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 49), new PointF(530, 49));

                page.Canvas.DrawString("PMS Scheduling Module Report",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       350, 52);

                page.Canvas.DrawString("Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt"),
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 52);

                page.Canvas.DrawString("Type: " + ReportType.Text,
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       380, 90);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 70), new PointF(530, 70));

                page.Canvas.DrawString(cDate.ToString("MMMM dd, yyyy").ToUpper() + " (" + cDate.ToString("dddd").ToUpper() + ")",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 90);

                PdfTable table = new PdfTable();
                table.Style.CellPadding       = 2;
                table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.AlternateStyle      = new PdfCellStyle();
                table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.HeaderSource             = PdfHeaderSource.ColumnCaptions;
                table.Style.HeaderStyle.Font         = new PdfFont(PdfFontFamily.TimesRoman, 13f);
                table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

                table.Style.ShowHeader = true;

                table.DataSourceType = PdfTableDataSourceType.TableDirect;
                table.DataSource     = GenerateList();
                //Set the width of column
                float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);
                table.Columns[0].Width        = width * 0.24f * width;
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[1].Width        = width * 0.21f * width;
                table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[2].Width        = width * 0.24f * width;
                table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[3].Width        = width * 0.24f * width;
                table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Draw(page, new PointF(10, 120));

                string fname = "Scheduling_Report-" + ReportType.Text + "-" + DateTime.Now.ToString("MMM_dd_yyyy") + ".pdf";
                //save
                pdfDoc.SaveToFile(@"..\..\" + fname);
                //launch the pdf document
                System.Diagnostics.Process.Start(@"..\..\" + fname);
            }
            else
            {
                string[] dt    = pmsutil.GetServerDateTime().Split(null);
                DateTime cDate = Convert.ToDateTime(dt[0]);
                DateTime cTime = DateTime.Parse(dt[1] + " " + dt[2]);

                PdfDocument pdfDoc = new PdfDocument();

                PdfPageBase page   = pdfDoc.Pages.Add();
                var         stream = this.GetType().GetTypeInfo().Assembly.GetManifestResourceStream("PMS.Assets.st_raphael_logo_dark.png");
                PdfImage    logo   = PdfImage.FromStream(stream);
                float       _width = 200;
                float       height = 80;
                float       x      = (page.Canvas.ClientSize.Width - _width) / 2;
                page.Canvas.DrawImage(logo, 0, -25, _width, height);

                page.Canvas.DrawString("Peñaranda St, Legazpi Port District",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       245, 0);

                page.Canvas.DrawString("Legazpi City, Albay",
                                       new PdfFont(PdfFontFamily.TimesRoman, 13f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       280, 20);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 49), new PointF(530, 49));

                page.Canvas.DrawString("PMS Scheduling Module Report",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       350, 52);

                page.Canvas.DrawString("Generated on: " + DateTime.Now.ToString("MMMM dd, yyyy hh:mm tt"),
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 52);

                page.Canvas.DrawString("Type: " + ReportType.Text,
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       380, 90);

                page.Canvas.DrawLine(new PdfPen(System.Drawing.Color.Black), new PointF(1, 70), new PointF(530, 70));

                page.Canvas.DrawString(cDate.ToString("MMMM dd, yyyy").ToUpper() + " (" + cDate.ToString("dddd").ToUpper() + ")",
                                       new PdfFont(PdfFontFamily.TimesRoman, 12f),
                                       new PdfSolidBrush(System.Drawing.Color.Black),
                                       10, 90);

                PdfTable table = new PdfTable();
                table.Style.CellPadding       = 2;
                table.Style.DefaultStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.AlternateStyle      = new PdfCellStyle();
                table.Style.AlternateStyle.Font = new PdfTrueTypeFont(new Font("Times New Roman", 11f));

                table.Style.HeaderSource             = PdfHeaderSource.ColumnCaptions;
                table.Style.HeaderStyle.Font         = new PdfFont(PdfFontFamily.TimesRoman, 13f);
                table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

                table.Style.ShowHeader = true;

                table.DataSourceType = PdfTableDataSourceType.TableDirect;
                table.DataSource     = GenerateList();
                //Set the width of column
                float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);
                table.Columns[0].Width        = width * 0.24f * width;
                table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[1].Width        = width * 0.21f * width;
                table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[2].Width        = width * 0.24f * width;
                table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Columns[3].Width        = width * 0.24f * width;
                table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                table.Draw(page, new PointF(10, 120));

                string fname = "Scheduling_Report-" + ReportType.Text + "-" + DateTime.Now.ToString("MMM_dd_yyyy") + ".pdf";
                //save
                pdfDoc.SaveToFile(@"..\..\" + fname);
                //launch the pdf document
                System.Diagnostics.Process.Start(@"..\..\" + fname);
            }
        }
예제 #8
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);
        }
예제 #9
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;
        }
예제 #10
0
        public void Treatment(Route NewRoute, Player NewUser)
        {
            idroute  = NewRoute.idroute;
            username = NewUser.nickname;
            string           stringRoute = "Route of " + username;
            PdfDocument      doc         = new PdfDocument();
            PdfUnitConvertor unitCvtr    = new PdfUnitConvertor();
            PdfMargins       margin      = new PdfMargins()
            {
                Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point),
                Bottom = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point),
                Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point),
                Right  = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point),
            };
            PdfPageBase     page   = doc.Pages.Add(PdfPageSize.A4, margin);
            float           y      = 10;
            PdfBrush        brush1 = PdfBrushes.Black;
            PdfBrush        brush2 = PdfBrushes.Blue;
            PdfTrueTypeFont font1  = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Regular));

            page.Canvas.DrawString("©thelittlewozniak", font2, brush2, 350, 0);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString(stringRoute, font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString(stringRoute, format1).Height;
            y = y + 5;
            InfoUser[0, 0] = "Name:";
            InfoUser[1, 0] = "Rapidity";
            InfoUser[2, 0] = "Trust";
            InfoUser[0, 1] = NewUser.nickname;
            InfoUser[1, 1] = NewUser.rapidity.RapidityName;
            InfoUser[2, 1] = NewUser.trust.trustName;
            PdfTable table = new PdfTable();

            table.Style.BorderPen = new PdfPen(PdfBrushes.Transparent, 0f);
            table.Style.DefaultStyle.BorderPen = new PdfPen(PdfBrushes.Transparent, 0f);
            table.DataSource = InfoUser;
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

            y = y + 70;
            string[,] InfoRoute = new string[6, 2];
            InfoRoute[0, 0]     = "IDROUTE: ";
            InfoRoute[1, 0]     = "WAZELINK: ";
            InfoRoute[2, 0]     = "MAPSLINK: ";
            InfoRoute[3, 0]     = "DISTANCEKM: ";
            InfoRoute[4, 0]     = "TIMEMIN: ";
            InfoRoute[5, 0]     = "STATUS: ";
            InfoRoute[0, 1]     = NewRoute.idroute.ToString();
            InfoRoute[1, 1]     = NewRoute.wazelink;
            InfoRoute[2, 1]     = NewRoute.mapslink + "\r\n";
            InfoRoute[3, 1]     = Convert.ToString(Math.Round(Convert.ToDouble(NewRoute.distance), 1));
            InfoRoute[4, 1]     = Convert.ToString(Math.Round(Convert.ToDouble(NewRoute.time), 1));
            InfoRoute[5, 1]     = NewRoute.status.statusName;
            PdfTable table2 = new PdfTable();

            table2.DataSource        = InfoRoute;
            table2.Style.CellPadding = 5;
            PdfLayoutResult result2 = table2.Draw(page, new PointF(0, y));

            stringRoute = stringRoute + " " + DateTime.Now.ToLongDateString() + ".pdf";
            doc.SaveToFile(stringRoute);
            doc.Close();
            System.Diagnostics.Process.Start(stringRoute);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a Pdf document
            PdfDocument doc = new PdfDocument();

            //Add a page
            PdfPageBase page = doc.Pages.Add();

            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 a table
            PdfTable table = new PdfTable();

            table.Style.BorderPen = new PdfPen(brush1, 0.5f);

            //Header style
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader     = true;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 14f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            //Repeat header
            table.Style.RepeatHeader = true;

            //Body style
            table.Style.DefaultStyle.BackgroundBrush = PdfBrushes.SkyBlue;
            table.Style.DefaultStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 10f));
            table.Style.DefaultStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            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    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            table.DataSource = GetData();

            //Set the Pdf table layout and specify the paginate bounds
            PdfTableLayoutFormat tableLayout = new PdfTableLayoutFormat();

            tableLayout.Break          = PdfLayoutBreakType.FitElement;
            tableLayout.Layout         = PdfLayoutType.Paginate;
            tableLayout.PaginateBounds = new RectangleF(0, y, page.ActualSize.Width - 100, page.ActualSize.Height / 3);

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

            //Drow the table in page
            PdfLayoutResult result = table.Draw(page, new PointF(0, y), tableLayout);

            //Save the document
            string output = "InsertPageBreak_out.pdf";

            doc.SaveToFile(output);
            doc.Close();

            //Launch the Pdf file
            PDFDocumentViewer(output);
        }
예제 #12
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");
        }
예제 #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Set the 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;

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

            float y = 10;

            //Title
            PdfBrush        brush  = PdfBrushes.Black;
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Country List", font, brush, page.Canvas.ClientSize.Width / 2, y, format);
            y = y + font.MeasureString("Country List", format).Height;
            y = y + 5;

            //Create data table
            PdfTable table = new PdfTable();

            table.Style.BorderPen = new PdfPen(brush, 0.5f);

            //Header style
            table.Style.HeaderSource   = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount = 1;
            table.Style.ShowHeader     = true;
            table.Style.HeaderStyle.BackgroundBrush = PdfBrushes.CadetBlue;
            table.Style.HeaderStyle.Font            = new PdfTrueTypeFont(new Font("Arial", 14f, FontStyle.Bold));
            table.Style.HeaderStyle.StringFormat    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            //Repeat header
            table.Style.RepeatHeader = true;

            //Body style
            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.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 text below the table
            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 the document
            doc.SaveToFile("AddRepeatingColumn_out.pdf");
            doc.Close();

            //Launch the Pdf
            PDFDocumentViewer("AddRepeatingColumn_out.pdf");
        }
예제 #14
0
        private static void DrawPage(PdfPageBase page, CFDIXML cfdi)
        {
            float pageWidth      = page.Canvas.ClientSize.Width;
            float y              = 0;
            float leftMargin     = 5;
            float midPage        = pageWidth / 2;
            float topWritingArea = 0;
            int   sectionSpacing = 15;
            float qrSize         = 100;

            //Fonts
            string          fontName    = "Arial Condensed";
            PdfTrueTypeFont font7Bold   = new PdfTrueTypeFont(new Font(fontName, 7f, System.Drawing.FontStyle.Bold));
            PdfTrueTypeFont font7       = new PdfTrueTypeFont(new Font(fontName, 7f, System.Drawing.FontStyle.Regular));
            PdfTrueTypeFont font6Italic = new PdfTrueTypeFont(new Font(fontName, 6f, System.Drawing.FontStyle.Italic));

            //Colors
            PdfRGBColor lightBlack = new PdfRGBColor(17, 17, 17);

            //Pen
            PdfPen penLightGray1p   = new PdfPen(System.Drawing.Color.LightGray, 1f);
            PdfPen penLightGray05p  = new PdfPen(System.Drawing.Color.LightGray, 0.5f);
            PdfPen penLightBlack10p = new PdfPen(lightBlack, 10f);

            //Brushes
            PdfBrush brushBlack     = new PdfSolidBrush(System.Drawing.Color.Black);
            PdfBrush brushLightGray = new PdfSolidBrush(System.Drawing.Color.LightGray);

            //Format Alignments
            PdfStringFormat formatRight  = new PdfStringFormat(PdfTextAlignment.Right);
            PdfStringFormat formatMiddle = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            PdfStringFormat formatLeft   = new PdfStringFormat(PdfTextAlignment.Left)
            {
                CharacterSpacing = 0.4f
            };

            //Page header
            String text = "Factura version " + cfdi.Version;

            page.Canvas.DrawString(text, font6Italic, brushLightGray, pageWidth, y, formatRight);
            SizeF size = font6Italic.MeasureString(text, formatRight);

            y = y + size.Height + 1;
            page.Canvas.DrawLine(penLightGray1p, 0, y, pageWidth, y);

            y = y + 5;
            topWritingArea = y;

            //Issuerinfo
            //Name
            DrawToPage(page, cfdi.Emisor.Nombre, font7Bold, brushBlack, formatLeft, leftMargin, y, out y);
            //RFC
            DrawToPage(page, cfdi.Emisor.Rfc, font7Bold, brushBlack, formatLeft, leftMargin, y, out y);
            //Fiscal Regime
            DrawToPage(page, cfdi.Emisor.RegimenFiscal, font7, brushBlack, formatLeft, leftMargin, y, out y);
            //Address
            text = "Calle:" + cfdi.Emisor.Domicilio.Calle + " No:" + cfdi.Emisor.Domicilio.NoExterior;
            if (cfdi.Emisor.Domicilio.NoInterior != null)
            {
                text += "-" + cfdi.Emisor.Domicilio.NoInterior;
            }
            text += " Col:" + cfdi.Emisor.Domicilio.Colonia + ", Localidad:" + cfdi.Emisor.Domicilio.Localidad + ", Municipio:" + cfdi.Emisor.Domicilio.Municipio + ", Estado:" + cfdi.Emisor.Domicilio.Estado + ", CP:" + cfdi.Emisor.Domicilio.Cp;
            RectangleF area = new RectangleF(leftMargin, y, midPage - 10, 30);

            DrawToPage(page, text, font7, brushBlack, formatLeft, area, y, out y, false);
            DrawToPage(page, "Pais:" + cfdi.Emisor.Domicilio.Pais, font7, brushBlack, formatLeft, leftMargin, y, out y);

            //Invoice data
            y = topWritingArea;
            //Invoice header
            y += 5;
            page.Canvas.DrawLine(penLightBlack10p, midPage, y, pageWidth, y);
            text = "Factura";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, pageWidth - size.Width - 10, y, out y);
            //Invoice number
            DrawToPageWithHeader(page, "Folio:", cfdi.Folio, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "Serie:", cfdi.Serie ?? "", font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "Folio Fiscal:", cfdi.TimbreFiscal.UUID, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "Serie CSD del SAT:", cfdi.TimbreFiscal.NoCertificadoSAT, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "No. Certificado:", cfdi.NoCertificado, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "Fecha emsión:", cfdi.Fecha, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPageWithHeader(page, "Fecha certificación:", cfdi.TimbreFiscal.FechaTimbrado, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);

            //Issue place
            y += 5;
            DrawToPageWithHeader(page, "Lugar de expedición:", cfdi.LugarExpedicion, font7Bold, font7, brushBlack, formatLeft, leftMargin, y, out y);

            //Reciever data
            //Reciever header
            y += sectionSpacing;
            page.Canvas.DrawLine(penLightBlack10p, leftMargin, y, pageWidth, y);
            text = "Receptor";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, midPage - (size.Width / 2), y, out y);
            //Reciever name
            DrawToPageWithHeader(page, "Receptor:  ", cfdi.Receptor.Nombre, font7Bold, font7, brushBlack, formatLeft, leftMargin, y, out y, true);
            //Reciever address
            text = "Calle:  " + cfdi.Receptor.Domicilio.Calle + " No:" + cfdi.Receptor.Domicilio.NoExterior;
            if (cfdi.Receptor.Domicilio.NoInterior != null)
            {
                text += "-" + cfdi.Receptor.Domicilio.NoInterior;
            }
            DrawToPageWithHeader(page, "Domicilio:   ", text, font7Bold, font7, brushBlack, formatLeft, midPage, y, out y);
            //RFC
            DrawToPageWithHeader(page, "R.F.C.:", cfdi.Receptor.Rfc, font7Bold, font7, brushBlack, formatLeft, leftMargin, y, out y, true);
            //Next line address
            text = " Col:" + cfdi.Receptor.Domicilio.Colonia + ", Localidad:" + cfdi.Receptor.Domicilio.Localidad + ", Municipio:" + cfdi.Receptor.Domicilio.Municipio;
            area = new RectangleF(midPage, y, midPage - 10, 20);
            DrawToPage(page, text, font7, brushBlack, formatLeft, area, y, out y, false);
            text = " Estado:" + cfdi.Receptor.Domicilio.Estado + ", CP:" + cfdi.Receptor.Domicilio.Cp;
            DrawToPage(page, text, font7, brushBlack, formatLeft, midPage, y, out y);
            DrawToPage(page, "Pais:" + cfdi.Receptor.Domicilio.Pais, font7, brushBlack, formatLeft, midPage, y, out y);

            //Products
            y += sectionSpacing;

            //Prepare data
            String[][] dataSource = new String[cfdi.Conceptos.Count + 1][];
            String     headers    = "Cant.;Unidad;Clave;Descripción;Valor unitario;Importe";
            int        i          = 0;

            dataSource[i] = headers.Split(';');
            foreach (Concepto product in cfdi.Conceptos)
            {
                i++;
                String[] content = new String[6];
                content[0]    = product.Cantidad.ToString();
                content[1]    = product.Unidad;
                content[2]    = product.NoIdentificacion;
                content[3]    = product.Descripcion;
                content[4]    = String.Format("{0:N1}", product.ValorUnitario);
                content[5]    = String.Format("{0:C2}", product.Importe);
                dataSource[i] = content;
            }

            //Generate table
            PdfTable      productsTable = new PdfTable();
            PdfTableStyle style         = new PdfTableStyle()
            {
                BorderPen      = new PdfPen(lightBlack, 0.5f),
                CellPadding    = 2,
                HeaderSource   = PdfHeaderSource.Rows,
                HeaderRowCount = 1,
                ShowHeader     = true,
                HeaderStyle    = new PdfCellStyle()
                {
                    BackgroundBrush = new PdfSolidBrush(System.Drawing.Color.Black),
                    TextBrush       = brushLightGray,
                    StringFormat    = formatMiddle
                }
            };

            productsTable.Style = style;

            productsTable.DataSource       = dataSource;
            productsTable.Columns[0].Width = 8;
            productsTable.Columns[3].Width = 30;
            foreach (PdfColumn column in productsTable.Columns)
            {
                column.StringFormat = formatLeft;
            }

            PdfLayoutResult result = productsTable.Draw(page, new PointF(leftMargin, y));

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

            //Total in letter and number
            page.Canvas.DrawLine(penLightBlack10p, leftMargin, y, pageWidth, y);
            text = "Total con Letra";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, leftMargin, y, out y);
            DrawToPage(page, Conv.Enletras(cfdi.Total.ToString()) + "M.N.", font7, brushBlack, formatLeft, leftMargin, y, out y, true);

            DrawToPageWithHeader(page, "Subtotal:", String.Format("       {0:C2}", cfdi.SubTotal), font7Bold, font7, brushBlack, formatLeft, midPage + (midPage / 2), y, out y);
            DrawToPageWithHeader(page, "Total:", String.Format("            {0:C2}", cfdi.Total), font7Bold, font7, brushBlack, formatLeft, midPage + (midPage / 2), y, out y);

            //QR Code with basic data
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(String.Format("?re={0}&rr={1}&tt={2:N1}&id={3}", cfdi.Emisor.Rfc, cfdi.Receptor.Rfc, cfdi.Total, cfdi.TimbreFiscal.UUID), QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);
            Bitmap          qrCodeImage = qrCode.GetGraphic(20);

            float qrPosition = y;

            PdfImage image = PdfImage.FromImage(qrCodeImage);

            page.Canvas.DrawImage(image, leftMargin, y, qrSize, qrSize);

            //Payment info
            y = qrPosition + sectionSpacing;
            DrawToPageWithHeader(page, "Método de pago:  ", cfdi.MetodoDePago, font7Bold, font7, brushBlack, formatLeft, leftMargin + qrSize, y, out y);
            DrawToPageWithHeader(page, "Cuenta:  ", cfdi.NumCtaPago ?? "", font7Bold, font7, brushBlack, formatLeft, leftMargin + qrSize, y, out y);
            DrawToPageWithHeader(page, "Forma de pago:  ", cfdi.FormaDePago, font7Bold, font7, brushBlack, formatLeft, leftMargin + qrSize, y, out y);
            DrawToPageWithHeader(page, "Condiciones de pago:  ", cfdi.CondicionesDePago ?? "", font7Bold, font7, brushBlack, formatLeft, leftMargin + qrSize, y, out y);

            y = qrPosition + qrSize + sectionSpacing;
            page.Canvas.DrawLine(penLightBlack10p, leftMargin, y, pageWidth, y);
            text = "Cadena original del complemento de certificación del SAT";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, leftMargin, y, out y);
            area = new RectangleF(leftMargin, y, pageWidth - 5, 100);
            DrawToPage(page, String.Format("||{0}|{1}|{2}|{3}|{4}", cfdi.TimbreFiscal.Version, cfdi.TimbreFiscal.UUID, cfdi.TimbreFiscal.FechaTimbrado, cfdi.Sello, cfdi.TimbreFiscal.NoCertificadoSAT), font7Bold, brushBlack, formatLeft, area, y, out y, false);

            y += sectionSpacing;
            page.Canvas.DrawLine(penLightBlack10p, leftMargin, y, pageWidth, y);
            text = "Sello digital del SAT";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, leftMargin, y, out y);
            area = new RectangleF(leftMargin, y, pageWidth - 5, 100);
            DrawToPage(page, cfdi.TimbreFiscal.SelloSAT, font7Bold, brushBlack, formatLeft, area, y, out y, false);

            y += sectionSpacing;
            page.Canvas.DrawLine(penLightBlack10p, leftMargin, y, pageWidth, y);
            text = "Sello digital del contribuyente que lo expide";
            size = font7Bold.MeasureString(text, formatLeft);
            y   -= 4;
            DrawToPage(page, text, font7Bold, brushLightGray, formatLeft, leftMargin, y, out y);
            area = new RectangleF(leftMargin, y, pageWidth - 5, 100);
            DrawToPage(page, cfdi.Sello, font7Bold, brushBlack, formatLeft, area, y, out y, false);

            //Footer
            DrawToPage(page, "Este documento es una representación impresa de un CFDI", font7, brushBlack, formatLeft, midPage, page.Canvas.ClientSize.Height - 30, out y, false);
        }
예제 #15
0
        public void printReport(DateTime sDateStart, DateTime sDateEnd, string sStatus, int Tank)
        {
            string sFileName = DateTime.Now.ToString("yyyy.MM.dd HH.mm.ss");

            sFileName = sFileName.Replace(".", "");
            sFileName = "Report_" + sFileName.Replace(" ", "");
            string sStartDate = sDateStart.Year + "-" + sDateStart.Month + "-" + sDateStart.Day;
            string sFinDate   = sDateEnd.Year + "-" + sDateEnd.Month + "-" + sDateEnd.Day;

            string sqlQuery = "select id, datefin, tankId, setp, mass, vol, cntst, cntfin, status, sourcetank from datatable";

            sqlQuery += " where (datecreate between '" + sStartDate + " 00:00:00' and '" + sFinDate + " 23:59:59')";
            if (!sStatus.Equals("всі"))
            {
                sqlQuery += " and (status = '" + sStatus + "')";
            }
            if (Tank > 0)
            {
                sqlQuery += " and (sourcetank = '" + Tank.ToString() + "')";
            }
            sqlQuery           += " union select '', 'Разом', '', '', sum(mass), sum(vol), '', '', '', '' from datatable";
            sqlQuery           += " where (datecreate between '" + sStartDate + " 00:00:00' and '" + sFinDate + " 23:59:59')";
            command.CommandText = sqlQuery;
            OdbcDataReader dataReader = command.ExecuteReader();

            List <List <string> > data       = new List <List <string> >();
            List <string>         dataHeader = new List <string>();

            dataHeader.Add("ID");
            dataHeader.Add("Дата");
            dataHeader.Add("Флексітанк");
            dataHeader.Add("Завдання,кг");
            dataHeader.Add("Маса,кг");
            dataHeader.Add("Об'єм,л");
            dataHeader.Add("Поч.покази, кг");
            dataHeader.Add("Кін.покази, кг");
            dataHeader.Add("Статус");
            dataHeader.Add("Бак");
            data.Add(dataHeader);
            int records = 0;

            while (dataReader.Read())
            {
                List <string> dataRow = new List <string>();
                for (int i = 0; i < dataHeader.Count; i++)
                {
                    if (!dataReader.GetValue(i).Equals(dbnull))
                    {
                        dataRow.Add(dataReader.GetValue(i).ToString());
                    }
                    else
                    {
                        dataRow.Add("");
                    }
                }
                data.Add(dataRow);
                records++;
            }
            dataReader.Close();
            if (records <= 1)
            {
                MessageBox.Show("Записів за вибраними критеріями не знайдено", "Звіт", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string[,] dataArray = new string[data.Count, data[0].Count];
            for (int i = 0; i < data.Count; i++)
            {
                for (int j = 0; j < data[0].Count; j++)
                {
                    dataArray[i, j] = data[i][j];
                }
            }

            PdfDocument      doc      = new PdfDocument();
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(1.5F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(1.7F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = unitCvtr.ConvertUnits(0.6F, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            PdfPageBase     page         = doc.Pages.Add(PdfPageSize.A4, margin);
            PdfStringFormat alignCenter  = new PdfStringFormat(PdfTextAlignment.Center);
            PdfStringFormat alignLeft    = new PdfStringFormat(PdfTextAlignment.Left);
            PdfStringFormat alignJustify = new PdfStringFormat(PdfTextAlignment.Justify);
            PdfStringFormat alignRight   = new PdfStringFormat(PdfTextAlignment.Right);
            Single          y            = 4;
            PdfBrush        brush1       = PdfBrushes.Black;
            PdfTrueTypeFont font1        = new PdfTrueTypeFont(new Font("Times", 16, FontStyle.Bold), true);
            PdfBrush        brush2       = PdfBrushes.DarkGray;
            PdfTrueTypeFont font2        = new PdfTrueTypeFont(new Font("Arial", 8, FontStyle.Regular), true);
            PdfTrueTypeFont fontTable    = new PdfTrueTypeFont(new Font("Times", 10, FontStyle.Regular), true);
            PdfTrueTypeFont fontHeader   = new PdfTrueTypeFont(new Font("Arial", 8, FontStyle.Bold), true);
            PdfStringFormat format1      = alignCenter;
            string          sTitle       = "Дані наливу з " + sDateStart.Day.ToString("d2") + "." + sDateStart.Month.ToString("d2") + "." + sDateStart.Year + " по ";

            sTitle += sDateEnd.Day.ToString("d2") + "." + sDateEnd.Month.ToString("d2") + "." + sDateEnd.Year + " (включно)";
            page.Canvas.DrawString(sTitle, font1, brush1, page.Canvas.ClientSize.Width / 2, y + 20, format1);
            y += 30 + font1.MeasureString(sTitle, format1).Height;
            PdfTable table = new PdfTable();

            table.Style.BorderPen                              = new PdfPen(brush1, 0.001f);
            table.Style.DefaultStyle.Font                      = fontTable;
            table.Style.DefaultStyle.BorderPen                 = new PdfPen(brush1, 0.001f);
            table.Style.CellPadding                            = 1;
            table.Style.HeaderSource                           = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount                         = 1;
            table.Style.ShowHeader                             = true;
            table.Style.HeaderStyle.Font                       = fontHeader;
            table.Style.RepeatHeader                           = true;
            table.Style.HeaderStyle.BackgroundBrush            = PdfBrushes.LightGray;
            table.Style.HeaderStyle.StringFormat               = alignCenter;
            table.Style.HeaderStyle.StringFormat.LineAlignment = PdfVerticalAlignment.Middle;
            table.Style.DefaultStyle.StringFormat              = alignCenter;
            table.Style.HeaderStyle.StringFormat.LineAlignment = PdfVerticalAlignment.Middle;

            table.DataSource = dataArray;

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

            // id, datefin, tankId, setp, mass, vol, cntst, cntfin, status, sourcetank
            table.Columns[0].Width = 0.05f * tableWidth;  // ID
            table.Columns[1].Width = 0.2f * tableWidth;   // Date
            table.Columns[2].Width = 0.2f * tableWidth;   // tankId 0.4
            table.Columns[3].Width = 0.075f * tableWidth; // setp
            table.Columns[4].Width = 0.075f * tableWidth; // mass 0.55
            table.Columns[5].Width = 0.075f * tableWidth; // vol  0.625
            table.Columns[6].Width = 0.1f * tableWidth;   // count start
            table.Columns[7].Width = 0.1f * tableWidth;   // count fin
            table.Columns[8].Width = 0.1f * tableWidth;   // status
            table.Columns[9].Width = 0.025f * tableWidth; // sourceTank

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

            y += result.Bounds.Height + 10;
            page.Canvas.DrawString(String.Format("* {0} записів знайдено ", records - 1), font2, brush2, 5, 0);
            page.Canvas.DrawString("Створено " + DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss"), font2, brush2, 200, 0);
            doc.SaveToFile("C:/FillFlex/Reports/" + sFileName + ".pdf");
            doc.Close();

            DialogResult res = MessageBox.Show("C:/FillFlex/Reports/" + sFileName + ".pdf успішно створено. Відкрити?", "Звіт", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res == DialogResult.Yes)
            {
                System.Diagnostics.Process.Start("C:/FillFlex/Reports/" + sFileName + ".pdf");
            }
        }
예제 #16
0
        public void TableToPdf()
        {
            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(2.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

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

            // Title
            PdfBrush        brush1       = PdfBrushes.Black;
            String          fontFileName = "C:\\Fonts\\bpg_nino_mtavruli_normal.ttf";
            PdfTrueTypeFont fontTrue     = new PdfTrueTypeFont(fontFileName, 14f);
            PdfStringFormat format1      = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("დაკავებულობა", fontTrue, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + fontTrue.MeasureString("დაკავებულობა", format1).Height;
            y = y + 5;

            DataTable dt = this.table.Clone();

            for (int i = 0; i < this.table.Columns.Count; i++)
            {
                dt.Columns[i].DataType = typeof(Object);
            }
            foreach (DataRow row in this.table.Rows)
            {
                dt.ImportRow(row);
            }
            DataRow headerRow = dt.NewRow();

            for (int i = 0; i < this.table.Columns.Count; i++)
            {
                headerRow[i] = this.table.Columns[i].ColumnName;
            }

            dt.Rows.InsertAt(headerRow, 0);
            PdfTable table = new PdfTable();

            table.Style.CellPadding       = 2;
            table.Style.HeaderSource      = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount    = 1;
            table.Style.ShowHeader        = true;
            table.Style.DefaultStyle.Font = new PdfTrueTypeFont(fontFileName, 10f);
            table.Style.HeaderStyle.Font  = new PdfTrueTypeFont(fontFileName, 12f);
            table.DataSource = dt;
            table.Style.AlternateStyle.Font = new PdfTrueTypeFont(fontFileName, 10f);
            PdfLayoutResult result = table.Draw(page, new PointF(0, y));

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

            doc.SaveToFile("TestTable.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("TestTable.pdf");
        }
예제 #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            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(';');
            }

            //create a pdf document
            PdfDocument doc = new PdfDocument();

            //add a new page
            PdfPageBase page = doc.Pages.Add();

            //creata a pdf table
            PdfTable table = new PdfTable();

            //set data source of the pdf table
            table.DataSource = dataSource;

            //set the color of table border
            PdfTableStyle style = new PdfTableStyle();

            style.CellPadding = 2;
            style.BorderPen   = new PdfPen(Color.Green, 1f);
            table.Style       = style;

            //add custom method to BeginRowLayout event
            table.BeginRowLayout += new BeginRowLayoutEventHandler(table_BeginRowLayout);

            //draw the pdf table into pdf document
            table.Draw(page, new PointF(0, 40));

            string output = "TableBorder.pdf";

            //save pdf document
            doc.SaveToFile(output);

            //Launching the Pdf file
            PDFDocumentViewer(output);
        }
예제 #18
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);
        }
예제 #19
0
        public static void CreatePDF()
        {
            //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 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("Customer Report", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Customer Report", format1).Height;
            y = y + 5;
            String[][] dataSource;
            using (var db = new AirportDbContext())
            {
                var tickets = db.Tickets.Select(x => new { Company = x.Company.Name, Destination = x.Destination.Name, CustomerName = x.Customer.FirstName + " " + x.Customer.LastName, Date = x.TravelingDate, Price = x.Price.ToString() });
                var counter = 1;
                dataSource    = new String[tickets.Count() + 1][];
                dataSource[0] = new string[] { "Company", "Destination", "Customer", "Date", "Price" };
                foreach (var ticket in tickets)
                {
                    var date = ticket.Date.Date.ToShortDateString();
                    dataSource[counter] = new string[] { ticket.Company, ticket.Destination, ticket.CustomerName, date, ticket.Price };
                    counter++;
                }
            }
            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",
                };

            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));

            //Save pdf file.
            doc.SaveToFile("TicketsReport.pdf");
            doc.Close();
            System.Diagnostics.Process.Start("TicketsReport.pdf");
        }
예제 #20
0
        public static void UdskrivBilag(tblbilag Bilag)
        {
            int            Regnskabid    = (int)Bilag.regnskabid;
            recMemRegnskab rec_regnskab  = (from r in Program.memRegnskab where r.Rid == Regnskabid select r).First();
            string         firma         = rec_regnskab.Firmanavn;
            string         regnskabsnavn = rec_regnskab.Navn;
            DateTime       startdato     = (DateTime)rec_regnskab.Start;
            DateTime       slutdato      = (DateTime)rec_regnskab.S**t;
            DateTime       bilagsdato    = (DateTime)Bilag.dato;

            int startMonth   = startdato.Month;
            int bilagMonth   = bilagsdato.Month;
            int regnskabsaar = slutdato.Year;
            int pnr;

            if (bilagMonth < startMonth)
            {
                pnr = bilagMonth + 12 - startMonth + 1;
            }
            else
            {
                pnr = bilagMonth - startMonth + 1;
            }
            DateTime PeriodeMonthYear = new DateTime(slutdato.Year, pnr, 1);
            string   Periode          = PeriodeMonthYear.ToString("MM");


            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            doc.DocumentInformation.Author       = "Hafsjold Data Consult";
            doc.DocumentInformation.Title        = String.Format("Bogføringsbilag {0}", regnskabsnavn);
            doc.DocumentInformation.Creator      = "Trans2SummaHDC";
            doc.DocumentInformation.Subject      = String.Format("Bilag {0}", ((int)Bilag.bilag).ToString());
            doc.DocumentInformation.CreationDate = DateTime.Now;

            //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(2f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            // Create one page
            PdfPageBase page  = doc.Pages.Add(PdfPageSize.A4, margin);
            float       width = page.Canvas.ClientSize.Width;

            float y = 10;

            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            string          s       = String.Format("Bogføringsbilag {0}", regnskabsnavn);

            page.Canvas.DrawString(s, font1, brush1, 1, y, format1);
            y = y + font1.MeasureString(s, format1).Height;
            y = y + 25;

            PdfBrush        brush2 = PdfBrushes.Black;
            PdfTrueTypeFont font2  = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));

            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Left);

            s = String.Format("Dato: {0}", ((DateTime)Bilag.dato).ToShortDateString());
            page.Canvas.DrawString(s, font2, brush2, 1, y, format2);

            PdfStringFormat format21 = new PdfStringFormat(PdfTextAlignment.Center);

            s = String.Format("Periode: {0}", Periode);
            page.Canvas.DrawString(s, font2, brush2, width / 2, y, format21);

            PdfStringFormat format22 = new PdfStringFormat(PdfTextAlignment.Right);

            s = String.Format("Bilag: {0}", ((int)Bilag.bilag).ToString());
            page.Canvas.DrawString(s, font2, brush2, width, y, format22);

            y = y + font2.MeasureString(s, format2).Height;
            y = y + 25;

            String[][] dataSource = new String[Bilag.tbltrans.Count + 1][];
            int        i          = 0;

            foreach (tbltran t in Bilag.tbltrans)
            {
                if (i == 0)
                {
                    String[] headings = new String[5];
                    headings[0]     = "Tekst";
                    headings[1]     = "Kontonr";
                    headings[2]     = "Kontonavn";
                    headings[3]     = "Debet";
                    headings[4]     = "Kredit";
                    dataSource[i++] = headings;
                }

                String[] datarow = new String[5];
                datarow[0]      = t.tekst;
                datarow[1]      = t.kontonr.ToString();
                datarow[2]      = t.kontonavn;
                datarow[3]      = t.debet != null ? ((decimal)(t.debet)).ToString("#,0.00;-#,0.00") : "";
                datarow[4]      = t.kredit != null ? ((decimal)(t.kredit)).ToString("#,0.00;-#,0.00") : "";
                dataSource[i++] = datarow;
            }

            PdfTable table = new PdfTable();

            table.Style.CellPadding              = 5; //2;
            table.Style.HeaderSource             = PdfHeaderSource.Rows;
            table.Style.HeaderRowCount           = 1;
            table.Style.HeaderStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);
            table.Style.HeaderStyle.Font         = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Bold));
            table.Style.ShowHeader   = true;
            table.Style.RepeatHeader = true;
            table.DataSource         = dataSource;


            table.Columns[0].Width        = width * 0.30f * width;
            table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[1].Width        = width * 0.10f * width;
            table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            table.Columns[2].Width        = width * 0.30f * width;
            table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[3].Width        = width * 0.15f * width;
            table.Columns[3].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);
            table.Columns[4].Width        = width * 0.15f * 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;

            //Save pdf file.
            string BilagPath = (from r in Program.karTrans2Summa where r.key == "BilagPath" select r.value).First();
            string BilagNavn = String.Format(@"Bilag {0}.pdf", ((int)Bilag.bilag).ToString());
            string filename  = Path.Combine(BilagPath, BilagNavn);

            doc.SaveToFile(filename);
            doc.Close();
        }
예제 #21
0
파일: BuildPDF.cs 프로젝트: Minerr/BredVVS
        public string Save(string path)
        {
            float currentPageHeight   = _pagePaddingLeft;
            int   prevElementCount    = 0;
            int   currentElementCount = 0;

            while (_document.Content.Count > 0)
            {
                PDFelement element = _document.Content.Dequeue();
                currentElementCount = element.ElementIndex;

                float posY = currentPageHeight;
                float posX = _pagePaddingLeft;

                if (element.GetType() == typeof(PDFline))
                {
                    PDFline line = (PDFline)element;

                    posX = GetElementHorizontalPosition(element.TextAlignment);
                    _currentPage.Canvas.DrawString(line.Text, line.Font, line.Brush, posX, posY, line.TextFormat);
                }
                else if (element.GetType() == typeof(PDFsplitLine))
                {
                    PDFsplitLine splitLine = (PDFsplitLine)element;

                    PDFline leftLine  = splitLine.LeftLine;
                    PDFline rightLine = splitLine.RightLine;

                    _currentPage.Canvas.DrawString(
                        leftLine.Text, leftLine.Font, leftLine.Brush,
                        GetElementHorizontalPosition(PdfTextAlignment.Left), posY,
                        leftLine.TextFormat
                        );
                    _currentPage.Canvas.DrawString(
                        rightLine.Text, rightLine.Font, rightLine.Brush,
                        GetElementHorizontalPosition(PdfTextAlignment.Right), posY,
                        rightLine.TextFormat
                        );
                }
                else if (element.GetType() == typeof(PDFtable))
                {
                    PDFtable table = (PDFtable)element;

                    PdfTable spireTable = new PdfTable();
                    spireTable.DataSource        = table.Table;
                    spireTable.BeginRowLayout   += Table_BeginRowLayout;
                    spireTable.Style.CellPadding = table.CellPadding;
                    spireTable.Style.BorderPen   = new PdfPen(table.Brush);
                    spireTable.Style.HeaderStyle.StringFormat = new PdfStringFormat(table.TextAlignment);
                    spireTable.Style.HeaderRowCount           = 1;
                    spireTable.Style.ShowHeader = true;
                    spireTable.Style.HeaderStyle.BackgroundBrush = PdfBrushes.LightGray;


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

                    spireTable.Draw(_currentPage, new PointF(posX, posY));
                }

                currentPageHeight += element.Height;
                if (currentPageHeight >= _pageMaxHeight)
                {
                    _currentPage      = _section.Pages.Add();
                    currentPageHeight = 0;
                }

                prevElementCount = currentElementCount;
            }

            _path = path;
            _spirePDF.SaveToFile(path, FileFormat.PDF);

            return(path);
        }
예제 #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument doc = new PdfDocument();

            doc.LoadFromFile(@"..\..\..\..\..\..\Data\SimpleTable.pdf");

            PdfPageBase page = doc.Pages[0];

            float y = 320;

            //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(60, 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, 65, y);

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

            //Launch the Pdf file
            PDFDocumentViewer("SimpleTable.pdf");
        }
예제 #23
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Set 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;

            //Add 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)
                {
                    //Set the width of the column
                    table.Columns[i].Width = width * 0.4f * width;
                    //Set the string format
                    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();

            //Launch the Pdf file
            PDFDocumentViewer("TableLayout.pdf");
        }
        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);
        }
예제 #25
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");
        }
예제 #26
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);
        }
예제 #27
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;
        }
예제 #28
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");
        }
예제 #29
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");
        }
예제 #30
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));
        }
예제 #31
0
        private void GenReceipt()
        {
            int    amnt = int.Parse(AmountToBePaid.Content.ToString());
            string OR   = pmsutil.GenerateReceiptNum();

            PdfDocument     pdfDoc  = new PdfDocument();
            PdfPageBase     page    = pdfDoc.Pages.Add();
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("ROMAN CATHOLIC BISHOP OF LEGAZPI, INC.",
                                   new PdfFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 240, 0, format1);

            page.Canvas.DrawString("\n\nThe Chancery, Cathedral Compound,\nAlbay District. Legazpi City 4500\nTel. No. (052) 481-2178 . NON-VAT Reg.TIN No. 000-636-377-000",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 240, 0, format1);

            page.Canvas.DrawString("OFFICIAL RECEIPT",
                                   new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 75);

            page.Canvas.DrawString("\nDate: _______________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 285, 70);

            page.Canvas.DrawString("Received From " + ReceivedFrom.Text +
                                   "\nwith TIN__________________and address at ___________________________" +
                                   "\nengaged in the business style of______________________________________" +
                                   "\nthe sum of__________________________________________________ pesos" +
                                   "\n(P___________) in parial/full payment of the following:",

                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 100);


            String[] data =
            {
                "For; ; ",
                " ;P; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                " ; ; ",
                "Total Sales; ; ",
                "Less: SC/PWD Discount; ; ",
                "Total Due; ; ",
                "Thank you        TOTAL; ; ",
            };
            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.DataSource        = dataSource;
            float width = page.Canvas.ClientSize.Width - (table.Columns.Count + 1);

            table.Columns[0].Width        = width * 0.1f * width;
            table.Columns[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[1].Width        = width * 0.02f * width;
            table.Columns[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            table.Columns[2].Width        = width * 0.03f * width;
            table.Columns[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            table.Draw(page, new System.Drawing.PointF(40, 170));

            page.Canvas.DrawString("Form of Payment:                        __ Cash    __ Check\n" +
                                   "Check No.:_______________Bank:_______________\n" +
                                   "Sr. Citizen TIN\n" +
                                   "OSCA/PWD ID No.________________Signature_______________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 420);

            page.Canvas.DrawString("No. 161455",
                                   new PdfFont(PdfFontFamily.TimesRoman, 18f, PdfFontStyle.Bold),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 40, 475);

            page.Canvas.DrawString("by:",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 200, 470);;

            page.Canvas.DrawString("__________________________",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 200, 500);;

            page.Canvas.DrawString("Cashier",
                                   new PdfFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Italic),
                                   new PdfSolidBrush(System.Drawing.Color.Black), 250, 510);;

            string fname = "test.pdf";

            pdfDoc.SaveToFile(@"Receipts\" + fname);
            //MessageBox.Show("yey");
            System.Diagnostics.Process.Start(@"Receipts\" + fname);
        }