Пример #1
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);
        }
Пример #2
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);
        }
Пример #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);
        }
Пример #4
0
        private void button21_Click(object sender, System.EventArgs e)
        {
            C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument();

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

            rc.Inflate(-72, -72);

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

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

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

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

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #5
0
        private void 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);
        }
Пример #6
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);
        }
Пример #7
0
        private void AddFooters()
        {
            Font fontHorz = new Font("Tahoma", 7, FontStyle.Bold);
            Font fontVert = new Font("Viner Hand ITC", 14, FontStyle.Bold);

            StringFormat sfRight = new StringFormat();

            sfRight.Alignment = StringAlignment.Far;

            StringFormat sfVert = new StringFormat();

            sfVert.FormatFlags |= StringFormatFlags.DirectionVertical;
            sfVert.Alignment    = StringAlignment.Center;

            for (int page = 0; page < _c1pdf.Pages.Count; page++)
            {
                // select page we want (could change PageSize)
                _c1pdf.CurrentPage = page;

                // build rectangles for rendering text
                RectangleF rcPage   = GetPageRect();
                RectangleF rcFooter = rcPage;
                rcFooter.Y      = rcFooter.Bottom + 6;
                rcFooter.Height = 12;
                RectangleF rcVert = rcPage;
                rcVert.X = rcPage.Right + 6;

                // add left-aligned footer
                string text = _c1pdf.DocumentInfo.Title;
                _c1pdf.DrawString(text, fontHorz, Brushes.Gray, rcFooter);

                // add right-aligned footer
                text = string.Format("Page {0} of {1}", page + 1, _c1pdf.Pages.Count);
                _c1pdf.DrawString(text, fontHorz, Brushes.Gray, rcFooter, sfRight);

                // add vertical text
                text = _c1pdf.DocumentInfo.Title + " (document created using the C1Pdf .NET component)";
                _c1pdf.DrawString(text, fontVert, Brushes.LightGray, rcVert, sfVert);

                // draw lines on bottom and right of the page
                _c1pdf.DrawLine(Pens.Gray, rcPage.Left, rcPage.Bottom, rcPage.Right, rcPage.Bottom);
                _c1pdf.DrawLine(Pens.Gray, rcPage.Right, rcPage.Top, rcPage.Right, rcPage.Bottom);
            }
        }
Пример #8
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);
        }
Пример #9
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 = tempdir + "hello world.pdf";

            pdf.Save(fileName);
            System.Diagnostics.Process.Start(fileName);
        }
Пример #10
0
        private void AddPageHeaders(RectangleF rcPage)
        {
            RectangleF rcHdr = rcPage;

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

                //draw letterhead
                string s = string.Format("Page {0} of {1}", page + 1, _c1pdf.Pages.Count);
                _c1pdf.DrawString(s, _fontBody, Brushes.LightGray, rcHdr, _sfRightCenter);
                rcHdr.Inflate(0, -30);
                _c1pdf.DrawRectangle(Pens.LightGray, rcHdr);
                rcHdr.Inflate(0, +30);
            }
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
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);
        }
Пример #16
0
        private RectangleF RenderTableHeader(Font font, RectangleF rc, string[] fields)
        {
            // calculate cell width (same for all columns)
            RectangleF rcCell = rc;

            rcCell.Width  = rc.Width / fields.Length;
            rcCell.Height = 0;

            //  calculate cell height (max of all columns)
            foreach (string field in fields)
            {
                float height = _c1pdf.MeasureString(field, font, rcCell.Width).Height;
                rcCell.Height = Math.Max(rcCell.Height, height);
            }

            // render header cells
            foreach (string field in fields)
            {
                _c1pdf.FillRectangle(Brushes.Black, rcCell);
                _c1pdf.DrawString(field, font, Brushes.White, rcCell);
                rcCell.Offset(rcCell.Width, 0);
            }

            // update rectangle and return it
            rc.Offset(0, rcCell.Height);
            return(rc);
        }
Пример #17
-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);
        }