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); }
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); }
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); }
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); }
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); }
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); }