private void ToolbarItem_Clicked(object sender, EventArgs e) { try { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); //Draw the text graphics.DrawString($"{income.Text} {expense.Text}", font, PdfBrushes.Black, new PointF(20, 0)); var list2 = new List <Models.PDFrecord>(); foreach (Models.Record r in list) { list2.Add(new Models.PDFrecord() { category = r.category != null ? r.category.name:"other", type = r.type, amount = r.amount, description = r.description, date = r.date }); } //Add list to IEnumerable IEnumerable <object> dataTable = list2; //Assign data source. pdfGrid.DataSource = dataTable; pdfGrid.AllowRowBreakAcrossPages = true; PdfGridStyle gridStyle = new PdfGridStyle(); //Set cell padding, which specifies the space between border and content of the cell gridStyle.CellPadding = new PdfPaddings(6, 6, 6, 6); pdfGrid.Style = gridStyle; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new PointF(20, 20)); //Save the PDF document to stream. MemoryStream stream = new MemoryStream(); doc.Save(stream); //Close the document. doc.Close(true); //Save the stream as a file in the device and invoke it for viewing string filename = $"budgetmeter_report_{range.Text.Replace("/","-")}.pdf"; Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView(filename, "application / pdf", stream); }catch (Exception ex) { Console.WriteLine($"ERROR: {ex}"); } }
private async void Reprtbtn_Clicked(object sender, EventArgs e) { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.arial.ttf"); PdfTemplate header = PdfHelper.AddHeader(doc, "تقرير العملاء", "Ittezan Pos" + " " + DateTime.Now.ToString()); PdfCellStyle headerStyle = new PdfCellStyle(); headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); page.Graphics.DrawPdfTemplate(header, new PointF()); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //String format // PdfFont pdfFont = new PdfTrueTypeFont(fontStream1, 12); //Create a DataTable. DataTable dataTable = new DataTable("EmpDetails"); List <Customer> customerDetails = new List <Customer>(); //Add columns to the DataTable dataTable.Columns.Add("ID"); dataTable.Columns.Add("Name"); dataTable.Columns.Add("Address"); //Add rows to the DataTable. foreach (var item in Clients) { Customer customer = new Customer(); customer.ID = item.id; customer.Name = item.name; customer.Address = item.address; customerDetails.Add(customer); dataTable.Rows.Add(new string[] { customer.ID.ToString(), customer.Name, customer.Address }); } //Assign data source. pdfGrid.DataSource = dataTable; pdfGrid.Headers.Add(1); PdfGridRow pdfGridRowHeader = pdfGrid.Headers[0]; pdfGridRowHeader.Cells[0].Value = "رقم العميل"; pdfGridRowHeader.Cells[1].Value = "إسم العميل"; pdfGridRowHeader.Cells[2].Value = "عنوان العميل"; PdfGridStyle pdfGridStyle = new PdfGridStyle(); pdfGridStyle.Font = new PdfTrueTypeFont(fontStream, 12); PdfGridLayoutFormat format1 = new PdfGridLayoutFormat(); format1.Break = PdfLayoutBreakType.FitPage; format1.Layout = PdfLayoutType.Paginate; PdfStringFormat format = new PdfStringFormat(); format.TextDirection = PdfTextDirection.RightToLeft; format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; pdfGrid.Columns[0].Format = format; pdfGrid.Columns[1].Format = format; pdfGrid.Columns[2].Format = format; pdfGrid.Style = pdfGridStyle; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.Point(0, (int)header.Height + 10), format1); MemoryStream stream = new MemoryStream(); //Save the document. doc.Save(stream); //close the document doc.Close(true); await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("تقرير العملاء.pdf", "application/pdf", stream); }
private async void Button_Clicked(object sender, EventArgs e) { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("IttezanPos.Assets.arial.ttf"); PdfTemplate header = PdfHelper.AddHeader(doc, "الأرصدة الإفتتاحية", "Ittezan Pos" + " " + DateTime.Now.ToString()); PdfCellStyle headerStyle = new PdfCellStyle(); headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); page.Graphics.DrawPdfTemplate(header, new PointF()); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //String format // PdfFont pdfFont = new PdfTrueTypeFont(fontStream1, 12); //Create a DataTable. DataTable dataTable = new DataTable("EmpDetails"); List <SuplierTotalAmount> customerDetails = new List <SuplierTotalAmount>(); //Add columns to the DataTable dataTable.Columns.Add("ID"); dataTable.Columns.Add("Name"); dataTable.Columns.Add("Address"); dataTable.Columns.Add("Total"); //Add rows to the DataTable. foreach (var item in suppliers) { SuplierTotalAmount customer = new SuplierTotalAmount(); customer.name = item.name; customer.remaining = item.remaining; customer.creditorit = item.creditorit; customer.total_amount = item.total_amount; customerDetails.Add(customer); dataTable.Rows.Add(new string[] { customer.total_amount.ToString(), customer.remaining.ToString(), customer.creditorit.ToString(), customer.name }); } //Assign data source. pdfGrid.DataSource = dataTable; pdfGrid.Headers.Add(1); PdfGridRow pdfGridRowHeader = pdfGrid.Headers[0]; pdfGridRowHeader.Cells[3].Value = "الإسم"; pdfGridRowHeader.Cells[2].Value = "المبلغ دائن/ له"; pdfGridRowHeader.Cells[1].Value = "المبلغ المدين / عليه"; pdfGridRowHeader.Cells[0].Value = "الرصيد"; PdfGridStyle pdfGridStyle = new PdfGridStyle(); pdfGridStyle.Font = new PdfTrueTypeFont(fontStream, 12); PdfGridLayoutFormat format1 = new PdfGridLayoutFormat(); format1.Break = PdfLayoutBreakType.FitPage; format1.Layout = PdfLayoutType.Paginate; PdfStringFormat format = new PdfStringFormat(); format.TextDirection = PdfTextDirection.RightToLeft; format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; pdfGrid.Columns[0].Format = format; pdfGrid.Columns[1].Format = format; pdfGrid.Columns[2].Format = format; pdfGrid.Columns[3].Format = format; pdfGrid.Style = pdfGridStyle; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.Point(0, (int)header.Height + 10), format1); MemoryStream stream = new MemoryStream(); //Save the document. doc.Save(stream); //close the document doc.Close(true); await Xamarin.Forms.DependencyService.Get <ISave>().SaveAndView("الأرصدة الإفتتاحية .pdf", "application/pdf", stream); }
public async Task PrintCheck(Order order, string path) { using (CarPartDbContext context = _contextFactory.CreateDbContext()) { if (order == null) { throw new Exception("Вы не выбрали заказ"); } Address address = await context.Address.FirstOrDefaultAsync(x => x.Id == order.Id); order.Address = address; var orderParts = await context.Orders.Where(a => a.Id == order.Id) .Join(context.OrderParts, t => t.Id, x => x.OrderId, (t, x) => new { t, x }) .Join(context.Parts, l => l.x.PartId, k => k.Id, (l, k) => new { l, k }) .Join(context.PartProviders, d => d.l.x.PartId, m => m.PartId, (d, m) => new { d, m }) .Join(context.Providers, z => z.m.ProviderId, u => u.Id, (z, u) => new { PartId = z.d.k.Id, PartName = z.d.k.Name, PartColor = z.d.k.Color, PartInOrder = z.d.l.x.AmountPart, PartPrice = z.d.l.x.Price, PartProvider = z.m.ProviderId, Provider = u.Name } ).ToListAsync(); using (PdfDocument document = new PdfDocument()) { double price = 0; PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont mainFont = new PdfTrueTypeFont(new Font("Arial Unicode MS", 14), true); PdfFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 12), true); graphics.DrawString("Магазин автозапчастей чек", font, PdfBrushes.Black, new PointF(200, 0)); graphics.DrawString($"Номер заказа: {order.Id}", mainFont, PdfBrushes.Black, new PointF(0, 25)); graphics.DrawString($"Дата создания заказа: {order.OrderCreationTime}", mainFont, PdfBrushes.Black, new PointF(0, 40)); graphics.DrawString($"Дата окончания заказа: {order.FinishDate}", mainFont, PdfBrushes.Black, new PointF(0, 55)); graphics.DrawString($"Статус: {order.Status}", mainFont, PdfBrushes.Black, new PointF(0, 70)); graphics.DrawString($"Адрес: г. {order.Address.City}, ул. {order.Address.Street} , {order.Address.House}-{order.Address.Apartament}", mainFont, PdfBrushes.Black, new PointF(0, 85)); PdfGrid pdfGrid = new PdfGrid(); DataTable dataTable = new DataTable(); dataTable.Columns.Add("Номер запчасти"); dataTable.Columns.Add("Имя"); dataTable.Columns.Add("Цвет"); dataTable.Columns.Add("Поставщик"); dataTable.Columns.Add("Всего"); dataTable.Columns.Add("Цена за единицу"); foreach (var p in orderParts) { dataTable.Rows.Add(new object[] { p.PartId, p.PartName, p.PartColor, p.Provider, p.PartInOrder, p.PartPrice }); price += p.PartInOrder * p.PartPrice; } PdfGridStyle gridStyle = new PdfGridStyle(); gridStyle.Font = font; pdfGrid.Style = gridStyle; graphics.DrawString($"Итого: {price}", mainFont, PdfBrushes.Black, new PointF(0, 105)); pdfGrid.DataSource = dataTable; pdfGrid.Draw(page, new PointF(0, 125)); document.Save(path); document.Close(true); } } }
private void button5_Click(object sender, EventArgs e) { String ClassID; if (GradeSelector.SelectedIndex == -1 || ClassSelector.SelectedIndex == -1) { Grade = 1; ClassID = "A"; } else { Grade = Int32.Parse(GradeSelector.SelectedItem.ToString()); ClassID = ClassSelector.SelectedItem.ToString(); } con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select TimeSlot , Monday , Tuesday , Wednesday , Thursday , Friday from dbo.TTable where ClassID = '" + ClassID + "' AND Grade = " + Grade; cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); con.Close(); if (dt.Rows.Count > 0) { //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); PdfPageTemplateElement header = AddHeader(doc); //Create a DataTable DataTable dataTable = dt; //Assign data source pdfGrid.DataSource = dataTable; //Initialize grid style. PdfGridStyle gridStyle = new PdfGridStyle(); //Add cell padding. gridStyle.CellPadding = new PdfPaddings(5, 5, 5, 5); //Apply style to grid. pdfGrid.Style = gridStyle; //Draw grid to the page of PDF document pdfGrid.Draw(page, new PointF(10, 10)); //Save the document String outputName = "Timetable" + Guid.NewGuid().ToString("N") + ".pdf"; doc.Save(outputName); //Close the document doc.Close(true); System.Diagnostics.Process.Start(outputName); } else { MessageBox.Show("There is no timetable to display as a pdf"); } }
public ActionResult DownloadPDF(int orderId) { var order = orderRepository.GetOrderDetailsById(orderId); int ShipingCharge = Convert.ToInt32(configuration["shippingCharge"]); PdfDocument document = new PdfDocument(); //Adds page settings document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 50; //Adds a page to the document PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 35, PdfFontStyle.Bold); //Draw the text graphics.DrawString("Prince Fashion!", font, PdfBrushes.Gray, new PointF(120, 5)); FileStream imageStream = new FileStream("wwwroot/images/logo.png", FileMode.Open, FileAccess.Read); RectangleF bounds = new RectangleF(10, 0, 80, 40); PdfImage image = PdfImage.FromStream(imageStream); //Draws the image to the PDF page page.Graphics.DrawImage(image, bounds); PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(116, 152, 190)); bounds = new RectangleF(0, bounds.Bottom + 50, graphics.ClientSize.Width, 40); //Draws a rectangle to place the heading in that region. graphics.DrawRectangle(solidBrush, bounds); //Creates a font for adding the heading in the page PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); //Creates a text element to add the invoice number PdfTextElement element1; if (order.OrderType.Equals("DoneOnlinepayment")) { element1 = new PdfTextElement("Type :: " + order.OrderType, subHeadingFont); } else { element1 = new PdfTextElement("Type :: COD "); } element1.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold); element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); element1.Draw(page, new PointF(graphics.ClientSize.Width - 250, bounds.Top - 40)); PdfTextElement element = new PdfTextElement("INVOICE " + orderId, subHeadingFont); element.Brush = PdfBrushes.White; //Draws the heading on the page PdfLayoutResult result = element.Draw(page, new PointF(10, bounds.Top + 8)); string currentDate = "DATE " + DateTime.Now.ToString("dd/MM/yyyy"); //Measures the width of the text to place it in the correct location SizeF textSize = subHeadingFont.MeasureString(currentDate); PointF textPosition = new PointF(graphics.ClientSize.Width - textSize.Width - 10, result.Bounds.Y); //Draws the date by using DrawString method graphics.DrawString(currentDate, subHeadingFont, element.Brush, textPosition); PdfFont timesRoman = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); //Creates text elements to add the address and draw it to the page. element = new PdfTextElement("BILL TO ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(126, 155, 203)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25)); element = new PdfTextElement("Name :: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 5)); element = new PdfTextElement(order.FirstName.ToUpper() + " " + order.LastName.ToUpper(), timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 40, result.Bounds.Bottom - 10)); element = new PdfTextElement("Mob No :: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 200, result.Bounds.Bottom - 10)); element = new PdfTextElement(order.PhoneNumber, timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10)); element = new PdfTextElement("Address :: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 5)); element = new PdfTextElement(order.AddressLine1 + " , " + order.AddressLine2, timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10)); element = new PdfTextElement("Email Id:: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 195, result.Bounds.Bottom - 10)); element = new PdfTextElement(order.Email, timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(result.Bounds.Left + 45, result.Bounds.Bottom - 10)); element = new PdfTextElement(order.City + " , " + order.State + " -" + order.ZipCode, timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(55, result.Bounds.Bottom + 5)); element = new PdfTextElement(order.Country, timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(55, result.Bounds.Bottom + 5)); PdfPen linePen = new PdfPen(new PdfColor(126, 151, 173), 0.70f); PointF startPoint = new PointF(0, result.Bounds.Bottom + 3); PointF endPoint = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 3); //Draws a line at the bottom of the address graphics.DrawLine(linePen, startPoint, endPoint); DataTable dt = new DataTable(); dt.Columns.Add("Product Code"); dt.Columns.Add("Product Disc"); dt.Columns.Add("Price"); dt.Columns.Add("Discount"); dt.Columns.Add("Discount Price"); foreach (var p in order.OrderLines) { float discountPrice = (float)Math.Round(p.Product.Price - p.Product.Price * p.Product.Discount / 100, 2); dt.Rows.Add(p.Product.ProductName, p.Product.ShortDescription, "Rs. " + p.Product.Price, p.Product.Discount + " %", "Rs. " + discountPrice); } if (order.OrderType.Equals("codpayment")) { dt.Rows.Add("Shipping Charge", "", "Rs. " + ShipingCharge, "", "Rs. " + ShipingCharge); } DataTable invoiceDetails = dt; //Creates a PDF grid PdfGrid grid = new PdfGrid(); //Adds the data source grid.DataSource = invoiceDetails; //Creates the grid cell styles PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; //Creates the header style PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(126, 155, 203)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 155, 203)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); //Adds cell customizations for (int i = 0; i < header.Cells.Count; i++) { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); } //Applies the header style header.ApplyStyle(headerStyle); PdfGridStyle gridStyle = new PdfGridStyle(); gridStyle.CellPadding = new PdfPaddings(2, 2, 2, 2); gridStyle.CellSpacing = 1; grid.Style = gridStyle; PdfStringFormat stringFormat = new PdfStringFormat(); stringFormat.Alignment = PdfTextAlignment.Left + 5; stringFormat.LineAlignment = PdfVerticalAlignment.Middle; //Apply string formatting for whole table for (int i = 0; i < grid.Columns.Count; i++) { grid.Columns[i].Format = stringFormat; } grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136)); //Creates the layout format for grid PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); // Creates layout format settings to allow the table pagination layoutFormat.Layout = PdfLayoutType.Paginate; //Draws the grid to the PDF page. PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100)), layoutFormat); element = new PdfTextElement("Total Price:: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(graphics.ClientSize.Width - 200, gridResult.Bounds.Bottom + 10)); element = new PdfTextElement("Rs. " + order.OrderTotal.ToString("0.00"), timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(graphics.ClientSize.Width - 140, result.Bounds.Bottom - 10)); element = new PdfTextElement("Total Product:: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(graphics.ClientSize.Width - 500, gridResult.Bounds.Bottom + 10)); element = new PdfTextElement(order.TotalItem.ToString("0"), timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(graphics.ClientSize.Width - 420, result.Bounds.Bottom - 10)); element = new PdfTextElement("OrderDate:: ", timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(10, gridResult.Bounds.Bottom + 10)); element = new PdfTextElement(order.OrderPlacedDate.ToString("dd/MM/yyyy"), timesRoman); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new PointF(60, result.Bounds.Bottom - 10)); element1.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Bold); element1 = new PdfTextElement("Thanks,", subHeadingFont); element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element1.Draw(page, new PointF(graphics.ClientSize.Width - 130, result.Bounds.Bottom + 20)); element1 = new PdfTextElement("Prince Digital,Surat", subHeadingFont); element1.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element1.Draw(page, new PointF(graphics.ClientSize.Width - 130, result.Bounds.Bottom + 1)); MemoryStream stream = new MemoryStream(); document.Save(stream); //Set the position as '0'. stream.Position = 0; //Download the PDF document in the browser FileStreamResult fileStreamResult = new FileStreamResult(stream, "application/pdf"); string FileName = "order_" + order.OrderId + ".pdf"; fileStreamResult.FileDownloadName = FileName; return(fileStreamResult); }
protected void btnDownload_Click(object sender, EventArgs e) { using (PdfDocument document = new PdfDocument()) { PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; //Drawing the logo image on the top PdfBitmap image = new PdfBitmap(Server.MapPath("~/Images/Logo.jpg")); graphics.DrawImage(image, 110, 0, 300, 100); //Drawing a rectangle below the logo in Coral color RectangleF bounds = new RectangleF(0, 100, graphics.ClientSize.Width, 30); PdfBrush brush = new PdfSolidBrush(new PdfColor(Color.Coral)); graphics.DrawRectangle(brush, bounds); //Loading data from Database into DataSet by calling the GetInvoiceDetails method ds = GetInvoiceDetails(ddlInvoice.SelectedValue); //Creating PdfTextElement objects and placing them on the document PdfFont textFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); PdfTextElement element = new PdfTextElement("INVOICE ID: " + ddlInvoice.SelectedValue, textFont); element.Brush = PdfBrushes.White; PdfLayoutResult result = element.Draw(page, new PointF(10, bounds.Top + 8)); string invoiceDate = "INVOICE DATE: " + ds.Tables[0].Rows[0][0]; SizeF textSize = textFont.MeasureString(invoiceDate); element = new PdfTextElement(invoiceDate, textFont); element.Brush = PdfBrushes.White; result = element.Draw(page, bounds.Width - textSize.Width - 10, bounds.Top + 8); element = new PdfTextElement("BILL TO:", textFont); element.Brush = PdfBrushes.Blue; result = element.Draw(page, 10, result.Bounds.Bottom + 20); //byte[] imageData = (byte[])ds.Tables[1].Rows[0][3]; //MemoryStream ms = new MemoryStream(imageData); //PdfBitmap customerImage = new PdfBitmap(ms); //graphics.DrawImage(customerImage, 410, result.Bounds.Bottom - 14, 100, 100); element = new PdfTextElement(ds.Tables[1].Rows[0][0].ToString(), textFont); result = element.Draw(page, 15, result.Bounds.Bottom); element = new PdfTextElement(ds.Tables[1].Rows[0][1].ToString(), textFont); result = element.Draw(page, 15, result.Bounds.Bottom); element = new PdfTextElement(ds.Tables[1].Rows[0][2].ToString(), textFont); result = element.Draw(page, 15, result.Bounds.Bottom); PdfPen linePen = new PdfPen(new PdfColor(Color.Coral), 0.75f); PointF startPoint = new PointF(0, result.Bounds.Bottom + 50); PointF endPoint = new PointF(graphics.ClientSize.Width, result.Bounds.Bottom + 50); graphics.DrawLine(linePen, startPoint, endPoint); DataTable invoiceDetails = ds.Tables[2]; PdfGrid grid = new PdfGrid(); grid.DataSource = invoiceDetails; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); PdfGridRow header = grid.Headers[0]; for (int i = 0; i < header.Cells.Count; i++) { header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); } header.ApplyStyle(headerStyle); PdfGridColumnCollection columns = grid.Columns; columns[2].Format.Alignment = PdfTextAlignment.Right; columns[3].Format.Alignment = PdfTextAlignment.Right; columns[4].Format.Alignment = PdfTextAlignment.Right; PdfGridStyle cellStyle = new PdfGridStyle(); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f, PdfFontStyle.Regular); cellStyle.TextBrush = PdfBrushes.DarkGreen; grid.Style = cellStyle; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 60), new SizeF(graphics.ClientSize.Width, graphics.ClientSize.Height - 100))); linePen = new PdfPen(new PdfColor(Color.Coral), 0.75f); startPoint = new PointF((gridResult.Bounds.Width / 5) * 4, gridResult.Bounds.Bottom + 20); endPoint = new PointF(graphics.ClientSize.Width, gridResult.Bounds.Bottom + 20); graphics.DrawLine(linePen, startPoint, endPoint); element = new PdfTextElement("TotalBill:", textFont); result = element.Draw(page, new PointF((gridResult.Bounds.Width / 5) * 3, gridResult.Bounds.Bottom + 25)); string billAmount = ds.Tables[3].Rows[0][0].ToString(); textSize = textFont.MeasureString(billAmount); element = new PdfTextElement(billAmount, textFont); result = element.Draw(page, new PointF(graphics.ClientSize.Width - textSize.Width, gridResult.Bounds.Bottom + 25)); linePen = new PdfPen(new PdfColor(Color.Coral), 0.75f); startPoint = new PointF((gridResult.Bounds.Width / 5) * 4, gridResult.Bounds.Bottom + 45); endPoint = new PointF(graphics.ClientSize.Width, gridResult.Bounds.Bottom + 45); graphics.DrawLine(linePen, startPoint, endPoint); string signature = "Signature"; textSize = textFont.MeasureString(signature); element = new PdfTextElement(signature, textFont); result = element.Draw(page, new PointF(graphics.ClientSize.Width - textSize.Width - 20, gridResult.Bounds.Bottom + 100)); linePen = new PdfPen(new PdfColor(Color.Coral), 0.75f); startPoint = new PointF(0, graphics.ClientSize.Height - 25); endPoint = new PointF(graphics.ClientSize.Width, graphics.ClientSize.Height - 25); graphics.DrawLine(linePen, startPoint, endPoint); graphics.DrawString("13-74/292, Diamond Towers, Jubliee Hills - 33. Phone: 2381 9999, Fax: 2381 8899", new PdfStandardFont(PdfFontFamily.Courier, 10), PdfBrushes.DarkCyan, new PointF(0, graphics.ClientSize.Height - 20)); graphics.DrawString("Email: [email protected], WebSite: www.paintcompany.com", new PdfStandardFont(PdfFontFamily.Courier, 10), PdfBrushes.DarkCyan, new PointF(0, graphics.ClientSize.Height - 10)); PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; document.Save("Invoice.pdf", HttpContext.Current.Response, HttpReadType.Save); }; }