Пример #1
0
        private void button20_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // set up to draw
            string     text = "We all came down to Montreux, by the Lake Geneva shoreline.";
            Font       font = new Font("Tahoma", 12);
            RectangleF rc   = new RectangleF(100, 100, 0, 0);

            // measure text on a single line
            rc.Size = pdf.MeasureString(text, font);
            pdf.DrawString(text, font, Brushes.Black, rc);
            pdf.DrawRectangle(Pens.LightGray, rc);

            // update rectangle for next sample
            rc.Y     = rc.Bottom + 12;
            rc.Width = 120;

            // measure text that wraps
            rc.Size = pdf.MeasureString(text, font, rc.Width);
            pdf.DrawString(text, font, Brushes.Black, rc);
            pdf.DrawRectangle(Pens.LightGray, rc);

            // save the document to a file
            string fileName = tempdir + "measure.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #2
0
        private void button18_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // set up to draw
            Font       font = new Font("Tahoma", 14);
            RectangleF rc   = new RectangleF(100, 100, 150, 28);

            // draw string using default options (left-top alignment, no clipping)
            string text = "This string is being rendered using the default options.";

            pdf.DrawString(text, font, Brushes.Black, rc);
            pdf.DrawRectangle(Pens.Black, rc);

            // create StringFormat to center align and clip
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            sf.FormatFlags  &= ~StringFormatFlags.NoClip;

            // render again using custom options
            rc.Offset(0, rc.Height + 30);
            text = "This string is being rendered using custom options.";
            pdf.DrawString(text, font, Brushes.Black, rc, sf);
            pdf.DrawRectangle(Pens.Black, rc);

            // save the document to a file
            string fileName = tempdir + "string.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #3
0
        private void button12_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();
            Image img = pictureBox3.Image;


            // stretch image to fill the rectangle
            Rectangle rc = new Rectangle(100, 100, 50, 30);

            pdf.DrawImage(img, rc);
            pdf.DrawRectangle(Pens.Black, rc);

            // render in actual size, clipping if necessary
            rc.Offset(rc.Width + 20, 0);
            pdf.DrawImage(img, rc, ContentAlignment.MiddleLeft, ImageSizeModeEnum.Clip);
            pdf.DrawRectangle(Pens.Black, rc);

            // scale the image to fit the rectangle while preserving the aspect ratio
            rc.Offset(rc.Width + 20, 0);
            pdf.DrawImage(img, rc, ContentAlignment.MiddleLeft, ImageSizeModeEnum.Scale);
            pdf.DrawRectangle(Pens.Black, rc);

            // step 3: save the document to a file
            string fileName = tempdir + "images.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #4
0
        private void button21_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // set up to draw
            Font       font = new Font("Tahoma", 12);
            RectangleF rc   = pdf.PageRectangle;

            rc.Inflate(-72, -72);

            // create document with 5 numbered pages
            for (int i = 0; i < 5; i++)
            {
                if (i > 0)
                {
                    pdf.NewPage();
                }
                pdf.DrawString("Page " + i.ToString(), font, Brushes.Black, rc);
                pdf.DrawRectangle(Pens.LightGray, rc);
            }

            // move the last page to the front of the document
            PdfPage last = pdf.Pages[pdf.Pages.Count - 1];

            pdf.Pages.Remove(last);
            pdf.Pages.Insert(0, last);

            // save the document to a file
            string fileName = tempdir + "pages.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #5
0
        private void button14_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create some points
            PointF[] points = new PointF[20];
            Random   rnd    = new Random();

            for (int i = 0; i < points.Length; i++)
            {
                points[i] = new PointF(rnd.Next(100, 500), rnd.Next(100, 200));
            }

            // draw lines
            pdf.DrawLines(Pens.Black, points);

            // show points
            foreach (PointF pt in points)
            {
                pdf.DrawRectangle(Pens.Red, pt.X - 3, pt.Y - 3, 6, 6);
            }

            // save the document to a file
            string fileName = tempdir + "drawlines.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #6
0
        private void button10_Click(object sender, System.EventArgs e)
        {
            // initialize
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create points
            PointF[] pts = new PointF[]
            {
                new PointF(100, 100), new PointF(120, 30),
                new PointF(200, 140), new PointF(230, 20),
            };

            // draw Bezier spline
            pdf.DrawBezier(new Pen(Color.Blue, 4), pts[0], pts[1], pts[2], pts[3]);

            // show points
            pdf.DrawLines(Pens.Gray, pts);
            foreach (PointF pt in pts)
            {
                pdf.DrawRectangle(Pens.Red, pt.X - 2, pt.Y - 2, 4, 4);
            }

            string fileName = tempdir + "bezier.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #7
0
        private void button7_Click(object sender, System.EventArgs e)
        {
            // initialize
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();
            Font font = new Font("Arial", 12);

            // create a 10 page document, make page 5 landscape
            for (int i = 0; i < 10; i++)
            {
                if (i > 0)
                {
                    pdf.NewPage();
                }
                pdf.Landscape = (i == 4);

                RectangleF rc = pdf.PageRectangle;
                rc.Inflate(-72, -72);
                pdf.DrawString("Hello", font, Brushes.Black, rc);
                pdf.DrawRectangle(Pens.Black, rc);
            }

            // save and show
            string fileName = tempdir + "landscape.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #8
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            // step 1: create the C1PdfDocument object
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // step 2: add content to the page
            Font       font = new Font("Arial", 12);
            RectangleF rc   = new RectangleF(72, 72, 100, 50);
            string     text = "Some long string to be rendered into a small rectangle. ";

            text = text + text + text + text + text + text;

            // center align and clip string
            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            //sf.FormatFlags |= StringFormatFlags.NoClip;

            pdf.DrawString(text, font, Brushes.Black, rc, sf);
            pdf.DrawRectangle(Pens.Gray, rc);

            using (Graphics g = this.CreateGraphics())
            {
                g.PageUnit = GraphicsUnit.Point;
                g.DrawString(text, font, Brushes.Black, rc, sf);
                g.DrawRectangle(Pens.Gray, Rectangle.Truncate(rc));
            }

            // step 3: save the document to a file
            string fileName = tempdir + "hello world.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #9
0
        private void button17_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create a rectangle
            RectangleF rc = new RectangleF(100, 100, 200, 150);

            // draw and fill rectangles with round corners
            for (int corner = 10; corner < 100; corner += 20)
            {
                SizeF sz = new SizeF(corner, corner / 2);
                pdf.FillRectangle(Brushes.Beige, rc, sz);
                pdf.DrawRectangle(Pens.Blue, rc, sz);
            }

            // draw a regular rectangle
            pdf.DrawRectangle(Pens.Black, rc);

            // save the document to a file
            string fileName = tempdir + "rect.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #10
0
        private void GdiModel_Load(object sender, EventArgs e)
        {
            //start document
            _c1pdf.Clear();

            //prepare to draw with Gdi-like commands
            int       penWidth = 0;
            int       penRGB   = 0;
            Rectangle rc       = new Rectangle(50, 50, 300, 200);
            string    text     = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font      font     = new Font("Times New Roman", 16, FontStyle.Italic | FontStyle.Underline);

            //start, c1, c2, end1, c3, c4, end
            PointF[] bezierPoints = new PointF[]
            {
                new PointF(110f, 200f), new PointF(120f, 110f), new PointF(135f, 150f),
                new PointF(150f, 200f), new PointF(160f, 250f), new PointF(165f, 200f),
                new PointF(150f, 100f)
            };

            //draw to pdf document
            C1.C1Pdf.C1PdfDocument g = _c1pdf;
            g.FillPie(Brushes.Red, rc, 0, 20f);
            g.FillPie(Brushes.Green, rc, 20f, 30f);
            g.FillPie(Brushes.Blue, rc, 60f, 12f);
            g.FillPie(Brushes.Gold, rc, -80f, -20f);
            for (float sa = 0; sa < 360; sa += 40)
            {
                Color penColor = Color.FromArgb(penRGB, penRGB, penRGB);
                Pen   pen      = new Pen(penColor, penWidth++);
                penRGB = penRGB + 20;
                g.DrawArc(pen, rc, sa, 40f);
            }
            g.DrawRectangle(Pens.Red, rc);
            g.DrawBeziers(Pens.Blue, bezierPoints);
            g.DrawString(text, font, Brushes.Black, rc);

            //save pdf file
            string filename = GetTempFileName(".pdf");

            _c1pdf.Save(filename);

            //display it
            webBrowser1.Navigate(filename);
        }
Пример #11
0
        private void AddPageHeaders(RectangleF rcPage)
        {
            RectangleF rcHdr = rcPage;

            rcHdr.Y      = 10;
            rcHdr.Height = rcPage.Top - 10;
            for (int page = 0; page < _c1pdf.Pages.Count; page++)
            {
                //reopen each page
                _c1pdf.CurrentPage = page;

                //draw letterhead
                string s = string.Format("Page {0} of {1}", page + 1, _c1pdf.Pages.Count);
                _c1pdf.DrawString(s, _fontBody, Brushes.LightGray, rcHdr, _sfRightCenter);
                rcHdr.Inflate(0, -30);
                _c1pdf.DrawRectangle(Pens.LightGray, rcHdr);
                rcHdr.Inflate(0, +30);
            }
        }
Пример #12
0
        private void button5_Click(object sender, System.EventArgs e)
        {
            // create pdf document
            C1.C1Pdf.C1PdfDocument g = new C1.C1Pdf.C1PdfDocument();

            // set up to draw
            Rectangle rc   = new Rectangle(0, 0, 300, 200);
            string    text = "Hello world of .NET Graphics and PDF.\r\nNice to meet you.";
            Font      font = new Font("Times New Roman", 12, FontStyle.Italic | FontStyle.Underline);

            PointF[] bezierpts = new PointF[]
            {
                new PointF(10f, 100f), new PointF(20f, 10f), new PointF(35f, 50f),
                new PointF(50f, 100f), new PointF(60f, 150f), new PointF(65f, 100f),
                new PointF(50f, 50f)
            };

            // draw to pdf document
            int penWidth = 0;
            int penRGB   = 0;

            g.FillPie(Brushes.Red, rc, 0, 20f);
            g.FillPie(Brushes.Green, rc, 20f, 30f);
            g.FillPie(Brushes.Blue, rc, 60f, 12f);
            g.FillPie(Brushes.Gold, rc, -80f, -20f);
            for (float startAngle = 0; startAngle < 360; startAngle += 40)
            {
                Color penColor = Color.FromArgb(penRGB, penRGB, penRGB);
                Pen   pen      = new Pen(penColor, penWidth++);
                penRGB = penRGB + 20;
                g.DrawArc(pen, rc, startAngle, 40f);
            }
            g.DrawRectangle(Pens.Red, rc);
            g.DrawBeziers(Pens.Blue, bezierpts);
            g.DrawString(text, font, Brushes.Black, rc);

            // show it
            string fileName = tempdir + "graphics.pdf";

            g.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #13
0
        private void button19_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // set up to draw
            Font       font = new Font("Tahoma", 14);
            RectangleF rc   = new RectangleF(100, 100, 300, 28);

            // measure RTF text and adjust the rectangle to fit
            string text = @"Short {\b RTF} snippet with some {\b bold} and some {\i italics} in it.";

            rc.Y      = rc.Bottom + 12;
            rc.Height = pdf.MeasureStringRtf(text, font, rc.Width).Height;

            // render RTF snippet
            pdf.DrawStringRtf(text, font, Brushes.Blue, rc);
            pdf.DrawRectangle(Pens.Black, rc);

            // save the document to a file
            string fileName = tempdir + "rtf.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #14
0
        private RectangleF RenderTableRow(Font font, Font hdrFont, RectangleF rcPage, RectangleF rc, DataRow dr)
        {
            _rowCount += 1;
            RectangleF rcCell = rc;

            rcCell.Height = 100;

            // break page if we have to
            if (rcCell.Bottom > rcPage.Bottom)
            {
                _c1pdf.NewPage();
                rc       = RenderTableHeader(hdrFont, rcPage, new string[] { "TextBoxes", "RadioButtons", "CheckBoxes", "ComboBoxes", "ListBoxes" });
                rcCell.Y = rc.Y;
            }


            // render data cells
            Pen pen = new Pen(Brushes.Gray, 0.1f);

            _c1pdf.DrawRectangle(pen, rcCell);
            rcCell.Inflate(-4, 0);
            // Render name
            float nameWidth = (float)(rc.Width * .5);
            float colWidth  = rc.Width / 2;
            float x1        = rc.Location.X + 2;
            float x2        = rc.Location.X + rc.Width / 2;
            float y1        = rc.Location.Y + 2;
            float y2        = rc.Location.Y + 25;

            // Declare possible locations for row controls
            PointF r1c1 = new PointF(rc.Location.X + 2, rc.Location.Y + 2);
            PointF r2c1 = new PointF(rc.Location.X + 2, rc.Location.Y + 30);
            PointF r1c2 = new PointF(rc.Location.X + rc.Width / 2, rc.Location.Y + 2);
            PointF r2c2 = new PointF(rc.Location.X + rc.Width / 2, rc.Location.Y + 32);
            PointF r3c2 = new PointF(rc.Location.X + rc.Width / 2, rc.Location.Y + 62);

            // Render String
            string employeeName = dr["FirstName"].ToString() + " " + dr["LastName"].ToString();

            _c1pdf.DrawString(employeeName, new Font(font.FontFamily, 20, FontStyle.Bold), Brushes.Black, new RectangleF(r1c1, new SizeF(nameWidth, 25)));

            // Render ComboBox
            _c1pdf.DrawString("Reports to:", font, Brushes.Black, new PointF(x1, y1 + 30));
            int reportsTo = string.IsNullOrEmpty(dr["ReportsTo"].ToString()) ? 0 : (int)dr["ReportsTo"];

            RenderComboBox(new string[] { "Nancy Davolio", "Andrew Fuller", "Janet Leverling", "Margaret Peacock", "Steven Buchanan", "Michael Suyama", "Robert King" }, reportsTo, font, new RectangleF(new PointF(x1 + 55, y1 + 29), new SizeF(colWidth - 70, 15)));

            // Render Radiobuttons
            _c1pdf.DrawString("Product Division:", font, Brushes.Black, new PointF(x1, y1 + 50));
            RenderRadioButton(true, "GroupDivision" + _rowCount.ToString(), "One", font, new RectangleF(new PointF(x1 + 80, y1 + 50), new SizeF(colWidth - 85, 15)));
            RenderRadioButton(true, "GroupDivision" + _rowCount.ToString(), "Two", font, new RectangleF(new PointF(x1 + 120, y1 + 50), new SizeF(colWidth - 125, 15)));
            RenderRadioButton(true, "GroupDivision" + _rowCount.ToString(), "Three", font, new RectangleF(new PointF(x1 + 160, y1 + 50), new SizeF(colWidth - 165, 15)));

            // Render Checkbox
            RenderCheckBox(true, " Receives Email Notifications", font, new RectangleF(new PointF(x2 + 10, y1 + 5), new SizeF(colWidth - 5, 15)));
            _c1pdf.DrawString("Email Address:", font, Brushes.Black, new PointF(x2 + 10, y1 + 30));

            // Render Textbox
            RenderTextBox(dr["Lastname"].ToString().ToLower() + "@nwind.com", font, new RectangleF(new PointF(x2 + 80, y1 + 29), new SizeF(colWidth - 95, 15)), Color.FromKnownColor(KnownColor.Info), "Enter Email Address", false);

            // Render Listbox
            _c1pdf.DrawString("Title:", font, Brushes.Black, new PointF(x2 + 10, y1 + 60));
            RenderListBox(new string[] { "Sales Representative", "Sales Manager", "Vice President, Sales", "Inside Sales Coordinator" }, dr["Title"].ToString(), font, new RectangleF(new PointF(x2 + 50, y1 + 55), new SizeF(colWidth - 65, 30)));

            rcCell.Inflate(4, 0);


            pen.Dispose();

            // update rectangle and return it
            rc.Offset(0, rcCell.Height);
            return(rc);
        }