Beispiel #1
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);
            Image img = Image.FromFile(@"..\..\..\..\..\..\Data\Background.png");
            page.BackgroundImage = img;

            //Draw table
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("ImageWaterMark.pdf");
        }
Beispiel #2
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), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f, PdfFontStyle.Bold);
            String formatted
                = "Beverages\nCondiments\nConfections\nDairy Products\nGrains/Cereals\nMeat/Poultry\nProduce\nSeafood";

            PdfList list = new PdfList(formatted);
            list.Font = font;
            list.Indent = 8;
            list.TextIndent = 5;
            list.Brush = brush;
            PdfLayoutResult result = list.Draw(page, 0, y);
            y = result.Bounds.Bottom;

            PdfSortedList sortedList = new PdfSortedList(formatted);
            sortedList.Font = font;
            sortedList.Indent = 8;
            sortedList.TextIndent = 5;
            sortedList.Brush = brush;
            sortedList.Draw(page, 0, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("SimpleList.pdf");
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageLayout = PdfPageLayout.TwoColumnLeft;

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

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = new PdfMargins(0);
            SetSectionTemplate(section, PdfPageSize.A4, margin, "Section 1");

            // Create one page
            PdfNewPage page = section.Pages.Add();

            //Draw page
            DrawPage(page); 

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

            page = section.Pages.Add();
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Template.pdf");
        }
Beispiel #4
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);

            PdfTilingBrush brush
                = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
            brush.Graphics.SetTransparency(0.3f);
            brush.Graphics.Save();
            brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
            brush.Graphics.RotateTransform(-45);
            brush.Graphics.DrawString("Spire.Pdf Demo",
                new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0,
                new PdfStringFormat(PdfTextAlignment.Center));
            brush.Graphics.Restore();
            brush.Graphics.SetTransparency(1);
            page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));

            //Draw the page
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("TextWaterMark.pdf");
        }
Beispiel #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.DocumentInformation.Author = "Spire.Pdf";

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

            for (int i = 1; i < 4; i++)
            {
                //create section
                PdfSection section = doc.Sections.Add();
                section.PageSettings.Size = PdfPageSize.A4;
                section.PageSettings.Margins = margin;

                for (int j = 0; j < i; j++)
                {
                    // Create one page
                    PdfPageBase page = section.Pages.Add();
                    DrawAutomaticField(page);
                }
            }

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

            //Launching the Pdf file.
            PDFDocumentViewer("AutomaticField.pdf");
        }
Beispiel #6
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;

            DrawCover(doc.Sections.Add(), margin);
            DrawContent(doc.Sections.Add(), margin);
            DrawPageNumber(doc.Sections[1], margin, 1, doc.Sections[1].Pages.Count);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Pagination.pdf");
        }
Beispiel #7
0
        private void SetSectionTemplate(PdfSection section, SizeF pageSize, PdfMargins margin, String label)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);
            leftSpace.Foreground = true;
            section.Template.OddLeft = leftSpace;

            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            float y = (pageSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f);
            RectangleF bounds
                = new RectangleF(10, y, margin.Left - 20, font.Height + 6);
            leftSpace.Graphics.DrawRectangle(PdfBrushes.OrangeRed, bounds);
            leftSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);
            rightSpace.Foreground = true;
            section.Template.EvenRight = rightSpace;
            bounds
                = new RectangleF(10, y, margin.Right - 20, font.Height + 6);
            rightSpace.Graphics.DrawRectangle(PdfBrushes.SaddleBrown, bounds);
            rightSpace.Graphics.DrawString(label, font, PdfBrushes.White, bounds, format);
        }
Beispiel #8
0
        private void DrawPageHeaderAndFooter(PdfPageBase page, PdfMargins margin, bool isCover)
        {
            page.Canvas.SetTransparency(0.5f);
            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");
            page.Canvas.DrawImage(headerImage, new PointF(0, 0));
            page.Canvas.DrawImage(footerImage, new PointF(0, page.Canvas.ClientSize.Height - footerImage.PhysicalDimension.Height));
            if (isCover)
            {
                page.Canvas.SetTransparency(1);
                return;
            }

            PdfBrush brush = PdfBrushes.Black;
            PdfPen pen = new PdfPen(brush, 0.75f);
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic), true);
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
            format.MeasureTrailingSpaces = true;
            float space = font.Height * 0.75f;
            float x = margin.Left;
            float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
            float y = margin.Top - space;
            page.Canvas.DrawLine(pen, x, y, x + width, y);
            y = y - 1 - font.Height;
            page.Canvas.DrawString("Demo of Spire.Pdf", font, brush, x + width, y, format);
            page.Canvas.SetTransparency(1);
        }
Beispiel #9
0
        private void DrawCover(PdfSection section, PdfMargins margin)
        {
            section.PageNumber = new PdfPageNumber();
            section.PageNumber.NumberStyle = PdfNumberStyle.LowerRoman;
            section.PageNumber.Prefix = "cover ";
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins.All = 0;
            PdfPageBase page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, true);

            //refenrence content
            PdfBrush brush1 = PdfBrushes.LightGray;
            PdfBrush brush2 = PdfBrushes.Blue;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 8f));
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            String text1 = "(All text and picture from ";
            String text2 = "Wikipedia";
            String text3 = ", the free encyclopedia)";
            float x = 0, y = 10;
            x = x + margin.Left;
            y = y + margin.Top;
            page.Canvas.DrawString(text1, font1, brush1, x, y, format);
            x = x + font1.MeasureString(text1, format).Width;
            page.Canvas.DrawString(text2, font1, brush2, x, y, format);
            x = x + font1.MeasureString(text2, format).Width;
            page.Canvas.DrawString(text3, font1, brush1, x, y, format);

            //cover
            PdfBrush brush3 = PdfBrushes.Black;
            PdfBrush brush4 = new PdfSolidBrush(new PdfRGBColor(0xf9, 0xf9, 0xf9));
            PdfImage image
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            String text = Pagination.Properties.Resources.ImageDescription;
            float r = image.PhysicalDimension.Height / image.Height;
            PdfPen pen = new PdfPen(brush1, r);
            SizeF size = font1.MeasureString(text, image.PhysicalDimension.Width - 2);
            PdfTemplate template
                = new PdfTemplate(image.PhysicalDimension.Width + 4 * r + 4,
                    image.PhysicalDimension.Height + 4 * r + 7 + size.Height);
            template.Graphics.DrawRectangle(pen, brush4, 0, 0, template.Width, template.Height);
            x = y = r + 2;
            template.Graphics.DrawRectangle(brush1, x, y,
                image.PhysicalDimension.Width + 2 * r,
                image.PhysicalDimension.Height + 2 * r);
            x = y = x + r;
            template.Graphics.DrawImage(image, x, y);

            x = x - 1;
            y = y + image.PhysicalDimension.Height + r + 2;
            template.Graphics.DrawString(text, font1, brush3,
                new RectangleF(new PointF(x, y), size));

            float x1 = (page.Canvas.ClientSize.Width - template.Width) / 2;
            float y1 = (page.Canvas.ClientSize.Height - margin.Top - margin.Bottom) * (1 - 0.618f) - template.Height / 2 + margin.Top;
            template.Draw(page.Canvas, x1, y1);

            //title
            format.Alignment = PdfTextAlignment.Center;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 24f, FontStyle.Bold));
            x = page.Canvas.ClientSize.Width / 2;
            y = y1 + template.Height + 10;
            page.Canvas.DrawString(Pagination.Properties.Resources.Title, font2, brush3, x, y, format);
        }
Beispiel #10
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;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

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

            float y = 0;

            //title
            y = DrawPageTitle(page, y);

            //load form config data
            using (Stream stream = File.OpenRead(@"..\..\..\..\..\..\Data\Form.xml"))
            {
                XPathDocument xpathDoc = new XPathDocument(stream);
                XPathNodeIterator sectionNodes = xpathDoc.CreateNavigator().Select("/form/section");
                int fieldIndex = 0;
                foreach (XPathNavigator sectionNode in sectionNodes)
                {
                    //draw section label
                    String sectionLabel = sectionNode.GetAttribute("name", "");
                    y = DrawFormSection(sectionLabel, page, y);

                    XPathNodeIterator fieldNodes = sectionNode.Select("field");
                    foreach (XPathNavigator fieldNode in fieldNodes)
                    {
                        y= DrawFormField(fieldNode, doc.Form, page, y, fieldIndex++);
                    }
                }
            }

            //draw button
            y = y + 10;
            float buttonWidth = 80;
            float buttonX = (page.Canvas.ClientSize.Width - buttonWidth) / 2;
            RectangleF buttonBounds = new RectangleF(buttonX, y, buttonWidth, 16f);
            PdfButtonField button = new PdfButtonField(page, "submit");
            button.Text = "Submit";
            button.Bounds = buttonBounds;
            PdfSubmitAction submitAction = new PdfSubmitAction("http://www.e-iceblue.com");
            button.Actions.MouseUp = submitAction;
            doc.Form.Fields.Add(button);

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

            //Launching the Pdf file.
            PDFDocumentViewer("FormField.pdf");
        }
        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 void buttonRun_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFiledialog = new SaveFileDialog();

            saveFiledialog.Filter = "PDF Document (*.pdf)|*.pdf";
            bool?result = saveFiledialog.ShowDialog();

            if (!result.HasValue || !result.Value)
            {
                return;
            }

            //create a pdf document
            PdfDocument document = 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
                = document.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0,
                                     PdfPageOrientation.Landscape);
            float y = 0;

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

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

            PdfGrid grid = new PdfGrid();

            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            grid.Columns.Add(this.dataGridVendorList.Columns.Count);

            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);

            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;

            //header of grid
            PdfGridRow headerRow = grid.Headers.Add(1)[0];

            headerRow.Style.Font
                = new PdfTrueTypeFont(new Font("Arial", 11f, System.Drawing.FontStyle.Bold), true);
            String[] header = { "Vendor Name", "Address", "City", "State", "Country" };
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            }
            headerRow.Style.BackgroundBrush = PdfBrushes.SeaGreen;

            //datarow of grid
            int rowIndex = 1;

            foreach (Vendor vendor in this.dataSource)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font     = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                row.Cells[0].Value = vendor.VendorName;
                row.Cells[1].Value = vendor.Address;
                row.Cells[2].Value = vendor.City;
                row.Cells[3].Value = vendor.State;
                row.Cells[4].Value = vendor.Country;

                row.Cells[0].Style.BackgroundBrush = PdfBrushes.LightGray;
                row.Cells[0].StringFormat          = row.Cells[1].StringFormat = row.Cells[2].StringFormat
                                                                                     = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                row.Cells[3].StringFormat             = row.Cells[4].StringFormat
                                                      = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (rowIndex % 2 == 0)
                {
                    row.Style.BackgroundBrush = PdfBrushes.YellowGreen;
                }
                else
                {
                    row.Style.BackgroundBrush = PdfBrushes.Bisque;
                }
                rowIndex++;
            }

            StringBuilder totalAmount = new StringBuilder();

            var groupByCountry
                = this.dataSource.GroupBy(v => v.Country)
                  .Select(g => new { Name = g.Key, Count = g.Count() });

            foreach (var item in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", item.Name, item.Count);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();

            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value        = "Total Amount";
            totalAmountRow.Cells[0].Style.Font   = new PdfTrueTypeFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value      = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), true);
            // = new Font("Arial", 10f, System.Drawing.FontStyle.Bold);
            totalAmountRow.Cells[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            PdfLayoutResult resultl = grid.Draw(page, new PointF(0, y));

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

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

            resultl.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                                           font2, brush2, 5, y);

            //Save pdf file.
            using (Stream stream = saveFiledialog.OpenFile())
            {
                document.SaveToStream(stream);
            }
            document.Close();
        }
Beispiel #13
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), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

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

            RectangleF             rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfLinearGradientBrush brush3
                = new PdfLinearGradientBrush(rctg, Color.OrangeRed, Color.Navy, PdfLinearGradientMode.Vertical);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 8f), true);

            PdfOrderedMarker marker1
                = new PdfOrderedMarker(PdfNumberStyle.LowerRoman, new PdfFont(PdfFontFamily.Helvetica, 10f));
            PdfOrderedMarker marker2
                = new PdfOrderedMarker(PdfNumberStyle.Numeric, new PdfFont(PdfFontFamily.Helvetica, 8f));

            PdfSortedList vendorList = new PdfSortedList(font2);

            vendorList.Indent     = 0;
            vendorList.TextIndent = 5;
            vendorList.Brush      = brush2;
            vendorList.Marker     = marker1;
            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 VendorNo, VendorName from vendors ";
                command.Connection = conn;

                OleDbCommand command2 = new OleDbCommand();
                command2.CommandText
                    = " select Description from parts where VendorNo = @VendorNo";
                command2.Connection = conn;
                OleDbParameter param = new OleDbParameter("@VendorNo", OleDbType.Double);
                command2.Parameters.Add(param);

                conn.Open();

                OleDbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    double        id      = reader.GetDouble(0);
                    PdfListItem   item    = vendorList.Items.Add(reader.GetString(1));
                    PdfSortedList subList = new PdfSortedList(font3);
                    subList.Marker               = marker2;
                    subList.Brush                = brush3;
                    item.SubList                 = subList;
                    subList.TextIndent           = 20;
                    command2.Parameters[0].Value = id;
                    using (OleDbDataReader reader2 = command2.ExecuteReader())
                    {
                        while (reader2.Read())
                        {
                            subList.Items.Add(reader2.GetString(0));
                        }
                    }
                    String maxNumberLabel = Convert.ToString(subList.Items.Count);
                    subList.Indent = 30 - font3.MeasureString(maxNumberLabel).Width;
                }
            }

            PdfTextLayout textLayout = new PdfTextLayout();

            textLayout.Break  = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            vendorList.Draw(page, new PointF(0, y), textLayout);

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

            //Launching the Pdf file.
            PDFDocumentViewer("List.pdf");
        }
Beispiel #14
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);
            page.BackgroundColor = Color.Chocolate;

            //Draw page
            DrawPage(page);

            page = doc.Pages.Add(PdfPageSize.A4, margin);
            page.BackgroundColor = Color.Coral;

            //Draw page
            DrawPage(page);

            page = doc.Pages.Add(PdfPageSize.A3, margin, PdfPageRotateAngle.RotateAngle180, PdfPageOrientation.Landscape);
            page.BackgroundColor = Color.LightPink;

            //Draw page
            DrawPage(page);

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            page = section.Pages.Add();

            //Draw page
            DrawPage(page);

            //set background color
            page = section.Pages.Add();
            page.BackgroundColor = Color.LightSkyBlue;
            DrawPage(page);

            //Landscape
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Orientation = PdfPageOrientation.Landscape;
            page = section.Pages.Add();
            DrawPage(page);

            //Rotate 90
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle90;
            page = section.Pages.Add();
            DrawPage(page);

            //Rotate 180
            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Rotate = PdfPageRotateAngle.RotateAngle180;
            page = section.Pages.Add();
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("PageSetup.pdf");
        }
Beispiel #15
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");
        }
Beispiel #16
0
        private PdfPageBase DrawPages(PdfDocument doc)
        {
            //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;

            //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);
        }
Beispiel #17
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();
            doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;

            //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 section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Fly;
            section.PageSettings.Transition.PageDuration = 1;

            PdfNewPage page = section.Pages.Add();
            page.BackgroundColor = Color.Red;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Green;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Blue;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Box;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;
            section.PageSettings.Transition = new PdfPageTransition();
            section.PageSettings.Transition.Duration = 2;
            section.PageSettings.Transition.Style = PdfTransitionStyle.Split;
            section.PageSettings.Transition.Dimension = PdfTransitionDimension.Vertical;
            section.PageSettings.Transition.Motion = PdfTransitionMotion.Inward;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Transition.pdf");
        }
Beispiel #18
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");
        }
Beispiel #19
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;

            PdfSection section = doc.Sections.Add();
            section.PageSettings.Margins = margin;
            section.PageSettings.Size = PdfPageSize.A4;

            // Create one page
            PdfPageBase page = section.Pages.Add();
            float y = 10;

            PdfBrush brush1 = PdfBrushes.Black;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true);
            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);

            //draw Codabar
            PdfTextWidget text = new PdfTextWidget();
            text.Font = font1;
            text.Text = "Codabar:";
            PdfLayoutResult result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
            barcode1.BarcodeToTextGapHeight = 1f;
            barcode1.EnableCheckDigit = true;
            barcode1.ShowCheckDigit = true;
            barcode1.TextDisplayLocation = TextLocation.Bottom;
            barcode1.TextColor = Color.Blue;
            barcode1.Draw(page, new PointF(0, y));
            y = barcode1.Bounds.Bottom + 5;


            //draw Code11Barcode
            text.Text = "Code11:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
            barcode2.BarcodeToTextGapHeight = 1f;
            barcode2.TextDisplayLocation = TextLocation.Bottom;
            barcode2.TextColor = Color.Blue;
            barcode2.Draw(page, new PointF(0, y));
            y = barcode2.Bounds.Bottom + 5;


            //draw Code128-A
            text.Text = "Code128-A:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode128ABarcode barcode3 = new PdfCode128ABarcode("HELLO 00-123");
            barcode3.BarcodeToTextGapHeight = 1f;
            barcode3.TextDisplayLocation = TextLocation.Bottom;
            barcode3.TextColor = Color.Blue;
            barcode3.Draw(page, new PointF(0, y));
            y = barcode3.Bounds.Bottom + 5;


            //draw Code128-B
            text.Text = "Code128-B:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode128BBarcode barcode4 = new PdfCode128BBarcode("Hello 00-123");
            barcode4.BarcodeToTextGapHeight = 1f;
            barcode4.TextDisplayLocation = TextLocation.Bottom;
            barcode4.TextColor = Color.Blue;
            barcode4.Draw(page, new PointF(0, y));
            y = barcode4.Bounds.Bottom + 5;


            //draw Code32
            text.Text = "Code32:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode32Barcode barcode5 = new PdfCode32Barcode("16273849");
            barcode5.BarcodeToTextGapHeight = 1f;
            barcode5.TextDisplayLocation = TextLocation.Bottom;
            barcode5.TextColor = Color.Blue;
            barcode5.Draw(page, new PointF(0, y));
            y = barcode5.Bounds.Bottom + 5;

            page = section.Pages.Add();
            y = 10;


            //draw Code39
            text.Text = "Code39:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode39Barcode barcode6 = new PdfCode39Barcode("16-273849");
            barcode6.BarcodeToTextGapHeight = 1f;
            barcode6.TextDisplayLocation = TextLocation.Bottom;
            barcode6.TextColor = Color.Blue;
            barcode6.Draw(page, new PointF(0, y));
            y = barcode6.Bounds.Bottom + 5;


            //draw Code39-E
            text.Text = "Code39-E:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode39ExtendedBarcode barcode7 = new PdfCode39ExtendedBarcode("16-273849");
            barcode7.BarcodeToTextGapHeight = 1f;
            barcode7.TextDisplayLocation = TextLocation.Bottom;
            barcode7.TextColor = Color.Blue;
            barcode7.Draw(page, new PointF(0, y));
            y = barcode7.Bounds.Bottom + 5;


            //draw Code93
            text.Text = "Code93:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode93Barcode barcode8 = new PdfCode93Barcode("16-273849");
            barcode8.BarcodeToTextGapHeight = 1f;
            barcode8.TextDisplayLocation = TextLocation.Bottom;
            barcode8.TextColor = Color.Blue;
            barcode8.QuietZone.Bottom = 5;
            barcode8.Draw(page, new PointF(0, y));
            y = barcode8.Bounds.Bottom + 5;


            //draw Code93-E
            text.Text = "Code93-E:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode93ExtendedBarcode barcode9 = new PdfCode93ExtendedBarcode("16-273849");
            barcode9.BarcodeToTextGapHeight = 1f;
            barcode9.TextDisplayLocation = TextLocation.Bottom;
            barcode9.TextColor = Color.Blue;
            barcode9.Draw(page, new PointF(0, y));
            y = barcode9.Bounds.Bottom + 5;


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

            //Launching the Pdf file.
            PDFDocumentViewer("Barcode.pdf");
        }
Beispiel #20
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, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);

            float y = 10;
            float x1 = page.Canvas.ClientSize.Width;

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

            String[] data
                = {
                    "VendorName;Address1;City;State;Country",
                    "Cacor Corporation;161 Southfield Rd;Southfield;OH;U.S.A.",
                    "Underwater;50 N 3rd Street;Indianapolis;IN;U.S.A.",
                    "J.W.  Luscher Mfg.;65 Addams Street;Berkely;MA;U.S.A.",
                    "Scuba Professionals;3105 East Brace;Rancho Dominguez;CA;U.S.A.",
                    "Divers'  Supply Shop;5208 University Dr;Macon;GA;U.S.A.",
                    "Techniques;52 Dolphin Drive;Redwood City;CA;U.S.A.",
                    "Perry Scuba;3443 James Ave;Hapeville;GA;U.S.A.",
                    "Beauchat, Inc.;45900 SW 2nd Ave;Ft Lauderdale;FL;U.S.A.",
                    "Amor Aqua;42 West 29th Street;New York;NY;U.S.A.",
                    "Aqua Research Corp.;P.O. Box 998;Cornish;NH;U.S.A.",
                    "B&K Undersea Photo;116 W 7th Street;New York;NY;U.S.A.",
                    "Diving International Unlimited;1148 David Drive;San Diego;DA;U.S.A.",
                    "Nautical Compressors;65 NW 167 Street;Miami;FL;U.S.A.",
                    "Glen Specialties, Inc.;17663 Campbell Lane;Huntington Beach;CA;U.S.A.",
                    "Dive Time;20 Miramar Ave;Long Beach;CA;U.S.A.",
                    "Undersea Systems, Inc.;18112 Gotham Street;Huntington Beach;CA;U.S.A.",
                    "Felix Diving;310 S Michigan Ave;Chicago;IL;U.S.A.",
                    "Central Valley Skin Divers;160 Jameston Ave;Jamaica;NY;U.S.A.",
                    "Parkway Dive Shop;241 Kelly Street;South Amboy;NJ;U.S.A.",
                    "Marine Camera & Dive;117 South Valley Rd;San Diego;CA;U.S.A.",
                    "Dive Canada;275 W Ninth Ave;Vancouver;British Columbia;Canada",
                    "Dive & Surf;P.O. Box 20210;Indianapolis;IN;U.S.A.",
                    "Fish Research Labs;29 Wilkins Rd Dept. SD;Los Banos;CA;U.S.A."
                };
            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

            String[] header = data[0].Split(';');
            grid.Columns.Add(header.Length);
            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            headerRow.Style.BackgroundBrush
                = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), Color.Red, Color.Blue);
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (i == 0)
                {
                    headerRow.Cells[i].Style.BackgroundBrush = PdfBrushes.Gray;
                }
            }

            Random random = new Random();
            Dictionary<String, int> groupByCountry = new Dictionary<String, int>();
            for (int r = 1; r < data.Length; r++)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                byte[] buffer = new byte[6];
                random.NextBytes(buffer);
                PdfRGBColor color1 = new PdfRGBColor(buffer[0], buffer[1], buffer[2]);
                PdfRGBColor color2 = new PdfRGBColor(buffer[3], buffer[4], buffer[5]);
                row.Style.BackgroundBrush
                    = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), color1, color2);
                String[] rowData = data[r].Split(';');
                for (int c = 0; c < rowData.Length; c++)
                {
                    row.Cells[c].Value = rowData[c];
                    if (c == 0)
                    {
                        row.Cells[c].Style.BackgroundBrush = PdfBrushes.Gray;
                    }
                    if(c < 3)
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    if (c == 4)
                    {
                        if (groupByCountry.ContainsKey(rowData[c]))
                        {
                            groupByCountry[rowData[c]] = groupByCountry[rowData[c]] + 1;
                        }
                        else
                        {
                            groupByCountry[rowData[c]] = 1;
                        }
                    }
                }
            }
            StringBuilder totalAmount = new StringBuilder();
            foreach (KeyValuePair<String, int> country in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", country.Key, country.Value);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            //append product list
            PdfGrid productList = new PdfGrid();
            productList.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f), 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 p.Description "
                    + " from vendors v "
                    + "     inner join parts p "
                    + "     on v.VendorNo = p.VendorNo "
                    + " where v.VendorName = 'Cacor Corporation'";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    productList.DataSource = dataTable;
                }
            }
            productList.Headers[0].Cells[0].Value = "Cacor Corporation";
            productList.Headers[0].Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
            productList.Headers[0].Cells[0].Style.Borders.All = new PdfPen(new PdfTilingBrush(new SizeF(1, 1)), 0);
            grid.Rows[0].Cells[0].Value = productList;
            grid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Left;

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

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

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

            //Launching the Pdf file.
            PDFDocumentViewer("Grid.pdf");
        }
Beispiel #21
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;
            float x = 0;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12));
            String label = "Simple Link: ";
            PdfStringFormat format = new PdfStringFormat();
            format.MeasureTrailingSpaces = true;
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12, FontStyle.Underline));
            String url1 = "http://www.e-iceblue.com";
            page.Canvas.DrawString(url1, font1, PdfBrushes.Blue, x, y);
            y = y + font1.MeasureString(url1).Height;

            label = "Web Link: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            String text = "e-iceblue";
            PdfTextWebLink link2 = new PdfTextWebLink();
            link2.Text = text;
            link2.Url = url1;
            link2.Font = font1;
            link2.Brush = PdfBrushes.Blue;
            link2.DrawTextWebLink(page.Canvas, new PointF(x, y));
            y = y + font1.MeasureString(text).Height;

            label = "URI Annonationa: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "Google";
            PointF location = new PointF(x, y);
            SizeF size = font1.MeasureString(text);
            RectangleF linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link3 = new PdfUriAnnotation(linkBounds);
            link3.Border = new PdfAnnotationBorder(0);
            link3.Uri = "http://www.google.com";
            (page as PdfNewPage).Annotations.Add(link3);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

            label = "URI Annonationa Action: ";
            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, 0, y, format);
            x = font.MeasureString(label, format).Width;
            text = "JavaScript Action (Click Me)";
            location = new PointF(x, y);
            size = font1.MeasureString(text);
            linkBounds = new RectangleF(location, size);
            PdfUriAnnotation link4 = new PdfUriAnnotation(linkBounds);
            link4.Border = new PdfAnnotationBorder(0.75f);
            link4.Color = Color.LightGray;
            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Hello.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action = new PdfJavaScriptAction(script);
            link4.Action = action;
            (page as PdfNewPage).Annotations.Add(link4);
            page.Canvas.DrawString(text, font1, PdfBrushes.Blue, x, y);
            y = y + size.Height;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Link.pdf");
        }
Beispiel #22
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 section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            // Create one page
            PdfPageBase page = section.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("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Attachment", format1).Height;
            y = y + 5;

            //attachment
            PdfAttachment attachment = new PdfAttachment("Header.png");
            attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Header.png");
            attachment.Description = "Page header picture of demo.";
            attachment.MimeType = "image/png";
            doc.Attachments.Add(attachment);

            attachment = new PdfAttachment("Footer.png");
            attachment.Data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Footer.png");
            attachment.Description = "Page footer picture of demo.";
            attachment.MimeType = "image/png";
            doc.Attachments.Add(attachment);

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            PointF location = new PointF(0, y);
            String label = "Sales Report Chart";
            byte[] data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SalesReportChart.png");
            SizeF size = font2.MeasureString(label);
            RectangleF bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation1
                = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data);
            annotation1.Color = Color.Teal;
            annotation1.Flags = PdfAnnotationFlags.ReadOnly;
            annotation1.Icon = PdfAttachmentIcon.Graph;
            annotation1.Text = "Sales Report Chart";
            (page as PdfNewPage).Annotations.Add(annotation1);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Science Personification Boston";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation2
                = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data);
            annotation2.Color = Color.Orange;
            annotation2.Flags = PdfAnnotationFlags.NoZoom;
            annotation2.Icon = PdfAttachmentIcon.PushPin;
            annotation2.Text = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation2);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Picture of Science";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Wikipedia_Science.png");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation3
                = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data);
            annotation3.Color = Color.SaddleBrown;
            annotation3.Flags = PdfAnnotationFlags.Locked;
            annotation3.Icon = PdfAttachmentIcon.Tag;
            annotation3.Text = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation3);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label = "Hawaii Killer Font";
            data = File.ReadAllBytes(@"..\..\..\..\..\..\Data\Hawaii_Killer.ttf");
            size = font2.MeasureString(label);
            bounds = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation4
                = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data);
            annotation4.Color = Color.CadetBlue;
            annotation4.Flags = PdfAnnotationFlags.NoRotate;
            annotation4.Icon = PdfAttachmentIcon.Paperclip;
            annotation4.Text = "Hawaii Killer Font, from http://www.1001freefonts.com";
            (page as PdfNewPage).Annotations.Add(annotation4);
            y = y + size.Height + 2;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Attachment.pdf");
        }
Beispiel #23
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 + 2;

            //table top
            PdfDestination tableTopDest = new PdfDestination(page);
            tableTopDest.Location = new PointF(0, y);
            tableTopDest.Mode = PdfDestinationMode.Location;
            tableTopDest.Zoom = 1f;

            //Draw table            
            PdfTrueTypeFont buttonFont = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            float buttonWidth = 70;
            float buttonHeight = buttonFont.Height * 1.5f;
            float tableTop = y;
            PdfLayoutResult tableLayoutResult = DrawTable(page, y + buttonHeight + 5);

            //table bottom
            PdfDestination tableBottomDest = new PdfDestination(tableLayoutResult.Page);
            tableBottomDest.Location = new PointF(0, tableLayoutResult.Bounds.Bottom);
            tableBottomDest.Mode = PdfDestinationMode.Location;
            tableBottomDest.Zoom = 1f;

            //go to table bottom
            float x = page.Canvas.ClientSize.Width - buttonWidth;
            PdfStringFormat format2 = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
            RectangleF buttonBounds = new RectangleF(x, tableTop, buttonWidth, buttonHeight);
            page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            page.Canvas.DrawString("To Bottom", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action1 = new PdfGoToAction(tableBottomDest);
            PdfActionAnnotation annotation1
                = new PdfActionAnnotation(buttonBounds, action1);
            annotation1.Border = new PdfAnnotationBorder(0.75f);
            annotation1.Color = Color.LightGray;
            (page as PdfNewPage).Annotations.Add(annotation1);

            //go to table top
            float tableBottom = tableLayoutResult.Bounds.Bottom + 5;
            buttonBounds = new RectangleF(x, tableBottom, buttonWidth, buttonHeight);
            tableLayoutResult.Page.Canvas.DrawRectangle(PdfBrushes.DarkGray, buttonBounds);
            tableLayoutResult.Page.Canvas.DrawString("To Top", buttonFont, PdfBrushes.CadetBlue, buttonBounds, format2);
            PdfGoToAction action2 = new PdfGoToAction(tableTopDest);
            PdfActionAnnotation annotation2
                = new PdfActionAnnotation(buttonBounds, action2);
            annotation2.Border = new PdfAnnotationBorder(0.75f);
            annotation2.Color = Color.LightGray;
            (tableLayoutResult.Page as PdfNewPage).Annotations.Add(annotation2);

            //goto last page
            PdfNamedAction action3 = new PdfNamedAction(PdfActionDestination.LastPage);
            doc.AfterOpenAction = action3;

            //script
            String script
                = "app.alert({"
                + "    cMsg: \"Oh no, you want to leave me.\","
                + "    nIcon: 3,"
                + "    cTitle: \"JavaScript Action\""
                + "});";
            PdfJavaScriptAction action4 = new PdfJavaScriptAction(script);
            doc.BeforeCloseAction = action4;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Action.pdf");
        }
Beispiel #24
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");
        }
Beispiel #25
0
        private void DrawContent(PdfSection section, PdfMargins margin)
        {
            section.PageNumber = new PdfPageNumber();
            section.PageNumber.NumberStyle = PdfNumberStyle.Numeric;
            section.PageNumber.Prefix = "page ";
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins.All = 0;
            PdfPageBase page = section.Pages.Add();
            DrawPageHeaderAndFooter(page, margin, false);

            float x = margin.Left;
            float y = margin.Top + 8;
            float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f), true);
            PdfBrush brush1 = PdfBrushes.Black;
            PdfPen pen1 = new PdfPen(brush1, 0.75f);
            page.Canvas.DrawString(Pagination.Properties.Resources.Title, font1, brush1, x, y);
            y = y + font1.MeasureString(Pagination.Properties.Resources.Title).Height + 6;
            page.Canvas.DrawLine(pen1, x, y, page.Canvas.ClientSize.Width - margin.Right, y);
            y = y + 1.75f;

            String content = Pagination.Properties.Resources.Content;
            String[] lines
                = content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Italic), true);
            PdfStringFormat format1 = new PdfStringFormat();
            format1.MeasureTrailingSpaces = true;
            format1.LineSpacing = font2.Height * 1.5f;
            format1.ParagraphIndent = font2.MeasureString("\t", format1).Width;
            y = y + font2.Height * 0.5f;
            SizeF size = font2.MeasureString(lines[0], width, format1);
            page.Canvas.DrawString(lines[0], font2, brush1,
                new RectangleF(new PointF(x, y), size), format1);
            y = y + size.Height;

            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            PdfStringFormat format2 = new PdfStringFormat();
            format2.LineSpacing = font3.Height * 1.4f;
            format2.MeasureTrailingSpaces = true;
            size = font3.MeasureString(lines[1], width, format2);
            page.Canvas.DrawString(lines[1], font3, brush1,
                new RectangleF(new PointF(x, y), size), format2);
            y = y + size.Height;

            y = y + font3.Height * 0.75f;
            float indent = font3.MeasureString("\t\t", format2).Width;
            float x1 = x + indent;
            size = font3.MeasureString(lines[2], width - indent, format2);
            page.Canvas.DrawString(lines[2], font3, brush1,
                new RectangleF(new PointF(x1, y), size), format2);
            y = y + size.Height + font3.Height * 0.75f;

            StringBuilder buff = new StringBuilder();
            for (int i = 3; i < lines.Length; i++)
            {
                buff.AppendLine(lines[i]);
            }
            content = buff.ToString();

            PdfStringLayouter textLayouter = new PdfStringLayouter();
            PdfStringLayoutResult result
                = textLayouter.Layout(content, font3, format2, new SizeF(width, float.MaxValue));
            foreach (LineInfo line in result.Lines)
            {
                if ((line.LineType & LineType.FirstParagraphLine) == LineType.FirstParagraphLine)
                {
                    y = y + font3.Height * 0.75f;
                }
                if (y > (page.Canvas.ClientSize.Height - margin.Bottom - result.LineHeight))
                {
                    page = section.Pages.Add();
                    DrawPageHeaderAndFooter(page, margin, false);
                    y = margin.Top;
                }
                page.Canvas.DrawString(line.Text, font3, brush1, x, y, format2);
                y = y + result.LineHeight;
            }
        }
        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 ApS";
            doc.DocumentInformation.Title        = String.Format("Bogføringsbilag {0}", regnskabsnavn);
            doc.DocumentInformation.Creator      = "Trans2SummaHDA";
            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();
        }
Beispiel #27
0
        public void BankUdbetalingsUdskrifter(dbData3060DataContext 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.tblMedlems
                         join h in p_dbData3060.tbloverforsels 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();
            }
        }
Beispiel #28
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            //Create PdfUnitConvertor to convert the unit
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();

            //Setting for page margin
            PdfMargins margin = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(2.0f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            //Add the first page
            PdfPageBase page1 = doc.Pages.Add(PdfPageSize.A4, margin);

            //Define a PdfBrush
            PdfBrush brush1 = PdfBrushes.Black;

            //Define a font
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold), true);

            //Set the string format
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);

            //Set the position for drawing
            float x = 0;
            float y = 50;

            //Text string
            string specification = "The sample demonstrates how to create a local document link in PDF document.";

            //Draw text string on first page
            page1.Canvas.DrawString(specification, font1, brush1, x, y, format1);

            //Use MeasureString to get the height of string
            y = y + font1.MeasureString(specification, format1).Height + 10;

            //Add the second page
            PdfPageBase page2 = doc.Pages.Add(PdfPageSize.A4, margin);

            //String text
            string PageContent = "This is the second page!";

            //Draw text string on second page
            page2.Canvas.DrawString(PageContent, font1, brush1, x, y, format1);

            //Add DocumentLinkAnnotation on the first page and link to the second page
            AddDocumentLinkAnnotation(doc, 0, 1, y);


            String result = "DocumentLinkAnnotation_out.pdf";

            //Save the document
            doc.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Beispiel #29
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;
        }
Beispiel #30
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");
        }
Beispiel #31
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");
        }
Beispiel #32
0
        private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
        {
            PdfPageTemplateElement leftSpace
                = new PdfPageTemplateElement(margin.Left, pageSize.Height);
            doc.Template.Left = leftSpace;

            PdfPageTemplateElement topSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Top);
            topSpace.Foreground = true;
            doc.Template.Top = topSpace;

            //draw header label
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
            String label = "Demo of Spire.Pdf";
            SizeF size = font.MeasureString(label, format);
            float y = topSpace.Height - font.Height - 1;
            PdfPen pen = new PdfPen(Color.Black, 0.75f);
            topSpace.Graphics.SetTransparency(0.5f);
            topSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y);
            y = y - 1 - size.Height;
            topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format);

            PdfPageTemplateElement rightSpace
                = new PdfPageTemplateElement(margin.Right, pageSize.Height);
            doc.Template.Right = rightSpace;

            PdfPageTemplateElement bottomSpace
                = new PdfPageTemplateElement(pageSize.Width, margin.Bottom);
            bottomSpace.Foreground = true;
            doc.Template.Bottom = bottomSpace;

            //draw footer label
            y = font.Height + 1;
            bottomSpace.Graphics.SetTransparency(0.5f);
            bottomSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y);
            y = y + 1;
            PdfPageNumberField pageNumber = new PdfPageNumberField();
            PdfPageCountField pageCount = new PdfPageCountField();
            PdfCompositeField pageNumberLabel = new PdfCompositeField();
            pageNumberLabel.AutomaticFields
                = new PdfAutomaticField[] { pageNumber, pageCount };
            pageNumberLabel.Brush = PdfBrushes.Black;
            pageNumberLabel.Font = font;
            pageNumberLabel.StringFormat = format;
            pageNumberLabel.Text = "page {0} of {1}";
            pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - margin.Right, y);

            PdfImage headerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png");
            PointF pageLeftTop = new PointF(-margin.Left, -margin.Top);
            PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension);
            header.Foreground = false;
            header.Graphics.SetTransparency(0.5f);
            header.Graphics.DrawImage(headerImage, 0, 0);
            doc.Template.Stamps.Add(header);

            PdfImage footerImage
                = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png");
            y = pageSize.Height - footerImage.PhysicalDimension.Height;
            PointF footerLocation = new PointF(-margin.Left, y);
            PdfPageTemplateElement footer = new PdfPageTemplateElement(footerLocation, footerImage.PhysicalDimension);
            footer.Foreground = false;
            footer.Graphics.SetTransparency(0.5f);
            footer.Graphics.DrawImage(footerImage, 0, 0);
            doc.Template.Stamps.Add(footer);
        }
Beispiel #33
0
 private void DrawPageNumber(PdfSection section, PdfMargins margin, int startNumber, int pageCount)
 {
     foreach (PdfPageBase page in section.Pages)
     {
         page.Canvas.SetTransparency(0.5f);
         PdfBrush brush = PdfBrushes.Black;
         PdfPen pen = new PdfPen(brush, 0.75f);
         PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic), true);
         PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right);
         format.MeasureTrailingSpaces = true;
         float space = font.Height * 0.75f;
         float x = margin.Left;
         float width = page.Canvas.ClientSize.Width - margin.Left - margin.Right;
         float y = page.Canvas.ClientSize.Height - margin.Bottom + space;
         page.Canvas.DrawLine(pen, x, y, x + width, y);
         y = y + 1;
         String numberLabel
             = String.Format("{0} of {1}", startNumber++, pageCount);
         page.Canvas.DrawString(numberLabel, font, brush, x + width, y, format);
         page.Canvas.SetTransparency(1);
     }
 }
Beispiel #34
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), true);
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);
            page.Canvas.DrawString("Categories List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Categories List", format1).Height;
            y = y + 5;

            RectangleF rctg = new RectangleF(new PointF(0, 0), page.Canvas.ClientSize);
            PdfLinearGradientBrush brush2
                = new PdfLinearGradientBrush(rctg, Color.Navy, Color.OrangeRed, PdfLinearGradientMode.Vertical);
            PdfLinearGradientBrush brush3
                = new PdfLinearGradientBrush(rctg, Color.OrangeRed, Color.Navy, PdfLinearGradientMode.Vertical);
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f), true);
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 8f), true);

            PdfOrderedMarker marker1
                = new PdfOrderedMarker(PdfNumberStyle.LowerRoman, new PdfFont(PdfFontFamily.Helvetica, 10f));
            PdfOrderedMarker marker2
                = new PdfOrderedMarker(PdfNumberStyle.Numeric, new PdfFont(PdfFontFamily.Helvetica, 8f));

            PdfSortedList vendorList = new PdfSortedList(font2);
            vendorList.Indent = 0;
            vendorList.TextIndent = 5;
            vendorList.Brush = brush2;
            vendorList.Marker = marker1;
            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 VendorNo, VendorName from vendors ";
                command.Connection = conn;

                OleDbCommand command2 = new OleDbCommand();
                command2.CommandText
                    = " select Description from parts where VendorNo = @VendorNo";
                command2.Connection = conn;
                OleDbParameter param = new OleDbParameter("@VendorNo", OleDbType.Double);
                command2.Parameters.Add(param);

                conn.Open();

                OleDbDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    double id = reader.GetDouble(0);
                    PdfListItem item = vendorList.Items.Add(reader.GetString(1));
                    PdfSortedList subList = new PdfSortedList(font3);
                    subList.Marker = marker2;
                    subList.Brush = brush3;
                    item.SubList = subList;
                    subList.TextIndent = 20;
                    command2.Parameters[0].Value = id;
                    using (OleDbDataReader reader2 = command2.ExecuteReader())
                    {
                        while (reader2.Read())
                        {
                            subList.Items.Add(reader2.GetString(0));
                        }
                    }
                    String maxNumberLabel = Convert.ToString(subList.Items.Count);
                    subList.Indent = 30 - font3.MeasureString(maxNumberLabel).Width;
                }
            }

            PdfTextLayout textLayout = new PdfTextLayout();
            textLayout.Break = PdfLayoutBreakType.FitPage;
            textLayout.Layout = PdfLayoutType.Paginate;
            vendorList.Draw(page, new PointF(0, y), textLayout);

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

            //Launching the Pdf file.
            PDFDocumentViewer("List.pdf");
        }
        private void crearFacturaPDF(String title)
        {
            //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 = 40;
            float infoMargin = 120;

            Cliente c = findCliente(fac_cliente.Text);
            //Encabezado
            PdfBrush brush1 = PdfBrushes.BlueViolet;
            PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Calibri", 11f)); ;
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Left);
            page.Canvas.DrawString(c.cl_nombre, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(c.cl_ruc, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(c.cl_direccion, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 5;
            page.Canvas.DrawString(fac_fecha.Text, font1, brush1, infoMargin, y, format1);
            y = y + font1.MeasureString(title, format1).Height + 30;

            //Productos
            PdfBrush brush2 = PdfBrushes.Green;
            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f));
            float x = 30;
            float totalX = page.Canvas.ClientSize.Width - 2 * x;
            foreach (FacturaItem fi in _FacturaItemsCollection)
            {

                page.Canvas.DrawString(fi.fi_codigo, font2, brush2, x, y, format1);
                x = x + 0.15f * totalX;
                page.Canvas.DrawString(fi.fi_nombre, font2, brush2, x, y, format1);
                x = x + 0.55f * totalX;
                page.Canvas.DrawString(fi.fi_cantidad.ToString("n2"), font2, brush2, x, y, format1);
                x = x + 0.15f * totalX;
                page.Canvas.DrawString(fi.fi_importe.ToString("n2"), font2, brush2, x, y, format1);
                y = y + font2.MeasureString(fi.fi_nombre, format1).Height + 5;
                x = 30;
            }

            //Tail
            y = page.Canvas.ClientSize.Height - 60;
            infoMargin = x + 0.85f * totalX;
            page.Canvas.DrawString(fact_total.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_total.ToString(), format1).Height - 5;
            page.Canvas.DrawString(fact_iva.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_total.ToString(), format1).Height - 5;
            page.Canvas.DrawString(fact_subtotal.ToString("n2"), font1, brush1, infoMargin, y, format1);
            y = y - font1.MeasureString(fact_subtotal.ToString(), format1).Height - 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 = title + ".pdf";
            pdfDoc.SaveToFile(@filename);

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

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

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

            //create section
            PdfSection section = doc.Sections.Add();

            section.PageSettings.Size    = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            // Create one page
            PdfPageBase page = section.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("Attachment", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Attachment", format1).Height;
            y = y + 5;

            //attachment
            PdfAttachment attachment = new PdfAttachment("Header.png");

            attachment.Data        = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Header.png");
            attachment.Description = "Page header picture of demo.";
            attachment.MimeType    = "image/png";
            doc.Attachments.Add(attachment);

            attachment             = new PdfAttachment("Footer.png");
            attachment.Data        = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Footer.png");
            attachment.Description = "Page footer picture of demo.";
            attachment.MimeType    = "image/png";
            doc.Attachments.Add(attachment);

            PdfTrueTypeFont font2    = new PdfTrueTypeFont(new Font("Arial", 12f, FontStyle.Bold));
            PointF          location = new PointF(0, y);
            String          label    = "Sales Report Chart";

            byte[]     data   = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\SalesReportChart.png");
            SizeF      size   = font2.MeasureString(label);
            RectangleF bounds = new RectangleF(location, size);

            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation1
                = new PdfAttachmentAnnotation(bounds, "SalesReportChart.png", data);

            annotation1.Color = Color.Teal;
            annotation1.Flags = PdfAnnotationFlags.ReadOnly;
            annotation1.Icon  = PdfAttachmentIcon.Graph;
            annotation1.Text  = "Sales Report Chart";
            (page as PdfNewPage).Annotations.Add(annotation1);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label    = "Science Personification Boston";
            data     = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\SciencePersonificationBoston.jpg");
            size     = font2.MeasureString(label);
            bounds   = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation2
                = new PdfAttachmentAnnotation(bounds, "SciencePersonificationBoston.jpg", data);

            annotation2.Color = Color.Orange;
            annotation2.Flags = PdfAnnotationFlags.NoZoom;
            annotation2.Icon  = PdfAttachmentIcon.PushPin;
            annotation2.Text  = "SciencePersonificationBoston.jpg, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation2);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label    = "Picture of Science";
            data     = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Wikipedia_Science.png");
            size     = font2.MeasureString(label);
            bounds   = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation3
                = new PdfAttachmentAnnotation(bounds, "Wikipedia_Science.png", data);

            annotation3.Color = Color.SaddleBrown;
            annotation3.Flags = PdfAnnotationFlags.Locked;
            annotation3.Icon  = PdfAttachmentIcon.Tag;
            annotation3.Text  = "Wikipedia_Science.png, from Wikipedia, the free encyclopedia";
            (page as PdfNewPage).Annotations.Add(annotation3);
            y = y + size.Height + 2;

            location = new PointF(0, y);
            label    = "Hawaii Killer Font";
            data     = File.ReadAllBytes(@"..\..\..\..\..\..\..\Data\Hawaii_Killer.ttf");
            size     = font2.MeasureString(label);
            bounds   = new RectangleF(location, size);
            page.Canvas.DrawString(label, font2, PdfBrushes.DarkOrange, bounds);
            bounds = new RectangleF(bounds.Right + 3, bounds.Top, font2.Height / 2, font2.Height);
            PdfAttachmentAnnotation annotation4
                = new PdfAttachmentAnnotation(bounds, "Hawaii_Killer.ttf", data);

            annotation4.Color = Color.CadetBlue;
            annotation4.Flags = PdfAnnotationFlags.NoRotate;
            annotation4.Icon  = PdfAttachmentIcon.Paperclip;
            annotation4.Text  = "Hawaii Killer Font, from http://www.1001freefonts.com";
            (page as PdfNewPage).Annotations.Add(annotation4);
            y = y + size.Height + 2;

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

            //Launching the Pdf file.
            PDFDocumentViewer("Attachment.pdf");
        }
Beispiel #37
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");
        }
Beispiel #38
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

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

            //create section
            PdfSection section = doc.Sections.Add();
            section.PageSettings.Size = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            // Create one page
            PdfPageBase page = section.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("Sales Report", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Sales Report", format1).Height;
            y = y + 5;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));
            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                conn.Open();

                OleDbCommand partQueryCommand = PreparePartQueryCommand(conn);
                OleDbCommand orderItemQueryCommand = PrepareOrderItemQueryCommand(conn);

                DataTable vendors = GetVendors(conn);
                for (int i = 0;  i < vendors.Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        //next page
                        page = section.Pages.Add();
                        y = 0;
                    }
                    //draw vendor
                    String vendorTitle = String.Format("{0}. {1}", i + 1, vendors.Rows[i].ItemArray[1]);
                    PdfLayoutResult drawVendorLayoutResult = DrawVendor(page, vendors, i, vendorTitle, y);

                    //add vendor bookmark
                    PdfDestination vendorBookmarkDest = new PdfDestination(page, new PointF(0, y));
                    PdfBookmark vendorBookmark = doc.Bookmarks.Add(vendorTitle);
                    vendorBookmark.Color = Color.SaddleBrown;
                    vendorBookmark.DisplayStyle = PdfTextStyle.Bold;
                    vendorBookmark.Action = new PdfGoToAction(vendorBookmarkDest);

                    y = drawVendorLayoutResult.Bounds.Bottom + 5;
                    page = drawVendorLayoutResult.Page;

                    //get parts of vendor
                    DataTable parts = GetParts(partQueryCommand, (double)vendors.Rows[i].ItemArray[0]);
                    for (int j = 0; j < parts.Rows.Count; j++)
                    {
                        if (j > 0)
                        {
                            //next page
                            page = section.Pages.Add();
                            y = 0;
                        }
                        //draw part
                        String partTitle = String.Format("{0}.{1}. {2}", i + 1, j + 1, parts.Rows[j].ItemArray[1]);
                        PdfLayoutResult drawPartLayoutResult = DrawPart(page, parts, j, partTitle, y);

                        //add part bookmark
                        PdfDestination partBookmarkDest = new PdfDestination(page, new PointF(0, y));
                        PdfBookmark partBookmark = vendorBookmark.Add(partTitle);
                        partBookmark.Color = Color.Coral;
                        partBookmark.DisplayStyle = PdfTextStyle.Italic;
                        partBookmark.Action = new PdfGoToAction(partBookmarkDest);

                        y = drawPartLayoutResult.Bounds.Bottom + 5;
                        page = drawPartLayoutResult.Page;

                        //get order items
                        String orderItemsTitle = String.Format("{0} - Order Items", parts.Rows[j].ItemArray[1]);
                        DataTable orderItems = GetOrderItems(orderItemQueryCommand, (double)parts.Rows[j].ItemArray[0]);
                        DrawOrderItems(page, orderItems, orderItemsTitle, y);
                    }
                }
            }

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

            //Launching the Pdf file.
            PDFDocumentViewer("Bookmark.pdf");
        }
Beispiel #39
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 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);
        }
Beispiel #41
0
        protected void createPdfButton_Click(object sender, EventArgs e)
        {
            // Get the PDF Standard
            // By default the Full PDF standard is used
            PdfStandardSubset pdfStandard = PdfStandardSubset.Full;

            if (pdfARadioButton.Checked)
            {
                pdfStandard = PdfStandardSubset.Pdf_A_1b;
            }
            else if (pdfXRadioButton.Checked)
            {
                pdfStandard = PdfStandardSubset.Pdf_X_1a;
            }

            // Get the Color Space
            // By default the RGB color space is used
            ColorSpace pdfColorSpace = ColorSpace.RGB;

            if (grayScaleRadioButton.Checked)
            {
                pdfColorSpace = ColorSpace.Gray;
            }
            else if (cmykRadioButton.Checked)
            {
                pdfColorSpace = ColorSpace.CMYK;
            }

            // Create the PDF document
            Document pdfDocument = null;

            // Get the server IP and port
            String serverIP   = textBoxServerIP.Text;
            uint   serverPort = uint.Parse(textBoxServerPort.Text);

            if (pdfStandard == PdfStandardSubset.Full && pdfColorSpace == ColorSpace.RGB)
            {
                // Create a PDF document with default standard and color space
                pdfDocument = new Document(serverIP, serverPort);
            }
            else
            {
                // Create a PDF document with the selected standard and color space
                pdfDocument = new Document(serverIP, serverPort, pdfStandard, pdfColorSpace);
            }

            // Set optional service password
            if (textBoxServicePassword.Text.Length > 0)
            {
                pdfDocument.ServicePassword = textBoxServicePassword.Text;
            }

            // Set license key received after purchase to use the converter in licensed mode
            // Leave it not set to use the converter in demo mode
            pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

            // Get the selected PDF page size
            PdfPageSize pdfPageSize = SelectedPdfPageSize();

            // Get the selected PDF page orientation
            PdfPageOrientation pdfPageOrientation = SelectedPdfPageOrientation();

            // Get the PDF page margins
            PdfMargins pdfPageMargins = new PdfMargins(float.Parse(leftMarginTextBox.Text), float.Parse(rightMarginTextBox.Text),
                                                       float.Parse(topMarginTextBox.Text), float.Parse(bottomMarginTextBox.Text));

            // Create a PDF page in PDF document
            PdfPage firstPdfPage = pdfDocument.AddPage(pdfPageSize, pdfPageMargins, pdfPageOrientation);

            // The URL of the HTML page to convert to PDF
            string urlToConvert = "http://www.evopdf.com";

            // Create the HTML to PDF element
            HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(urlToConvert);

            // Optionally set a delay before conversion to allow asynchonous scripts to finish
            htmlToPdfElement.ConversionDelay = 2;

            // Add the HTML to PDF element to PDF document
            firstPdfPage.AddElement(htmlToPdfElement);

            // Save the PDF document in a memory buffer
            byte[] outPdfBuffer = pdfDocument.Save();

            // Send the PDF as response to browser

            // Set response content type
            Response.AddHeader("Content-Type", "application/pdf");

            // Instruct the browser to open the PDF file as an attachment or inline
            Response.AddHeader("Content-Disposition", String.Format("attachment; filename=Create_PDF_Documents.pdf; size={0}", outPdfBuffer.Length.ToString()));

            // Write the PDF document buffer to HTTP response
            Response.BinaryWrite(outPdfBuffer);

            // End the HTTP response and stop the current page processing
            Response.End();
        }
        private void buttonRun_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFiledialog = new SaveFileDialog();
            saveFiledialog.Filter = "PDF Document (*.pdf)|*.pdf";
            bool? result = saveFiledialog.ShowDialog();
            if (!result.HasValue || !result.Value)
            {
                return;
            }

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

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

            //create one page
            PdfPageBase page
                = document.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0,
                PdfPageOrientation.Landscape);
            float y = 0;

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

            PdfGrid grid = new PdfGrid();
            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);
            grid.Columns.Add(this.dataGridVendorList.Columns.Count);

            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);
            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;

            //header of grid
            PdfGridRow headerRow = grid.Headers.Add(1)[0];
            headerRow.Style.Font
                = new PdfInternalFont(new Font("Arial", 11f, System.Drawing.FontStyle.Bold), true);
            String[] header = { "Vendor Name", "Address", "City", "State", "Country" };
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);

            }
            headerRow.Style.BackgroundBrush = PdfBrushes.SeaGreen;

            //datarow of grid
            int rowIndex = 1;
            foreach (Vendor vendor in this.dataSource)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfInternalFont(new Font("Arial", 10f), true);
                row.Cells[0].Value = vendor.VendorName;
                row.Cells[1].Value = vendor.Address;
                row.Cells[2].Value = vendor.City;
                row.Cells[3].Value = vendor.State;
                row.Cells[4].Value = vendor.Country;

                row.Cells[0].Style.BackgroundBrush = PdfBrushes.LightGray;
                row.Cells[0].StringFormat = row.Cells[1].StringFormat = row.Cells[2].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                row.Cells[3].StringFormat = row.Cells[4].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (rowIndex % 2 == 0)
                {
                    row.Style.BackgroundBrush = PdfBrushes.YellowGreen;
                }
                else
                {
                    row.Style.BackgroundBrush = PdfBrushes.Bisque;
                }
                rowIndex++;
            }

            StringBuilder totalAmount = new StringBuilder();

            var groupByCountry
                = this.dataSource.GroupBy(v => v.Country)
                    .Select(g => new { Name = g.Key, Count = g.Count() });

            foreach (var item in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", item.Name, item.Count);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();
            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value = "Total Amount";
            totalAmountRow.Cells[0].Style.Font
                = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan = 4;
            totalAmountRow.Cells[1].Value = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font
                = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat
                = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

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

            PdfBrush brush2 = PdfBrushes.Gray;
            PdfTrueTypeFont font2 = new PdfInternalFont(new Font("Arial", 9f));
            resultl.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                font2, brush2, 5, y);

            //Save pdf file.
            using (Stream stream = saveFiledialog.OpenFile())
            {
                document.SaveToStream(stream);
            }
            document.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document
            PdfDocument doc = new PdfDocument();

            doc.ViewerPreferences.PageMode = PdfPageMode.FullScreen;

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

            //Create one section
            PdfSection section = doc.Sections.Add();

            section.PageSettings.Size                    = PdfPageSize.A4;
            section.PageSettings.Margins                 = margin;
            section.PageSettings.Transition              = new PdfPageTransition();
            section.PageSettings.Transition.Duration     = 2;
            section.PageSettings.Transition.Style        = PdfTransitionStyle.Fly;
            section.PageSettings.Transition.PageDuration = 1;

            PdfNewPage page = section.Pages.Add();

            page.BackgroundColor = Color.Red;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Green;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Blue;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size                    = PdfPageSize.A4;
            section.PageSettings.Margins                 = margin;
            section.PageSettings.Transition              = new PdfPageTransition();
            section.PageSettings.Transition.Duration     = 2;
            section.PageSettings.Transition.Style        = PdfTransitionStyle.Box;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

            section = doc.Sections.Add();
            section.PageSettings.Size                    = PdfPageSize.A4;
            section.PageSettings.Margins                 = margin;
            section.PageSettings.Transition              = new PdfPageTransition();
            section.PageSettings.Transition.Duration     = 2;
            section.PageSettings.Transition.Style        = PdfTransitionStyle.Split;
            section.PageSettings.Transition.Dimension    = PdfTransitionDimension.Vertical;
            section.PageSettings.Transition.Motion       = PdfTransitionMotion.Inward;
            section.PageSettings.Transition.PageDuration = 1;

            page = section.Pages.Add();
            page.BackgroundColor = Color.Orange;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Brown;
            DrawPage(page);

            page = section.Pages.Add();
            page.BackgroundColor = Color.Navy;
            DrawPage(page);

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

            //Launch the Pdf file
            PDFDocumentViewer("Transition.pdf");
        }
Beispiel #44
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, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape);

            float y  = 10;
            float x1 = page.Canvas.ClientSize.Width;

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

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

            String[] data
                =
                {
                "VendorName;Address1;City;State;Country",
                "Cacor Corporation;161 Southfield Rd;Southfield;OH;U.S.A.",
                "Underwater;50 N 3rd Street;Indianapolis;IN;U.S.A.",
                "J.W.  Luscher Mfg.;65 Addams Street;Berkely;MA;U.S.A.",
                "Scuba Professionals;3105 East Brace;Rancho Dominguez;CA;U.S.A.",
                "Divers'  Supply Shop;5208 University Dr;Macon;GA;U.S.A.",
                "Techniques;52 Dolphin Drive;Redwood City;CA;U.S.A.",
                "Perry Scuba;3443 James Ave;Hapeville;GA;U.S.A.",
                "Beauchat, Inc.;45900 SW 2nd Ave;Ft Lauderdale;FL;U.S.A.",
                "Amor Aqua;42 West 29th Street;New York;NY;U.S.A.",
                "Aqua Research Corp.;P.O. Box 998;Cornish;NH;U.S.A.",
                "B&K Undersea Photo;116 W 7th Street;New York;NY;U.S.A.",
                "Diving International Unlimited;1148 David Drive;San Diego;DA;U.S.A.",
                "Nautical Compressors;65 NW 167 Street;Miami;FL;U.S.A.",
                "Glen Specialties, Inc.;17663 Campbell Lane;Huntington Beach;CA;U.S.A.",
                "Dive Time;20 Miramar Ave;Long Beach;CA;U.S.A.",
                "Undersea Systems, Inc.;18112 Gotham Street;Huntington Beach;CA;U.S.A.",
                "Felix Diving;310 S Michigan Ave;Chicago;IL;U.S.A.",
                "Central Valley Skin Divers;160 Jameston Ave;Jamaica;NY;U.S.A.",
                "Parkway Dive Shop;241 Kelly Street;South Amboy;NJ;U.S.A.",
                "Marine Camera & Dive;117 South Valley Rd;San Diego;CA;U.S.A.",
                "Dive Canada;275 W Ninth Ave;Vancouver;British Columbia;Canada",
                "Dive & Surf;P.O. Box 20210;Indianapolis;IN;U.S.A.",
                "Fish Research Labs;29 Wilkins Rd Dept. SD;Los Banos;CA;U.S.A."
                };
            PdfGrid grid = new PdfGrid();

            grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1);

            String[] header = data[0].Split(';');
            grid.Columns.Add(header.Length);
            float width
                = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1);

            grid.Columns[0].Width = width * 0.25f;
            grid.Columns[1].Width = width * 0.25f;
            grid.Columns[2].Width = width * 0.25f;
            grid.Columns[3].Width = width * 0.15f;
            grid.Columns[4].Width = width * 0.10f;
            PdfGridRow headerRow = grid.Headers.Add(1)[0];

            headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true);
            headerRow.Style.BackgroundBrush
                = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), Color.Red, Color.Blue);
            for (int i = 0; i < header.Length; i++)
            {
                headerRow.Cells[i].Value = header[i];
                headerRow.Cells[i].StringFormat
                    = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                if (i == 0)
                {
                    headerRow.Cells[i].Style.BackgroundBrush = PdfBrushes.Gray;
                }
            }

            Random random = new Random();
            Dictionary <String, int> groupByCountry = new Dictionary <String, int>();

            for (int r = 1; r < data.Length; r++)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true);
                byte[] buffer = new byte[6];
                random.NextBytes(buffer);
                PdfRGBColor color1 = new PdfRGBColor(buffer[0], buffer[1], buffer[2]);
                PdfRGBColor color2 = new PdfRGBColor(buffer[3], buffer[4], buffer[5]);
                row.Style.BackgroundBrush
                    = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), color1, color2);
                String[] rowData = data[r].Split(';');
                for (int c = 0; c < rowData.Length; c++)
                {
                    row.Cells[c].Value = rowData[c];
                    if (c == 0)
                    {
                        row.Cells[c].Style.BackgroundBrush = PdfBrushes.Gray;
                    }
                    if (c < 3)
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
                    }
                    else
                    {
                        row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle);
                    }
                    if (c == 4)
                    {
                        if (groupByCountry.ContainsKey(rowData[c]))
                        {
                            groupByCountry[rowData[c]] = groupByCountry[rowData[c]] + 1;
                        }
                        else
                        {
                            groupByCountry[rowData[c]] = 1;
                        }
                    }
                }
            }
            StringBuilder totalAmount = new StringBuilder();

            foreach (KeyValuePair <String, int> country in groupByCountry)
            {
                totalAmount.AppendFormat("{0}:\t{1}", country.Key, country.Value);
                totalAmount.AppendLine();
            }

            PdfGridRow totalAmountRow = grid.Rows.Add();

            totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum;
            totalAmountRow.Cells[0].Value        = "Total Amount";
            totalAmountRow.Cells[0].Style.Font   = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true);
            totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle);
            totalAmountRow.Cells[1].ColumnSpan   = 4;
            totalAmountRow.Cells[1].Value        = totalAmount.ToString();
            totalAmountRow.Cells[1].Style.Font   = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true);
            totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle);

            //append product list
            PdfGrid productList = new PdfGrid();

            productList.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f), 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 p.Description "
                      + " from vendors v "
                      + "     inner join parts p "
                      + "     on v.VendorNo = p.VendorNo "
                      + " where v.VendorName = 'Cacor Corporation'";
                command.Connection = conn;
                using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command))
                {
                    DataTable dataTable = new DataTable();
                    dataAdapter.Fill(dataTable);
                    productList.DataSource = dataTable;
                }
            }
            productList.Headers[0].Cells[0].Value             = "Cacor Corporation";
            productList.Headers[0].Cells[0].Style.Font        = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true);
            productList.Headers[0].Cells[0].Style.Borders.All = new PdfPen(new PdfTilingBrush(new SizeF(1, 1)), 0);
            grid.Rows[0].Cells[0].Value = productList;
            grid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Left;

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

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

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

            result.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1),
                                          font2, brush2, 5, y);

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

            //Launching the Pdf file.
            PDFDocumentViewer("Grid.pdf");
        }
Beispiel #45
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");
            }
        }
Beispiel #46
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");
        }
        async private void PrintInvoice_Tapped(object sender, EventArgs e)
        {
            order.PaymentType = 0;
            double finalPayment = Convert.ToDouble(lblFinalPayment.Text);

            if (finalPayment == 0)
            {
                await DisplayAlert("صدور فاکتور", "فاکتور به مبلغ صفر نمیتواتد در سیستم ثبت گردد", "باشه");
            }
            else
            {
                await SandoghcheController._connection.InsertAsync(order);

                await SandoghcheController._connection.InsertAllAsync(order.OrderDetails);

                await SandoghcheController._connection.UpdateWithChildrenAsync(order);

                await UpdateProductsAmount();

                if (Device.RuntimePlatform == Device.iOS)
                {
                    //iOS stuff
                }
                else if (Device.RuntimePlatform == Device.Android)
                {
                    PdfDocument doc = new PdfDocument();
                    doc.PageSettings.Size = new Syncfusion.Drawing.SizeF(300, 800);
                    PdfMargins margins = new PdfMargins();
                    margins.All = 10;
                    doc.PageSettings.Margins = margins;
                    PdfPage page = doc.Pages.Add();

                    PdfGraphics graphics = page.Graphics;

                    //var test = GetType().GetTypeInfo().Assembly.GetManifestResourceNames();
                    Stream  fontStream = typeof(EditPage).GetTypeInfo().Assembly.GetManifestResourceStream("Sandoghche.Images.IRANSans(FaNum).ttf");
                    PdfFont font       = new PdfTrueTypeFont(fontStream, 10);


                    PdfStringFormat format = new PdfStringFormat();
                    format.TextDirection = PdfTextDirection.RightToLeft;
                    format.Alignment     = PdfTextAlignment.Center;

                    PdfStringFormat format2 = new PdfStringFormat();
                    format2.TextDirection = PdfTextDirection.RightToLeft;
                    format2.Alignment     = PdfTextAlignment.Right;

                    PdfStringFormat format3 = new PdfStringFormat();
                    format3.TextDirection = PdfTextDirection.RightToLeft;
                    format3.Alignment     = PdfTextAlignment.Left;


                    graphics.DrawString(lblClient.Text, font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
                    graphics.DrawString("فاکتور فروش", font, PdfBrushes.Black, new RectangleF(0, 20, page.GetClientSize().Width, page.GetClientSize().Height), format);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 40), new PointF(300, 40));
                    graphics.DrawString("تاریخ :" + SandoghcheController.GetPersianDate(Convert.ToDateTime(order.DateCreated)), font, PdfBrushes.Black, new RectangleF(0, 42, page.GetClientSize().Width, page.GetClientSize().Height), format);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 60), new PointF(300, 60));
                    graphics.DrawString("ردیف عنوان                                    تعداد   قیمت واحد   قیمت کل          ", font, PdfBrushes.Black, new RectangleF(0, 60, page.GetClientSize().Width, page.GetClientSize().Height), format);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, 75), new PointF(300, 75));


                    string source = "";
                    int    length = 5;
                    string result = source.PadRight(length).Substring(0, length);


                    int height = 75;
                    foreach (var item in order.OrderDetails)
                    {
                        string rowNumber   = item.RowNumber.ToString().PadLeft(5).Substring(0, 5);
                        string productText = item.ProductText.PadRight(20).Substring(0, 20);
                        string Number      = item.Number.ToString().PadLeft(5).Substring(0, 5);
                        string Price       = item.Price.ToString().PadLeft(12).Substring(0, 12);
                        string TotalPrice  = item.TotalPrice.ToString().PadLeft(12).Substring(0, 12);
                        graphics.DrawString(rowNumber, font, PdfBrushes.Black, 285, height, format2);
                        graphics.DrawString(productText, font, PdfBrushes.Black, 255, height, format2);
                        graphics.DrawString(Number, font, PdfBrushes.Black, 130, height, format2);
                        graphics.DrawString(Price, font, PdfBrushes.Black, 110, height, format2);
                        graphics.DrawString(TotalPrice, font, PdfBrushes.Black, 55, height, format2);
                        height += 15;
                        graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height));
                        productText = "";
                    }
                    graphics.DrawString("مالیات : " + (order.Tax1 + order.Tax2).ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height));
                    height += 15;
                    graphics.DrawString("سرویس : " + order.TotalServiceFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height));
                    height += 15;
                    graphics.DrawString("پیک : " + order.DeliveryFee.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height));
                    height += 15;
                    graphics.DrawString‍("تخفیف : " + order.TotalDiscount.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height));
                    height += 15;
                    graphics.DrawString‍("توضیحات : " + order.Comment, font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(100, height));
                    height += 15;
                    graphics.DrawString("جمع کل : " + order.FinalPayment.ToString(), font, PdfBrushes.Black, new RectangleF(0, height, page.GetClientSize().Width, page.GetClientSize().Height), format3);
                    graphics.DrawLine(new PdfPen(PdfBrushes.Black, .5f), new PointF(0, height), new PointF(300, height));


                    MemoryStream stream = new MemoryStream();

                    doc.Save(stream);
                    byte[] test = stream.ToArray();
                    doc.Close(true);


                    DependencyService.Get <IPrintPdf>().PrintPdf(test, order.OrderId);
                }
                else if (Device.RuntimePlatform == Device.UWP)
                {
                    DependencyService.Get <IPrint>().Print(order, "فاکتور فروش", clientName);
                }

                await setOrderNumber();
                await setReceiptNumber();

                lblTax.Text          = "0";
                lblDiscount.Text     = "0";
                lblService.Text      = "0";
                lblTax.Text          = "0";
                lblFinalPayment.Text = "0";
                lblTotalPrice.Text   = "0";
                lblDelivery.Text     = "0";

                ProductsDataGrid.ItemsSource = null;
                lstProducts.ItemsSource      = null;
                await getCategories();

                order = new Order();
            }
        }