Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private void button4_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   = pdf.PageRectangle;

            rc.Inflate(-72, -72);

            // stretch image to fill the rectangle
            pdf.DrawImage(pictureBox1.Image, rc);

            // center image within the rectangle, scale keeping aspect ratio
            pdf.DrawImage(pictureBox1.Image, rc, ContentAlignment.MiddleCenter, C1.C1Pdf.ImageSizeModeEnum.Scale);

            // center image within the rectangle, keep original size
            pdf.DrawImage(pictureBox1.Image, rc, ContentAlignment.TopLeft, C1.C1Pdf.ImageSizeModeEnum.Clip);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 4
0
        private void button11_Click(object sender, System.EventArgs e)
        {
            // initialize
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create points
            PointF[] pts = new PointF[]
            {
                new PointF(50f, 100f), new PointF(100f, 10f), new PointF(250f, 50f),
                new PointF(400f, 100f), new PointF(500f, 150f), new PointF(550f, 250f),
                new PointF(400f, 300f)
            };

            // draw Bezier spline
            pdf.DrawBeziers(new Pen(Color.Blue, 4), pts);

            // show points
            pdf.DrawLines(Pens.Gray, pts);
            for (int i = 0; i < pts.Length; i++)
            {
                Brush brush = (i % 3 == 0)? Brushes.Red: Brushes.Green;
                pdf.FillRectangle(brush, pts[i].X - 2, pts[i].Y - 2, 4, 4);
            }

            // save document
            string fileName = tempdir + "beziers.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        private void button13_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create a thin (hairline) black pen
            Pen thinPen = new Pen(Color.Black, 0);

            // create a thick (3pt) blue pen
            Pen thickPen = new Pen(Color.Blue, 3);

            // create a thick (2pt) dotted red pen
            Pen dotPen = new Pen(Color.Red, 2);

            dotPen.DashStyle = DashStyle.Dot;

            // draw some lines
            pdf.DrawLine(thinPen, 100, 100, 300, 100);
            pdf.DrawLine(thickPen, 100, 120, 300, 120);
            pdf.DrawLine(dotPen, 100, 140, 300, 140);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private void button15_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create an array with some brushes
            Brush[] brushes = new Brush[]
            {
                Brushes.Red, Brushes.Green, Brushes.Blue,
                Brushes.Yellow, Brushes.Crimson, Brushes.Aquamarine
            };

            // setup rectangle and initialize angles
            RectangleF rc         = new RectangleF(100, 100, 180, 150);
            float      startAngle = 0;
            float      sweepAngle = -90;        // << counter-clockwise

            // draw pie
            foreach (Brush brush in brushes)
            {
                pdf.FillPie(brush, rc, startAngle, sweepAngle);
                pdf.DrawPie(Pens.Black, rc, startAngle, sweepAngle);
                startAngle += sweepAngle;
                sweepAngle /= 2;
            }

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        private void button8_Click(object sender, System.EventArgs e)
        {
            // initialize
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create a regular (external) hyperlink
            RectangleF rc   = new RectangleF(50, 50, 200, 15);
            Font       font = new Font("Arial", 10, FontStyle.Underline);

            pdf.AddLink("http://www.componentone.com", rc);
            pdf.DrawString("Visit ComponentOne", font, Brushes.Blue, rc);

            // create a link target
            pdf.AddTarget("#myLink", rc);

            // add a few pages
            for (int i = 0; i < 5; i++)
            {
                pdf.NewPage();
            }

            // add a link to the target
            pdf.AddLink("#myLink", rc);
            pdf.FillRectangle(Brushes.BlanchedAlmond, rc);
            pdf.DrawString("Local link: back to page 1...", font, Brushes.Blue, rc);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 14
0
        private void button9_Click(object sender, System.EventArgs e)
        {
            // initialize
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            RectangleF rc = new RectangleF(0, 0, 200, 180);

            pdf.DrawEllipse(Pens.Gray, rc);
            pdf.DrawArc(new Pen(Color.Black, 4), rc, 0, 45);
            pdf.DrawArc(new Pen(Color.Red, 4), rc, 0, -45);

            string fileName = tempdir + "arc.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);

            Bitmap bmp = new Bitmap(pictureBox2.Size.Width, pictureBox2.Size.Height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.PageUnit = GraphicsUnit.Point;
                g.DrawEllipse(Pens.Gray, rc);
                g.DrawArc(new Pen(Color.Black, 4), rc, 0, 45);
                g.DrawArc(new Pen(Color.Red, 4), rc, 0, -45);
            }
            this.pictureBox2.Image = bmp;
        }
Exemplo n.º 15
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.c1PdfDocument1 = new C1.C1Pdf.C1PdfDocument();
     this.button1        = new System.Windows.Forms.Button();
     this.comboBox1      = new System.Windows.Forms.ComboBox();
     this.label1         = new System.Windows.Forms.Label();
     this.SuspendLayout();
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(168, 80);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(120, 24);
     this.button1.TabIndex = 0;
     this.button1.Text     = "Go";
     this.button1.Click   += new System.EventHandler(this.button1_Click);
     //
     // comboBox1
     //
     this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     this.comboBox1.Items.AddRange(new object[] {
         "5",
         "10",
         "50",
         "100",
         "200"
     });
     this.comboBox1.Location = new System.Drawing.Point(8, 80);
     this.comboBox1.Name     = "comboBox1";
     this.comboBox1.Size     = new System.Drawing.Size(152, 21);
     this.comboBox1.TabIndex = 1;
     //
     // label1
     //
     this.label1.Location = new System.Drawing.Point(8, 8);
     this.label1.Name     = "label1";
     this.label1.Size     = new System.Drawing.Size(280, 48);
     this.label1.TabIndex = 2;
     this.label1.Text     = "Select the number of threads you want to create, then click \"Go\". Each thread wil" +
                            "l generate a Pdf file under \"c:\\temp\".";
     //
     // Form1
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(296, 117);
     this.Controls.AddRange(new System.Windows.Forms.Control[] {
         this.label1,
         this.comboBox1,
         this.button1
     });
     this.Name          = "Form1";
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
     this.Text          = "C1Pdf: Threaded test";
     this.Load         += new System.EventHandler(this.Form1_Load);
     this.ResumeLayout(false);
 }
Exemplo n.º 16
0
        private void CreatePDF()
        {
            _c1pdf = new C1PdfDocument();
            // create pdf document
            _c1pdf.Clear();
            _c1pdf.DocumentInfo.Title = "PDF Acroform";
            TEMP_DIR = Server.MapPath("../Temp");
            if (Directory.Exists(TEMP_DIR))
            {
            }
            else
            {
                Directory.CreateDirectory(TEMP_DIR);
            }
            // calculate page rect (discounting margins)
            RectangleF rcPage = GetPageRect();
            RectangleF rc     = rcPage;


            // add title
            Font titleFont = new Font("Tahoma", 24, FontStyle.Bold);

            rc = RenderParagraph(_c1pdf.DocumentInfo.Title, titleFont, rcPage, rc, false);

            // render Employees table
            rc = RenderTable(rc, rcPage);

            // Render Buttons
            Font          btnFont = new Font("Tahoma", 14, FontStyle.Bold);
            PdfPushButton button1 = RenderPushButton("Submit", btnFont, new RectangleF(new PointF(rc.X, rc.Y + 10), new SizeF(90, 25)), ButtonLayout.TextLeftImageRight);

            button1.Actions.LostFocus.Add(new PdfPushButton.Action(ButtonAction.GotoPage, "Bmark"));
            button1.BorderStyle = FieldBorderStyle.Inset;
            button1.BorderWidth = FieldBorderWidth.Medium;
            button1.BorderColor = Color.Black;

            PdfPushButton button2 = RenderPushButton("Clear Fields", btnFont, new RectangleF(new PointF(rc.X + 110, rc.Y + 10), new SizeF(110, 25)), ButtonLayout.TextLeftImageRight);

            button2.Actions.Pressed.Add(new PdfPushButton.Action(ButtonAction.ClearFields));
            button2.BorderStyle = FieldBorderStyle.Dashed;
            button2.BorderWidth = FieldBorderWidth.Medium;
            button2.BorderColor = Color.Black;

            // second pass to number pages
            AddFooters();

            // save to file and show it
            // save pdf file

            _c1pdf.Compression = CompressionEnum.None;
            string uid = System.Guid.NewGuid().ToString();

            filename = Server.MapPath("~") + "\\Temp\\testpdf" + uid + ".pdf";
            _c1pdf.Save(filename);
        }
Exemplo n.º 17
0
        private void CreatePDF()
        {
            _c1pdf = new C1PdfDocument();
            // create pdf document
            _c1pdf.Clear();
            _c1pdf.DocumentInfo.Title = "PDF Acroform";
            TEMP_DIR = Server.MapPath("../Temp");
            if (Directory.Exists(TEMP_DIR))
            {

            }
            else
            {
                Directory.CreateDirectory(TEMP_DIR);

            }
            // calculate page rect (discounting margins)
            RectangleF rcPage = GetPageRect();
            RectangleF rc = rcPage;


            // add title
            Font titleFont = new Font("Tahoma", 24, FontStyle.Bold);
            rc = RenderParagraph(_c1pdf.DocumentInfo.Title, titleFont, rcPage, rc, false);

            // render Employees table
            rc = RenderTable(rc, rcPage);

            // Render Buttons
            Font btnFont = new Font("Tahoma", 14, FontStyle.Bold);
            PdfPushButton button1 = RenderPushButton("Submit", btnFont, new RectangleF(new PointF(rc.X, rc.Y + 10), new SizeF(90, 25)), ButtonLayout.TextLeftImageRight);
            button1.Actions.LostFocus.Add(new PdfPushButton.Action(ButtonAction.GotoPage, "Bmark"));
            button1.BorderStyle = FieldBorderStyle.Inset;
            button1.BorderWidth = FieldBorderWidth.Medium;
            button1.BorderColor = Color.Black;

            PdfPushButton button2 = RenderPushButton("Clear Fields", btnFont, new RectangleF(new PointF(rc.X + 110, rc.Y + 10), new SizeF(110, 25)), ButtonLayout.TextLeftImageRight);
            button2.Actions.Pressed.Add(new PdfPushButton.Action(ButtonAction.ClearFields));
            button2.BorderStyle = FieldBorderStyle.Dashed;
            button2.BorderWidth = FieldBorderWidth.Medium;
            button2.BorderColor = Color.Black;

            // second pass to number pages
            AddFooters();

            // save to file and show it
            // save pdf file
           
            _c1pdf.Compression = CompressionEnum.None;
            string uid = System.Guid.NewGuid().ToString();
            filename = Server.MapPath("~") + "\\Temp\\testpdf" + uid + ".pdf";
            _c1pdf.Save(filename);
        }
Exemplo n.º 18
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
     this._c1c    = new C1.Win.C1Chart.C1Chart();
     this.button1 = new System.Windows.Forms.Button();
     this._pdf    = new C1.C1Pdf.C1PdfDocument();
     this.button2 = new System.Windows.Forms.Button();
     ((System.ComponentModel.ISupportInitialize)(this._c1c)).BeginInit();
     this.SuspendLayout();
     //
     // _c1c
     //
     this._c1c.Dock     = System.Windows.Forms.DockStyle.Fill;
     this._c1c.Location = new System.Drawing.Point(0, 45);
     this._c1c.Name     = "_c1c";
     this._c1c.PropBag  = resources.GetString("_c1c.PropBag");
     this._c1c.Size     = new System.Drawing.Size(560, 312);
     this._c1c.TabIndex = 0;
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(8, 8);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(161, 24);
     this.button1.TabIndex = 1;
     this.button1.Text     = "Convert to Pdf (regular)";
     this.button1.Click   += new System.EventHandler(this.button1_Click);
     //
     // button2
     //
     this.button2.Location = new System.Drawing.Point(175, 8);
     this.button2.Name     = "button2";
     this.button2.Size     = new System.Drawing.Size(161, 24);
     this.button2.TabIndex = 1;
     this.button2.Text     = "Convert to Pdf (high-res)";
     this.button2.Click   += new System.EventHandler(this.button2_Click);
     //
     // Form1
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(560, 357);
     this.Controls.Add(this.button2);
     this.Controls.Add(this.button1);
     this.Controls.Add(this._c1c);
     this.Name    = "Form1";
     this.Padding = new System.Windows.Forms.Padding(0, 45, 0, 0);
     this.Text    = "Form1";
     this.Load   += new System.EventHandler(this.Form1_Load);
     ((System.ComponentModel.ISupportInitialize)(this._c1c)).EndInit();
     this.ResumeLayout(false);
 }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        private void button1_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   = pdf.PageRectangle;

            rc.Inflate(-72, -72);
            pdf.DrawString("Hello World!", font, Brushes.Black, rc);

            // step 3: save the document to a file
            string fileName = @"c:\temp\hello world.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 21
0
        private void button3_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   = pdf.PageRectangle;

            rc.Inflate(-72, -72);
            pdf.DrawStringRtf(@"To {\b boldly} go where {\i no one} has gone before!", font, Brushes.Black, rc);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 22
0
        private void DrawPageImage(C1.C1Pdf.C1PdfDocument pdf, int index)
        {
            // get image bounds
            RectangleF rcBounds = pdf.PageRectangle;

            rcBounds.Inflate(-72, -72);

            // calculate zoom factor
            if (index == 0)
            {
                // get size of largest image
                SizeF szMax = Size.Empty;
                foreach (Image page in _images)
                {
                    szMax.Height = Math.Max(szMax.Height, page.Height);
                    szMax.Width  = Math.Max(szMax.Width, page.Width);
                }

                // get size of page bounds
                SizeF szPage = rcBounds.Size;

                // calculate zoom so largest image doesn't overflow the page
                _zoom = 1;
                float zh = szPage.Width / szMax.Width;
                float zv = szPage.Height / szMax.Height;
                if (zh < 1 || zv < 1)
                {
                    _zoom = Math.Min(zh, zv);
                }
            }

            // draw grid image
            var   rc  = rcBounds;
            Image img = _images[index] as Image;

            rc.Width  = (int)(img.Width * _zoom);
            rc.Height = (int)(img.Height * _zoom);
            if (index > 0)
            {
                pdf.NewPage();
            }
            pdf.DrawImage(img, rc);
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        private void button16_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

            // create an array with some points
            PointF[] points = new PointF[]
            {
                new PointF(100, 100), new PointF(300, 100), new PointF(200, 200)
            };

            // fill and draw a polygon
            pdf.FillPolygon(Brushes.Beige, points);
            pdf.DrawPolygon(Pens.Black, points);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 25
0
        private void button6_Click(object sender, System.EventArgs e)
        {
            // get rtf template
            string rtfHdr = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033" +
                            @"{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\froman\fprq2\fcharset0 Book Antiqua;}}" +
                            @"{\colortbl ;\red0\green0\blue0;}\viewkind4\uc1\pard\f0\fs20\par" +
                            @"\pard\tx1440\tx2880\tx4320\tx5760\cf1\b\f1\fs24 Directory Report created on <<TODAY>>\par" +
                            @"\ul\par Name\tab Extension\tab Size\tab Date\tab Attributes\par";
            string rtfEntry = @"\cf0\ulnone\b0\f0\fs16 <<NAME>>\tab <<EXT>>\tab <<SIZE>>\tab <<DATE>>\tab <<ATTS>>\par";

            // build rtf string
            StringBuilder sb = new StringBuilder();

            sb.Append(rtfHdr.Replace("<<TODAY>>", DateTime.Today.ToShortDateString()));
            foreach (string file in Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "*.bmp"))
            {
                string   s  = rtfEntry;
                FileInfo fi = new FileInfo(file);
                s = s.Replace("<<NAME>>", Path.GetFileNameWithoutExtension(file));
                s = s.Replace("<<EXT>>", fi.Extension);
                s = s.Replace("<<SIZE>>", string.Format("{0:#,##0}", fi.Length));
                s = s.Replace("<<DATE>>", fi.LastWriteTime.ToShortDateString());
                s = s.Replace("<<ATTS>>", fi.Attributes.ToString());
                sb.Append(s);
            }
            sb.Append("}");

            // render it
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();
            RectangleF             rc  = pdf.PageRectangle;

            rc.Inflate(-72, -72);
            pdf.DrawStringRtf(sb.ToString(), Font, Brushes.Black, rc);

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
        private void CreatePDF()
        {
            _c1pdf = new C1PdfDocument();
            // initialize pdf generator
            _c1pdf.Clear();
            _c1pdf.DocumentInfo.Title = "Pdf Document With Table of Contents";
            TEMP_DIR = Server.MapPath("../Temp");
            if (Directory.Exists(TEMP_DIR))
            {
            }
            else
            {
                Directory.CreateDirectory(TEMP_DIR);
            }
            // add title
            Font       titleFont = new Font("Tahoma", 24, FontStyle.Bold);
            RectangleF rcPage    = GetPageRect();
            RectangleF rc        = RenderParagraph(_c1pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);

            rc.Y += 12;

            // create nonsense document
            ArrayList bkmk       = new ArrayList();
            Font      headerFont = new Font("Tahoma", 16, FontStyle.Bold);
            Font      bodyFont   = new Font("Tahoma", 10);

            for (int i = 0; i < 30; i++)
            {
                // create ith header (as a link target and outline entry)
                string header = string.Format("{0}. {1}", i + 1, BuildRandomTitle());
                rc = RenderParagraph(header, headerFont, rcPage, rc, true, true);

                // save bookmark to build TOC later
                int pageNumber = _c1pdf.CurrentPage + 1;
                bkmk.Add(new string[] { pageNumber.ToString(), header });

                // create some text
                rc.X     += 36;
                rc.Width -= 36;
                for (int j = 0; j < 3 + _rnd.Next(10); j++)
                {
                    string text = BuildRandomParagraph();
                    rc    = RenderParagraph(text, bodyFont, rcPage, rc);
                    rc.Y += 6;
                }
                rc.X     -= 36;
                rc.Width += 36;
                rc.Y     += 20;
            }

            // number pages (before adding TOC)
            AddFooters();

            // start Table of Contents
            _c1pdf.NewPage();                   // start TOC on a new page
            int tocPage = _c1pdf.CurrentPage;   // save page index (to move TOC later)

            rc        = RenderParagraph("Table of Contents", titleFont, rcPage, rcPage, true);
            rc.Y     += 12;
            rc.X     += 30;
            rc.Width -= 40;

            // render Table of Contents
            Pen dottedPen = new Pen(Brushes.Gray, 1.5f);

            dottedPen.DashStyle = DashStyle.Dot;
            StringFormat sfRight = new StringFormat();

            sfRight.Alignment = StringAlignment.Far;
            rc.Height         = bodyFont.Height;
            foreach (string[] entry in bkmk)
            {
                // get bookmark info
                string page   = entry[0];
                string header = entry[1];

                // render header name and page number
                _c1pdf.DrawString(header, bodyFont, Brushes.Black, rc);
                _c1pdf.DrawString(page, bodyFont, Brushes.Black, rc, sfRight);

                // connect the two with some dots (looks better than a dotted line)
                string dots = ". ";
                float  wid  = _c1pdf.MeasureString(dots, bodyFont).Width;
                float  x1   = rc.X + _c1pdf.MeasureString(header, bodyFont).Width + 8;
                float  x2   = rc.Right - _c1pdf.MeasureString(page, bodyFont).Width - 8;
                float  x    = rc.X;
                for (rc.X = x1; rc.X < x2; rc.X += wid)
                {
                    _c1pdf.DrawString(dots, bodyFont, Brushes.Gray, rc);
                }
                rc.X = x;

                // add local hyperlink to entry
                _c1pdf.AddLink("#" + header, rc);

                // move on to next entry
                rc.Offset(0, rc.Height);
                if (rc.Bottom > rcPage.Bottom)
                {
                    _c1pdf.NewPage();
                    rc.Y = rcPage.Y;
                }
            }

            // move table of contents to start of document
            PdfPage[] arr = new PdfPage[_c1pdf.Pages.Count - tocPage];
            _c1pdf.Pages.CopyTo(tocPage, arr, 0, arr.Length);
            _c1pdf.Pages.RemoveRange(tocPage, arr.Length);
            _c1pdf.Pages.InsertRange(0, arr);

            // save pdf file
            string uid = System.Guid.NewGuid().ToString();

            filename = Server.MapPath("~") + "\\Temp\\testpdf" + uid + ".pdf";
            _c1pdf.Save(filename);

            // display it
            //webBrowser1.Navigate(filename);
        }
Exemplo n.º 29
0
        private void CreatePDF()
        {
            _c1pdf = new C1PdfDocument();
            // initialize pdf generator
            _c1pdf.Clear();
            _c1pdf.DocumentInfo.Title = "Pdf Document With Table of Contents";
            TEMP_DIR = Server.MapPath("../Temp");
            if (Directory.Exists(TEMP_DIR))
            {

            }
            else
            {
                Directory.CreateDirectory(TEMP_DIR);

            }
            // add title
            Font titleFont = new Font("Tahoma", 24, FontStyle.Bold);
            RectangleF rcPage = GetPageRect();
            RectangleF rc = RenderParagraph(_c1pdf.DocumentInfo.Title, titleFont, rcPage, rcPage, false);
            rc.Y += 12;

            // create nonsense document
            ArrayList bkmk = new ArrayList();
            Font headerFont = new Font("Tahoma", 16, FontStyle.Bold);
            Font bodyFont = new Font("Tahoma", 10);
            for (int i = 0; i < 30; i++)
            {
                // create ith header (as a link target and outline entry)
                string header = string.Format("{0}. {1}", i + 1, BuildRandomTitle());
                rc = RenderParagraph(header, headerFont, rcPage, rc, true, true);

                // save bookmark to build TOC later
                int pageNumber = _c1pdf.CurrentPage + 1;
                bkmk.Add(new string[] { pageNumber.ToString(), header });

                // create some text
                rc.X += 36;
                rc.Width -= 36;
                for (int j = 0; j < 3 + _rnd.Next(10); j++)
                {
                    string text = BuildRandomParagraph();
                    rc = RenderParagraph(text, bodyFont, rcPage, rc);
                    rc.Y += 6;
                }
                rc.X -= 36;
                rc.Width += 36;
                rc.Y += 20;
            }

            // number pages (before adding TOC)
            AddFooters();

            // start Table of Contents
            _c1pdf.NewPage();					// start TOC on a new page
            int tocPage = _c1pdf.CurrentPage;	// save page index (to move TOC later)
            rc = RenderParagraph("Table of Contents", titleFont, rcPage, rcPage, true);
            rc.Y += 12;
            rc.X += 30;
            rc.Width -= 40;

            // render Table of Contents
            Pen dottedPen = new Pen(Brushes.Gray, 1.5f);
            dottedPen.DashStyle = DashStyle.Dot;
            StringFormat sfRight = new StringFormat();
            sfRight.Alignment = StringAlignment.Far;
            rc.Height = bodyFont.Height;
            foreach (string[] entry in bkmk)
            {
                // get bookmark info
                string page = entry[0];
                string header = entry[1];

                // render header name and page number
                _c1pdf.DrawString(header, bodyFont, Brushes.Black, rc);
                _c1pdf.DrawString(page, bodyFont, Brushes.Black, rc, sfRight);

                // connect the two with some dots (looks better than a dotted line)
                string dots = ". ";
                float wid = _c1pdf.MeasureString(dots, bodyFont).Width;
                float x1 = rc.X + _c1pdf.MeasureString(header, bodyFont).Width + 8;
                float x2 = rc.Right - _c1pdf.MeasureString(page, bodyFont).Width - 8;
                float x = rc.X;
                for (rc.X = x1; rc.X < x2; rc.X += wid)
                    _c1pdf.DrawString(dots, bodyFont, Brushes.Gray, rc);
                rc.X = x;

                // add local hyperlink to entry
                _c1pdf.AddLink("#" + header, rc);

                // move on to next entry
                rc.Offset(0, rc.Height);
                if (rc.Bottom > rcPage.Bottom)
                {
                    _c1pdf.NewPage();
                    rc.Y = rcPage.Y;
                }
            }

            // move table of contents to start of document
            PdfPage[] arr = new PdfPage[_c1pdf.Pages.Count - tocPage];
            _c1pdf.Pages.CopyTo(tocPage, arr, 0, arr.Length);
            _c1pdf.Pages.RemoveRange(tocPage, arr.Length);
            _c1pdf.Pages.InsertRange(0, arr);

            // save pdf file
            string uid = System.Guid.NewGuid().ToString();
            filename = Server.MapPath("~") + "\\Temp\\testpdf" + uid + ".pdf";
            _c1pdf.Save(filename);

            // display it
            //webBrowser1.Navigate(filename);
        }
Exemplo n.º 30
0
        private void Create()
        {
            _c1pdf = new C1PdfDocument();
            //create StringFormat for right-aligned fields
            _sfRight                     = new StringFormat();
            _sfRight.Alignment           = StringAlignment.Far;
            _sfRightCenter               = new StringFormat();
            _sfRightCenter.Alignment     = StringAlignment.Far;
            _sfRightCenter.LineAlignment = StringAlignment.Center;

            //initialize pdf generator
            _c1pdf.Clear();

            //get page rectangle, discount margins
            RectangleF rcPage = _c1pdf.PageRectangle;

            rcPage.Inflate(-72, -92);

            //loop through selected categories
            int       page = 0;
            DataTable dt   = GetCategories();

            foreach (DataRow dr in dt.Rows)
            {
                //add page break, update page counter
                if (page > 0)
                {
                    _c1pdf.NewPage();
                }
                page++;

                //get current category name
                string catName = (string)dr["CategoryName"];

                //add title to page
                _c1pdf.DrawString(catName, _fontTitle, Brushes.Blue, rcPage);

                //add outline entry
                _c1pdf.AddBookmark(catName, 0, 0);

                //build row template
                RectangleF[] rcRows = new RectangleF[6];
                for (int i = 0; i < rcRows.Length; i++)
                {
                    rcRows[i]          = RectangleF.Empty;
                    rcRows[i].Location = new PointF(rcPage.X, rcPage.Y + _fontHeader.SizeInPoints + 10);
                    rcRows[i].Size     = new SizeF(0, _fontBody.SizeInPoints + 3);
                }
                rcRows[0].Width = 110;          // Product Name
                rcRows[1].Width = 60;           // Unit Price
                rcRows[2].Width = 80;           // Qty/Unit
                rcRows[3].Width = 60;           // Stock Units
                rcRows[4].Width = 60;           // Stock Value
                rcRows[5].Width = 60;           // Reorder
                for (int i = 1; i < rcRows.Length; i++)
                {
                    rcRows[i].X = rcRows[i - 1].X + rcRows[i - 1].Width + 8;
                }

                //add column headers
                _c1pdf.FillRectangle(Brushes.DarkGray, RectangleF.Union(rcRows[0], rcRows[5]));
                _c1pdf.DrawString("Product Name", _fontHeader, Brushes.White, rcRows[0]);
                _c1pdf.DrawString("Unit Price", _fontHeader, Brushes.White, rcRows[1], _sfRight);
                _c1pdf.DrawString("Qty/Unit", _fontHeader, Brushes.White, rcRows[2]);
                _c1pdf.DrawString("Stock Units", _fontHeader, Brushes.White, rcRows[3], _sfRight);
                _c1pdf.DrawString("Stock Value", _fontHeader, Brushes.White, rcRows[4], _sfRight);
                _c1pdf.DrawString("Reorder", _fontHeader, Brushes.White, rcRows[5]);

                //loop through products in this category
                DataRow[] products = dr.GetChildRows("Categories_Products");

                foreach (DataRow product in products)
                {
                    //move on to next row
                    for (int i = 0; i < rcRows.Length; i++)
                    {
                        rcRows[i].Y += rcRows[i].Height;
                    }

                    //add row with some data
                    try
                    {
                        _c1pdf.DrawString(product["ProductName"].ToString(), _fontBody, Brushes.Black, rcRows[0]);
                        _c1pdf.DrawString(string.Format("{0:c}", product["UnitPrice"]), _fontBody, Brushes.Black, rcRows[1], _sfRight);
                        _c1pdf.DrawString(string.Format("{0}", product["QuantityPerUnit"]), _fontBody, Brushes.Black, rcRows[2]);
                        _c1pdf.DrawString(string.Format("{0}", product["UnitsInStock"]), _fontBody, Brushes.Black, rcRows[3], _sfRight);
                        _c1pdf.DrawString(string.Format("{0:c}", product["ValueInStock"]), _fontBody, Brushes.Black, rcRows[4], _sfRight);
                        if ((bool)product["OrderNow"])
                        {
                            _c1pdf.DrawString("<<<", _fontBody, Brushes.Red, rcRows[5]);
                        }
                    }
                    catch
                    {
                        // Debug.Assert(false);
                    }
                }
                if (products.Length == 0)
                {
                    rcRows[0].Y += rcRows[0].Height;
                    _c1pdf.DrawString("No products in this category.", _fontBody, Brushes.Black,
                                      RectangleF.Union(rcRows[0], rcRows[5]));
                }
            }

            //add page headers
            AddPageHeaders(rcPage);
        }
Exemplo n.º 31
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.button1      = new System.Windows.Forms.Button();
     this.textBox1     = new System.Windows.Forms.TextBox();
     this._c1pdf       = new C1.C1Pdf.C1PdfDocument();
     this._cmbLanguage = new System.Windows.Forms.ComboBox();
     this.SuspendLayout();
     //
     // button1
     //
     this.button1.Location = new System.Drawing.Point(8, 8);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(152, 24);
     this.button1.TabIndex = 0;
     this.button1.Text     = "Create Pdf Document";
     this.button1.Click   += new System.EventHandler(this.button1_Click);
     //
     // textBox1
     //
     this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                                                                   | System.Windows.Forms.AnchorStyles.Left)
                                                                  | System.Windows.Forms.AnchorStyles.Right)));
     this.textBox1.Font       = new System.Drawing.Font("MS Gothic", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(128)));
     this.textBox1.Location   = new System.Drawing.Point(8, 40);
     this.textBox1.Multiline  = true;
     this.textBox1.Name       = "textBox1";
     this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
     this.textBox1.Size       = new System.Drawing.Size(328, 320);
     this.textBox1.TabIndex   = 1;
     this.textBox1.Text       = "";
     this.textBox1.WordWrap   = false;
     //
     // _c1pdf
     //
     this._c1pdf.DocumentInfo.Producer = "ComponentOne C1Pdf";
     this._c1pdf.FontType = C1.C1Pdf.FontTypeEnum.Embedded;
     this._c1pdf.Security.AllowCopyContent     = true;
     this._c1pdf.Security.AllowEditAnnotations = true;
     this._c1pdf.Security.AllowEditContent     = true;
     this._c1pdf.Security.AllowPrint           = true;
     //
     // _cmbLanguage
     //
     this._cmbLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     this._cmbLanguage.Items.AddRange(new object[] {
         "Japanese",
         "Chinese",
         "Russian"
     });
     this._cmbLanguage.Location              = new System.Drawing.Point(176, 8);
     this._cmbLanguage.Name                  = "_cmbLanguage";
     this._cmbLanguage.Size                  = new System.Drawing.Size(144, 21);
     this._cmbLanguage.TabIndex              = 2;
     this._cmbLanguage.SelectedIndexChanged += new System.EventHandler(this._cmbLanguage_SelectedIndexChanged);
     //
     // Form1
     //
     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
     this.ClientSize        = new System.Drawing.Size(344, 373);
     this.Controls.Add(this._cmbLanguage);
     this.Controls.Add(this.textBox1);
     this.Controls.Add(this.button1);
     this.Name          = "Form1";
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
     this.Text          = "C1Pdf Eastern Text";
     this.Load         += new System.EventHandler(this.Form1_Load);
     this.ResumeLayout(false);
 }
Exemplo n.º 32
-1
        private void Create()
        {
            _c1pdf = new C1PdfDocument();
            //create StringFormat for right-aligned fields
            _sfRight = new StringFormat();
            _sfRight.Alignment = StringAlignment.Far;
            _sfRightCenter = new StringFormat();
            _sfRightCenter.Alignment = StringAlignment.Far;
            _sfRightCenter.LineAlignment = StringAlignment.Center;

            //initialize pdf generator
            _c1pdf.Clear();

            //get page rectangle, discount margins
            RectangleF rcPage = _c1pdf.PageRectangle;
            rcPage.Inflate(-72, -92);

            //loop through selected categories
            int page = 0;
            DataTable dt = GetCategories();
            foreach (DataRow dr in dt.Rows)
            {
                //add page break, update page counter
                if (page > 0) _c1pdf.NewPage();
                page++;

                //get current category name
                string catName = (string)dr["CategoryName"];

                //add title to page
                _c1pdf.DrawString(catName, _fontTitle, Brushes.Blue, rcPage);

                //add outline entry
                _c1pdf.AddBookmark(catName, 0, 0);

                //build row template
                RectangleF[] rcRows = new RectangleF[6];
                for (int i = 0; i < rcRows.Length; i++)
                {
                    rcRows[i] = RectangleF.Empty;
                    rcRows[i].Location = new PointF(rcPage.X, rcPage.Y + _fontHeader.SizeInPoints + 10);
                    rcRows[i].Size = new SizeF(0, _fontBody.SizeInPoints + 3);
                }
                rcRows[0].Width = 110;		// Product Name
                rcRows[1].Width = 60;		// Unit Price
                rcRows[2].Width = 80;		// Qty/Unit
                rcRows[3].Width = 60;		// Stock Units
                rcRows[4].Width = 60;		// Stock Value
                rcRows[5].Width = 60;		// Reorder
                for (int i = 1; i < rcRows.Length; i++)
                    rcRows[i].X = rcRows[i - 1].X + rcRows[i - 1].Width + 8;

                //add column headers
                _c1pdf.FillRectangle(Brushes.DarkGray, RectangleF.Union(rcRows[0], rcRows[5]));
                _c1pdf.DrawString("Product Name", _fontHeader, Brushes.White, rcRows[0]);
                _c1pdf.DrawString("Unit Price", _fontHeader, Brushes.White, rcRows[1], _sfRight);
                _c1pdf.DrawString("Qty/Unit", _fontHeader, Brushes.White, rcRows[2]);
                _c1pdf.DrawString("Stock Units", _fontHeader, Brushes.White, rcRows[3], _sfRight);
                _c1pdf.DrawString("Stock Value", _fontHeader, Brushes.White, rcRows[4], _sfRight);
                _c1pdf.DrawString("Reorder", _fontHeader, Brushes.White, rcRows[5]);

                //loop through products in this category
                DataRow[] products = dr.GetChildRows("Categories_Products");

                foreach (DataRow product in products)
                {
                    //move on to next row
                    for (int i = 0; i < rcRows.Length; i++)
                        rcRows[i].Y += rcRows[i].Height;

                    //add row with some data
                    try
                    {
                        _c1pdf.DrawString(product["ProductName"].ToString(), _fontBody, Brushes.Black, rcRows[0]);
                        _c1pdf.DrawString(string.Format("{0:c}", product["UnitPrice"]), _fontBody, Brushes.Black, rcRows[1], _sfRight);
                        _c1pdf.DrawString(string.Format("{0}", product["QuantityPerUnit"]), _fontBody, Brushes.Black, rcRows[2]);
                        _c1pdf.DrawString(string.Format("{0}", product["UnitsInStock"]), _fontBody, Brushes.Black, rcRows[3], _sfRight);
                        _c1pdf.DrawString(string.Format("{0:c}", product["ValueInStock"]), _fontBody, Brushes.Black, rcRows[4], _sfRight);
                        if ((bool)product["OrderNow"])
                            _c1pdf.DrawString("<<<", _fontBody, Brushes.Red, rcRows[5]);
                    }
                    catch
                    {
                        // Debug.Assert(false);
                    }
                }
                if (products.Length == 0)
                {
                    rcRows[0].Y += rcRows[0].Height;
                    _c1pdf.DrawString("No products in this category.", _fontBody, Brushes.Black,
                                      RectangleF.Union(rcRows[0], rcRows[5]));
                }
            }

            //add page headers
            AddPageHeaders(rcPage);
        }