public void AddPie(int x, int y, int w, int h, float startAngle, float sweepAngle, PdfBrush color, float width) { PdfPen pen = new PdfPen(color, width); m_grapics.DrawPie(pen, x, y, w, h, startAngle, sweepAngle); }
public ActionResult InteractiveFeatures(string InsideBrowser) { #region Field Definitions document = new PdfDocument(); document.PageSettings.Margins.All = 0; document.PageSettings.Size = new SizeF(PdfPageSize.A4.Width, 600); interactivePage = document.Pages.Add(); PdfGraphics g = interactivePage.Graphics; RectangleF rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100); PdfBrush whiteBrush = new PdfSolidBrush(white); PdfPen whitePen = new PdfPen(white, 5); PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 25); Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60); Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73); #endregion #region Header g.DrawRectangle(purpleBrush, rect); g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180); g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200)); g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10)); string basePath = _hostingEnvironment.WebRootPath; string dataPath = string.Empty; dataPath = basePath + @"/PDF/"; //Read the file FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130)); #endregion #region Body //Invoice Number Random invoiceNumber = new Random(); g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210)); g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210)); //Current Date PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date"); textBoxField.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); textBoxField.Bounds = new RectangleF(384, 204, 150, 30); textBoxField.ForeColor = new PdfColor(maroonColor); textBoxField.ReadOnly = true; document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); var thisfieldis = this.getField('date'); var theday = util.printd('dddd',newdate); var thedate = util.printd('d',newdate); var themonth = util.printd('mmmm',newdate); var theyear = util.printd('yyyy',newdate); thisfieldis.strokeColor=color.transparent; thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;"); document.Form.Fields.Add(textBoxField); //invoice table PdfLightTable table = new PdfLightTable(); table.Style.ShowHeader = true; g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140)); //Header Style PdfCellStyle headerStyle = new PdfCellStyle(); headerStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); headerStyle.TextBrush = whiteBrush; headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor); headerStyle.BorderPen = new PdfPen(whiteBrush, 0); table.Style.HeaderStyle = headerStyle; //Cell Style PdfCellStyle bodyStyle = new PdfCellStyle(); bodyStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); bodyStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Left); bodyStyle.BorderPen = new PdfPen(whiteBrush, 0); table.Style.DefaultStyle = bodyStyle; table.DataSource = GetProductReport(_hostingEnvironment.WebRootPath); table.Columns[0].Width = 90; table.Columns[1].Width = 160; table.Columns[3].Width = 100; table.Columns[4].Width = 65; table.Style.CellPadding = 3; table.BeginCellLayout += table_BeginCellLayout; PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140)); g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom)); CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, ""); //Send to Server PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline"); sendButton.Bounds = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25); sendButton.BorderColor = white; sendButton.BackColor = maroonColor; sendButton.ForeColor = white; sendButton.Text = "Order Online"; PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php"); submitAction.DataFormat = SubmitDataFormat.Html; sendButton.Actions.MouseUp = submitAction; document.Form.Fields.Add(sendButton); //Order by Mail PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail"); sendMail.Bounds = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25); sendMail.Text = "Order By Mail"; sendMail.BorderColor = white; sendMail.BackColor = maroonColor; sendMail.ForeColor = white; // Create a javascript action. PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");" + "var aSubmitFields = [];" + "for( var i = 0 ; i < this.numFields; i++){" + "aSubmitFields[i] = this.getNthFieldName(i);" + "}" + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}"); sendMail.Actions.MouseUp = javaAction; document.Form.Fields.Add(sendMail); //Print PdfButtonField printButton = new PdfButtonField(interactivePage, "print"); printButton.Bounds = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25); printButton.BorderColor = white; printButton.BackColor = maroonColor; printButton.ForeColor = white; printButton.Text = "Print"; printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); "); document.Form.Fields.Add(printButton); file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file); attachment.ModificationDate = DateTime.Now; attachment.Description = "Specification"; document.Attachments.Add(attachment); //Open Specification PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification"); openSpecificationButton.Bounds = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15); openSpecificationButton.TextAlignment = PdfTextAlignment.Left; openSpecificationButton.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); openSpecificationButton.BorderStyle = PdfBorderStyle.Underline; openSpecificationButton.BorderColor = orangeColor; openSpecificationButton.BackColor = new PdfColor(255, 255, 255); openSpecificationButton.ForeColor = orangeColor; openSpecificationButton.Text = "Open Specification"; openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });"); document.Form.Fields.Add(openSpecificationButton); RectangleF uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20); PdfTextWebLink linkAnnot = new PdfTextWebLink(); linkAnnot.Url = "http://www.adventure-works.com"; linkAnnot.Text = "http://www.adventure-works.com"; linkAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 8); linkAnnot.Brush = PdfBrushes.White; linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location); #endregion #region Footer g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100)); g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180); #endregion //Save the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); document.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; //Close the PDF document. document.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Interactive features.pdf"; return(fileStreamResult); }
public ActionResult DrawingShapes(string InsideBrowser) { // Create a new PDF document. PdfDocument doc = new PdfDocument(); int i; // Create a new page. PdfPage page = doc.Pages.Add(); // Obtain PdfGraphics object. PdfGraphics g = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold); #region Polygon PdfPen pen = new PdfPen(Color.Black); pen.Width = 3; PointF p1 = new PointF(05, 10); PointF p2 = new PointF(05, 10); PointF p3 = new PointF(60, 70); PointF p4 = new PointF(40, 70); PointF[] points = { p1, p2, p3, p4 }; int pointNum = 16; points = new PointF[pointNum]; double f = 360.0 / pointNum * Math.PI / 180.0; const double r = 100; PointF center = new PointF(140, 140); for (i = 0; i < pointNum; ++i) { PointF p = new PointF(); double theta = i * f; p.Y = (float)(Math.Sin(theta) * r + center.Y); p.X = (float)(Math.Cos(theta) * r + center.X); points[i] = p; } PdfSolidBrush brush = new PdfSolidBrush(Color.Green); pen.Color = Color.Brown; pen.Width = 10; pen.LineJoin = PdfLineJoin.Round; g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0)); g.DrawPolygon(pen, brush, points); #endregion #region Pie RectangleF rect = new RectangleF(200, 50, 200, 200); brush.Color = Color.Green; pen.Color = Color.Brown; pen.Width = 10; rect.Location = new PointF(20, 280); pen.LineJoin = PdfLineJoin.Round; g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250)); g.DrawPie(pen, brush, rect, 180, 60); g.DrawPie(pen, brush, rect, 360 - 60, 60); g.DrawPie(pen, brush, rect, 60, 60); #endregion #region Arc g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0)); pen = new PdfPen(Color.Black); pen.Width = 11; pen.LineCap = PdfLineCap.Round; pen.Color = Color.Brown; rect = new RectangleF(310, 40, 200, 200); g.DrawArc(pen, rect, 0, 90); pen.Color = Color.DarkGreen; rect.X -= 10; g.DrawArc(pen, rect, 90, 90); pen.Color = Color.Brown; rect.Y -= 10; g.DrawArc(pen, rect, 180, 90); pen.Color = Color.DarkGreen; rect.X += 10; g.DrawArc(pen, rect, 270, 90); #endregion #region Rectangle rect = new RectangleF(310, 280, 200, 100); brush.Color = Color.Green; pen.Color = Color.Brown; g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255)); g.DrawRectangle(pen, brush, rect); #endregion #region ellipse pen = new PdfPen(Color.Black); rect = new RectangleF(270, 400, 160, 1000); g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390)); PdfEllipse ellipse = new PdfEllipse(rect); PdfLayoutFormat format = new PdfLayoutFormat(); format.Break = PdfLayoutBreakType.FitPage; format.Layout = PdfLayoutType.Paginate; ellipse.Brush = PdfBrushes.Brown; ellipse.Draw(page, 20, 20, format); brush = new PdfSolidBrush(Color.Black); ellipse.Brush = PdfBrushes.DarkGreen; ellipse.Draw(page, 40, 40, format); #endregion #region Transaparency page = doc.Pages[1]; g = page.Graphics; g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80)); PdfBrush gBrush; rect = new RectangleF(10, 150, 100, 100); pen = new PdfPen(Color.Black); gBrush = new PdfSolidBrush(Color.DarkGreen); g.DrawRectangle(pen, gBrush, rect); gBrush = new PdfSolidBrush(Color.Brown); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Brown); g.SetTransparency(0.7f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; gBrush = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal); g.SetTransparency(0.5f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Blue); gBrush = new PdfSolidBrush(Color.Gray); g.SetTransparency(0.25f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Black); gBrush = new PdfSolidBrush(Color.Green); g.SetTransparency(0.1f); g.DrawRectangle(pen, gBrush, rect); #endregion #region Rectangle with Color space PointF location = new PointF(10, 50); page = doc.Pages.Add(); g = page.Graphics; doc.ColorSpace = (PdfColorSpace)i; // SolidBrush gBrush = new PdfSolidBrush(Color.Red); DrawRectangles(location, g, font, gBrush, pen, doc); // LinearGradient location = new PointF(180, 50); PointF point2 = location; point2.X += 180; gBrush = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red); DrawRectangles(location, g, font, gBrush, pen, doc); // Raidal Gradient location = new PointF(360, 50); point2 = location; point2 = new PointF(location.X + 50, location.Y + 50); //point2.Y += 250; //point2.X = 150; gBrush = new PdfRadialGradientBrush(point2, 0, point2, 100, Color.Blue, Color.Red); (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.Both; DrawRectangles(location, g, font, gBrush, pen, doc); g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0)); #endregion //Save the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); doc.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; //Close the PDF document. doc.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Shapes.pdf"; return(fileStreamResult); }
public ActionResult DrawingShapes(string InsideBrowser) { // Create a new PDF document. PdfDocument doc = new PdfDocument(); int i; // Create a new page. PdfPage page = doc.Pages.Add(); // Obtain PdfGraphics object. PdfGraphics g = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14, PdfFontStyle.Bold); #region Polygon PdfPen pen = new PdfPen(Color.Black); pen.Width = 3; PointF p1 = new PointF(05, 10); PointF p2 = new PointF(05, 10); PointF p3 = new PointF(60, 70); PointF p4 = new PointF(40, 70); PointF[] points = { p1, p2, p3, p4 }; int pointNum = 16; points = new PointF[pointNum]; double f = 360.0 / pointNum * Math.PI / 180.0; const double r = 100; PointF center = new PointF(140, 140); for (i = 0; i < pointNum; ++i) { PointF p = new PointF(); double theta = i * f; p.Y = (float)(Math.Sin(theta) * r + center.Y); p.X = (float)(Math.Cos(theta) * r + center.X); points[i] = p; } PdfSolidBrush brush = new PdfSolidBrush(Color.Green); pen.Color = Color.Brown; pen.Width = 10; pen.LineJoin = PdfLineJoin.Round; g.DrawString("Polygon", font, PdfBrushes.DarkBlue, new PointF(50, 0)); g.DrawPolygon(pen, brush, points); #endregion #region Pie RectangleF rect = new RectangleF(200, 50, 200, 200); brush.Color = Color.Green; pen.Color = Color.Brown; pen.Width = 10; rect.Location = new PointF(20, 280); pen.LineJoin = PdfLineJoin.Round; g.DrawString("Pie shape", font, PdfBrushes.DarkBlue, new PointF(50, 250)); g.DrawPie(pen, brush, rect, 180, 60); g.DrawPie(pen, brush, rect, 360 - 60, 60); g.DrawPie(pen, brush, rect, 60, 60); #endregion #region Arc g.DrawString("Arcs", font, PdfBrushes.DarkBlue, new PointF(330, 0)); pen = new PdfPen(Color.Black); pen.Width = 11; pen.LineCap = PdfLineCap.Round; pen.Color = Color.Brown; rect = new RectangleF(310, 40, 200, 200); g.DrawArc(pen, rect, 0, 90); pen.Color = Color.DarkGreen; rect.X -= 10; g.DrawArc(pen, rect, 90, 90); pen.Color = Color.Brown; rect.Y -= 10; g.DrawArc(pen, rect, 180, 90); pen.Color = Color.DarkGreen; rect.X += 10; g.DrawArc(pen, rect, 270, 90); #endregion #region Rectangle rect = new RectangleF(310, 280, 200, 100); brush.Color = Color.Green; pen.Color = Color.Brown; g.DrawString("Simple Rectangle", font, PdfBrushes.DarkBlue, new PointF(310, 255)); g.DrawRectangle(pen, brush, rect); #endregion #region ellipse // Draw a simple ellipse. pen = new PdfPen(Color.Black); rect = new RectangleF(80, 520, 100, 200); //page = doc.Pages[0]; //g = page.Graphics; PdfLinearGradientBrush lgBrush = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.White, 90); brush = new PdfSolidBrush(Color.Black); brush.Color = Color.DarkGreen; pen.Color = Color.Brown; pen.Width = 10.0f; g.DrawString("Ellipse with Gradient", font, PdfBrushes.DarkBlue, new PointF(50, 490)); g.DrawEllipse(pen, lgBrush, rect); rect = new RectangleF(270, 400, 160, 1000); g.DrawString("Shape with pagination", font, PdfBrushes.DarkBlue, new PointF(300, 390)); PdfEllipse ellipse = new PdfEllipse(rect); PdfLayoutFormat format = new PdfLayoutFormat(); format.Break = PdfLayoutBreakType.FitPage; format.Layout = PdfLayoutType.Paginate; ellipse.Brush = PdfBrushes.Brown; ellipse.Draw(page, 20, 20, format); brush = new PdfSolidBrush(Color.Black); ellipse.Brush = PdfBrushes.DarkGreen; ellipse.Draw(page, 40, 40, format); #endregion #region Transaparency page = doc.Pages[1]; g = page.Graphics; g.DrawString("Transparent Rectangles", font, PdfBrushes.DarkBlue, new PointF(50, 80)); PdfBrush gBrush; rect = new RectangleF(10, 150, 100, 100); pen = new PdfPen(Color.Black); gBrush = new PdfSolidBrush(Color.DarkGreen); g.DrawRectangle(pen, gBrush, rect); gBrush = new PdfSolidBrush(Color.Brown); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Brown); g.SetTransparency(0.7f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; gBrush = new PdfLinearGradientBrush(rect, Color.DarkGreen, Color.Brown, PdfLinearGradientMode.BackwardDiagonal); g.SetTransparency(0.5f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Blue); gBrush = new PdfSolidBrush(Color.Gray); g.SetTransparency(0.25f); g.DrawRectangle(pen, gBrush, rect); rect.X += 20; rect.Y += 20; pen = new PdfPen(Color.Black); gBrush = new PdfSolidBrush(Color.Green); g.SetTransparency(0.1f); g.DrawRectangle(pen, gBrush, rect); #endregion #region Rectangle with Color space PointF location = new PointF(10, 50); page = doc.Pages.Add(); g = page.Graphics; doc.ColorSpace = (PdfColorSpace)i; // SolidBrush gBrush = new PdfSolidBrush(Color.Red); DrawRectangles(location, g, font, gBrush, pen, doc); // LinearGradient location = new PointF(180, 50); PointF point2 = location; point2.X += 100; gBrush = new PdfLinearGradientBrush(location, point2, Color.Blue, Color.Red); DrawRectangles(location, g, font, gBrush, pen, doc); // Raidal Gradient location = new PointF(360, 50); point2 = location; point2.Y += 250; point2.X = 150; gBrush = new PdfRadialGradientBrush(point2, 210, point2, 400, Color.Blue, Color.Red); (gBrush as PdfRadialGradientBrush).Extend = PdfExtend.End; DrawRectangles(location, g, font, gBrush, pen, doc); g.DrawString("Rectangle with color spaces", font, PdfBrushes.DarkBlue, new PointF(150, 0)); #endregion //Stream the output to the browser. if (InsideBrowser == "Browser") { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Open)); } else { return(doc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } }