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