Example #1
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;
        }
Example #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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
Example #8
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);
        }
Example #9
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);
        }
Example #10
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);
        }
Example #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);
        }
Example #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);
        }
Example #13
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);
        }
Example #14
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);
        }
Example #15
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);
        }
Example #16
0
        private void CreatePdf(Image img)
        {
            // export to pdf
            _pdf.Clear();
            RectangleF rc = _pdf.PageRectangle;

            rc.Inflate(-72, -72); // << 1" margin
            _pdf.DrawImage(img, rc, ContentAlignment.MiddleCenter, ImageSizeModeEnum.Scale);
            string fileName = Application.StartupPath + @"\pie.pdf";

            _pdf.Save(fileName);

            // show pdf
            System.Diagnostics.Process.Start(fileName);
        }
Example #17
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);
        }
Example #18
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);
        }
Example #19
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);
        }
Example #20
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);
        }
Example #21
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);
        }
Example #22
0
        protected void btnexport_Click(object sender, EventArgs e)
        {
            try
            {
                Create();

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

                Response.Clear();
                Response.ContentType = "application/pdf";
                Response.TransmitFile(filename);
                Response.Flush();
                File.Delete(filename);
                Response.End();
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
Example #23
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);
        }
Example #24
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);
        }
Example #25
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            _c1pdf.Clear();
            RectangleF rc = _c1pdf.PageRectangle;

            rc.Inflate(-72, -72);
            _c1pdf.DrawString(textBox1.Text, textBox1.Font, Brushes.Black, rc);

            string          infoString = "single char: 不明だった炭素の";
            PdfDocumentInfo info       = _c1pdf.DocumentInfo;

            info.Author   = infoString;
            info.Creator  = infoString;
            info.Keywords = infoString;
            info.Producer = infoString;
            info.Subject  = infoString;
            info.Title    = infoString;

            // save and show pdf document
            string fileName = string.Format(@"{0}\{1}.pdf", Path.GetDirectoryName(Application.ExecutablePath), _cmbLanguage.Text);

            _c1pdf.Save(fileName);
            Process.Start(fileName);
        }
Example #26
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);
        }
Example #27
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);
        }
Example #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);
        }