예제 #1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            _pdf.Clear();

            Rectangle    rcell = new Rectangle(72, 72, 36, 36);
            StringFormat sf    = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Font f1  = new Font("Tahoma", rcell.Height / 2);
            Font f2  = new Font("Tahoma", rcell.Height / 6);
            Pen  pen = new Pen(Brushes.Black, 0.1f);

            int col = 0;

            for (char c = (char)32; c <= (char)256; c++)
            {
                // show this character
                _pdf.DrawRectangle(pen, rcell);
                _pdf.DrawString(c.ToString(), f1, Brushes.Black, rcell, sf);

                rcell.Width  /= 2;
                rcell.Height /= 4;
                _pdf.DrawRectangle(pen, rcell);
                _pdf.DrawString(((int)c).ToString(), f2, Brushes.Black, rcell, sf);
                rcell.Width  *= 2;
                rcell.Height *= 4;

                // increment rectangle
                col++;
                if (col >= 12)
                {
                    col      = 0;
                    rcell.X  = 72;
                    rcell.Y += rcell.Height;
                }
                else
                {
                    rcell.X += rcell.Width;
                }
            }

            string tempdir = Application.ExecutablePath.Substring(0,
                                                                  Application.ExecutablePath.LastIndexOf("\\") + 1);
            string fname = tempdir + "chartbl.pdf";

            _pdf.Save(fname);
            System.Diagnostics.Process.Start(fname);
        }
예제 #2
0
        private void _btnCreate_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument(System.Drawing.Printing.PaperKind.A4);
            pdf.Compression                   = C1.C1Pdf.CompressionEnum.None;
            pdf.Security.UserPassword         = _txtUser.Text;
            pdf.Security.OwnerPassword        = _txtOwner.Text;
            pdf.Security.AllowPrint           = _chkAllowPrint.Checked;
            pdf.Security.AllowCopyContent     = _chkAllowCopy.Checked;
            pdf.Security.AllowEditAnnotations = _chkAllowEditAnnot.Checked;
            pdf.Security.AllowEditContent     = _chkAllowEditContent.Checked;

            RectangleF rc = pdf.PageRectangle;

            rc.Inflate(-72, -72);
            pdf.DrawRectangle(Pens.Black, rc, new SizeF(72, 72));
            rc.Inflate(-72, -72);

            Font   font = new Font("Tahoma", 12);
            string text = string.Format("Owner password is '{0}'\r\nUser password is '{1}'", _txtOwner.Text, _txtUser.Text);

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

            string fileName = Path.GetDirectoryName(Application.ExecutablePath) + @"\security.pdf";

            pdf.Save(fileName);
            Process.Start(fileName);
        }
예제 #3
0
        private void CreatePDF()
        {
            _c1pdf = new C1.C1Pdf.C1PdfDocument();
            //start document
            _c1pdf.Clear();
            TEMP_DIR = Server.MapPath("../Temp");
            if (Directory.Exists(TEMP_DIR))
            {
            }
            else
            {
                Directory.CreateDirectory(TEMP_DIR);
            }
            //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);
        }
예제 #4
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // start document
            _c1pdf.Clear();
            _c1pdf.Security.AllowPrint = false;
            //_c1pdf.Security.UserPassword = "******";
            //_c1pdf.Landscape = true;

            // build page and chart rectangles
            RectangleF rcPage = _c1pdf.PageRectangle;

            rcPage.Inflate(-60, -72);
            rcPage.X = 72;
            RectangleF rcChart = new RectangleF(rcPage.X, rcPage.Y, 160, 160);

            // show title
            Font       font = new Font("Tahoma", 16, FontStyle.Bold);
            string     text = "Pdf charts created with the C1Chart control.";
            RectangleF rc   = rcPage;

            rc.Y = rcPage.Y - 24;
            _c1pdf.DrawString(text, font, Brushes.DarkGray, rc);

            // scan controls on the selected tab page and render charts
            foreach (Control c in tabControl1.SelectedTab.Controls)
            {
                // skip invisible controls
                if (!c.Visible)
                {
                    continue;
                }

                // get chart control
                C1.Win.C1Chart.C1Chart     c2d = c as C1.Win.C1Chart.C1Chart;
                C1.Win.C1Chart3D.C1Chart3D c3d = c as C1.Win.C1Chart3D.C1Chart3D;

                // get metafile from chart control
                label1.Text = string.Format("Getting image from {0}...", c.Name);
                label1.Update();
                Metafile meta = null;
                if (c2d != null)
                {
                    meta = (Metafile)c2d.GetImage();
                }
                if (c3d != null)
                {
                    meta = (Metafile)c3d.GetImage();
                }

                // make sure we got the metafile
                if (meta == null)
                {
                    continue;
                }

                // draw it, frame it, and move on
                label1.Text = string.Format("Exporting {0}...", c.Name);
                label1.Update();
                _c1pdf.DrawImage(meta, rcChart);
                _c1pdf.DrawRectangle(Pens.SteelBlue, rcChart);
                rcChart = NextChartRect(rcChart, rcPage);
            }
            label1.Text = string.Empty;

            // save document and show it
            string tempdir = Application.ExecutablePath.Substring(0,
                                                                  Application.ExecutablePath.LastIndexOf("\\") + 1);
            string fileName = string.Format(tempdir + @"{0}.pdf", tabControl1.SelectedTab.Text);

            _c1pdf.Save(fileName);
            Process.Start(fileName);
        }
예제 #5
0
        //=============================================================================
        // test arcs and pies
        private void button3_Click(object sender, System.EventArgs e)
        {
            _c1pdf.Clear();
            _c1pdf.Compression = C1.C1Pdf.CompressionEnum.None;

            int       penWidth = 0;
            int       penRGB   = 0;
            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);

            // start, c1, c2, end1, c3, c4, end
            PointF[] bezierPoints = 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 .NET Graphics object
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.FillRectangle(Brushes.White, 0, 0, bmp.Width, bmp.Height);
                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);
                g.Dispose();
            }
            this.pictureBox1.Image = bmp;
            this.pictureBox1.Refresh();

            // draw to pdf document
            penWidth = 0;
            penRGB   = 0;
            if (true)
            {
                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);
            }

            // show pdf document
            SaveAndShow(@"c:\temp\test\arcpie.pdf");
        }
예제 #6
0
        private void DumpMetas(string mask)
        {
            Cursor = Cursors.WaitCursor;

            _c1pdf.Clear();
            _c1pdf.Compression = C1.C1Pdf.CompressionEnum.None;
            //_c1pdf.Compression = C1.C1Pdf.CompressionEnum.BestCompression;
            Random rnd  = new Random();
            Font   font = new Font("Courier New", 9, FontStyle.Bold);

            // look for emf files in the executable directory
            string path  = Path.GetDirectoryName(Application.ExecutablePath);
            bool   first = true;

            string[] files = Directory.GetFiles(path, mask);
            foreach (string fileName in files)
            {
                statusBar1.Text = string.Format("Exporting {0}...", Path.GetFileName(fileName));
                Application.DoEvents();

                // new page
                if (!first)
                {
                    _c1pdf.NewPage();
                }
                first = false;

                // load metafile
                Metafile meta = (Metafile)Metafile.FromFile(fileName);

                // get metafile size in points
                SizeF szPage = GetImageSizeInPoints(meta);
                Console.WriteLine("Adding page {0:f2}\" x {1:f2}\"", szPage.Width / 72f, szPage.Height / 72f);

                // size page to metafile
                _c1pdf.PageSize = szPage;

                // draw metafile on the page
                RectangleF rc = _c1pdf.PageRectangle;
                _c1pdf.FillRectangle(Brushes.AntiqueWhite, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawString(fileName, font, Brushes.Black, rc);

                // draw thumbnail at random place
                rc.Width  /= 5;
                rc.Height /= 5;
                rc.X       = rnd.Next((int)(szPage.Width - rc.Width));
                rc.Y       = rnd.Next((int)(szPage.Height - rc.Height));
                _c1pdf.FillRectangle(Brushes.White, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawRectangle(Pens.Black, rc);

                // add outline entry if there's more than one page
                if (files.Length > 1)
                {
                    _c1pdf.AddBookmark(Path.GetFileName(fileName), 0, 0);
                }
            }

            // show the result
            statusBar1.Text = "Saving...";
            SaveAndShow(@"c:\temp\test\metas.pdf");
            Cursor          = Cursors.Default;
            statusBar1.Text = "Ready";
        }