void Pdf_Clicked(object sender, EventArgs args) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); g.DrawRectangle(new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 20)); PdfGrid grid = new PdfGrid(); grid.DataSource = GetDataSource(); PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(126, 151, 173)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } header.ApplyStyle(headerStyle); cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(131, 130, 136)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); if (i > 1) { float val = float.MinValue; float.TryParse(cell.Value.ToString(), out val); cell.Value = "$" + val.ToString(); } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + 40), new Syncfusion.Drawing.SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) pos += grid.Columns[i].Width; PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f); gridResult.Page.Graphics.DrawString("Total Due", font, new PdfSolidBrush(new PdfColor(126, 151, 173)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 12), new PdfSolidBrush(new PdfColor(89, 89, 93)), new Syncfusion.Drawing.PointF(pos - 55, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$13600", font, new PdfSolidBrush(new PdfColor(131, 130, 136)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 20), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); MemoryStream data = new MemoryStream(); document.Save(data); document.Close(); DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data); }
public PrintBill(ObservableCollection <printBillData> finalBillOrderPrint, string name, string total) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); PdfFont font2 = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Courier, 7); PdfPen pen = new PdfPen(System.Drawing.Color.Black); graphics.DrawString("High on Flavours", font, PdfBrushes.Black, new PointF(190, 0)); graphics.DrawString("experience India ...", font2, PdfBrushes.Black, new PointF(300, 20)); graphics.DrawString("Bonhoefferstraße 4/1, 69123 Heidelberg", font3, PdfBrushes.Black, new PointF(185, 40)); graphics.DrawString("Ph no: +49 12345678910 Email: [email protected]", font3, PdfBrushes.Black, new PointF(150, 50)); graphics.DrawLine(pen, new PointF(0, 60), new PointF(950, 60)); graphics.DrawLine(pen, new PointF(0, page.Graphics.ClientSize.Height - 100), new PointF(950, page.Graphics.ClientSize.Height - 100)); graphics.DrawString("Total: " + total + " EURO", font2, PdfBrushes.Black, new PointF(400, page.Graphics.ClientSize.Height - 80)); PdfGrid grid = new PdfGrid(); grid.DataSource = finalBillOrderPrint; PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.OnePage; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, 75), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat); doc.Save(name + ".pdf"); System.Diagnostics.Process.Start(name + ".pdf"); doc.Close(true); }
protected void Button3_Click(object sender, EventArgs e) { PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Columns.Add("Job"); dt.Columns.Add("Salary"); dt.Rows.Add(1001, "Scott", "CEO", 50000); dt.Rows.Add(1002, "Smith", "President", 40000); dt.Rows.Add(1003, "Blake", "Manager", 30000); dt.Rows.Add(1004, "Jane", "Analyst", 15000); dt.Rows.Add(1005, "Thomas", "Salesman", 10000); dt.Rows.Add(1006, "Stefen", "Salesman", 10000); dt.Rows.Add(1007, "Mary", "Admin", 8000); dt.Rows.Add(1008, "Diana", "Admin", 8000); dt.Rows.Add(1009, "Peter", "Clerk", 5000); dt.Rows.Add(1010, "David", "Clerk", 5000); PdfGrid grid = new PdfGrid(); grid.DataSource = dt; grid.Draw(page, new PointF(0, 0)); document.Save("Thrid.pdf", HttpContext.Current.Response, HttpReadType.Save); document.Close(); }
public void CreatePDFwithTable() { //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 a DataTable. DataTable dataTable = new DataTable(); //Add columns to the DataTable dataTable.Columns.Add("ID"); dataTable.Columns.Add("Name"); //Add rows to the DataTable. dataTable.Rows.Add(new object[] { "E01", "Clay" }); dataTable.Rows.Add(new object[] { "E02", "Thomas" }); dataTable.Rows.Add(new object[] { "E03", "Andrew" }); dataTable.Rows.Add(new object[] { "E04", "Paul" }); dataTable.Rows.Add(new object[] { "E05", "Gary" }); //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new PointF(10, 10)); //Save the document. doc.Save("Output.pdf"); //close the document doc.Close(true); }
private void CreatePDF(object data) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfGrid pdfGrid = new PdfGrid { DataSource = data }; pdfGrid.Draw(page, new PointF(10, 10)); string folderPath = "C:\\PdfTest\\"; if (!System.IO.Directory.Exists(folderPath)) { System.IO.Directory.CreateDirectory(folderPath); } string fullPath = folderPath + "Reporte_de_rentas_" + DateTime.Now.ToString("ddMMyyyy_HHmmss") + ".pdf"; doc.Save(fullPath); doc.Close(true); var wb = new WebBrowser(); wb.Navigate(fullPath); }
//public async Task<IActionResult> Export(Employee employee) //{ // using (var workbook = new XLWorkbook()) // { // var worksheet = workbook.Worksheets.Add("Employee"); // var currentRow = 1; // #region Header // worksheet.Cell(currentRow, 1).Value = "Фамилия"; // worksheet.Cell(currentRow, 2).Value = "Имя"; // worksheet.Cell(currentRow, 3).Value = "Отчество"; // #endregion // #region Body // foreach (var employeee in _context.Employees) // { // currentRow++; // worksheet.Cell(currentRow, 1).Value = employeee.Surname; // worksheet.Cell(currentRow, 2).Value = employeee.Name; // worksheet.Cell(currentRow, 3).Value = employeee.Second_Name; // } // #endregion // using (var stream = new MemoryStream()) // { // workbook.SaveAs(stream); // var content = stream.ToArray(); // return File( // content, // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // "Employee.xlsx" // ); // } // } //} public IActionResult CreateDocument() { _context.Zadachis.Load(); PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Add list to IEnumerable IEnumerable <Zadachi> dataTable = _context.Zadachis; //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); }
private void PrintToPdf(object sender, RoutedEventArgs e) { try { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PDF Files (*.pdf)|*.pdf"; saveFileDialog.DefaultExt = "pdf"; saveFileDialog.AddExtension = true; if (saveFileDialog.ShowDialog() == true) { //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); //Assign data source pdfGrid.DataSource = DataGrid.ItemsSource; //Draw grid to the page of PDF document pdfGrid.Draw(page, new PointF(10, 10)); //Save the document doc.Save(saveFileDialog.FileName); //Close the document doc.Close(true); } } catch (Exception ex) { _logger.Error(ex); } }
//Export weather data to PDF document. public MemoryStream CreatePdf(WeatherForecast[] forecasts) { if (forecasts == null) { throw new ArgumentNullException("Forecast cannot be null"); } //Create a new PDF document using (PdfDocument pdfDocument = new PdfDocument()) { int paragraphAfterSpacing = 8; int cellMargin = 8; // pdfDocument.PageSettings.Size = PdfPageSize.A4; //Add page to the PDF document PdfPage page = pdfDocument.Pages.Add(); //Create a new font PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); //Create a text element to draw a text in PDF page PdfTextElement title = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black); PdfLayoutResult result = title.Draw(page, new PointF(0, 0)); PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); PdfTextElement content = new PdfTextElement("This component demonstrates fetching data from a service and Exporting the data to PDF document using Syncfusion .NET PDF library.", contentFont, PdfBrushes.Black); PdfLayoutFormat format = new PdfLayoutFormat(); format.Layout = PdfLayoutType.Paginate; //Draw a text to the PDF document result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); pdfGrid.Style.CellPadding.Left = cellMargin; pdfGrid.Style.CellPadding.Right = cellMargin; //Applying built-in style to the PDF grid pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); //Assign data source pdfGrid.DataSource = forecasts; pdfGrid.Style.Font = contentFont; //Draw PDF grid into the PDF page pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + paragraphAfterSpacing)); using (MemoryStream stream = new MemoryStream()) { //Saving the PDF document into the stream pdfDocument.Save(stream); //Closing the PDF document pdfDocument.Close(true); return(stream); } } }
public ActionResult CreateDocument() { PdfDocument doc = new PdfDocument(); //Add a page to the document. PdfPage page = doc.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; PdfGrid pdfGrid = new PdfGrid(); //FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read); //PdfBitmap image = new PdfBitmap(imageStream); ////Draw the image //graphics.DrawImage(image, 0, 0); //using (AppDbContext context = new AppDbContext()) //{ //} //List<Order> orders = new List<Order>(); //foreach (DataTable table in data.Tables) //{ // foreach (DataRow row in table.Rows) // { // Order order = new Order() // { // OrderId = int.Parse(row["OrderId"].ToString()), // FirstName = row["FirstName"].ToString(), // LastName = row["LastName"].ToString(), // AddressLine1 = row["AddressLine1"].ToString(), // ZipCode = row["ZipCode"].ToString(), // PhoneNumber = row["PhoneNumber"].ToString(), // OrderPlaced = DateTime.Parse(row["OrderDetails"].ToString()), // OrderTotal = decimal.Parse(row["OrderTotal"].ToString()) // }; // orders.Add(order); // } //} //IEnumerable<Object> datatable = orders; //pdfGrid.DataSource = datatable; pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); }
private static async Task CreatePDFAsync() { PdfDocument document = new PdfDocument(); //Add a page to the document. PdfPage page = document.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. graphics.DrawString("This is a grid", font, PdfBrushes.Black, new PointF(10, 10)); var pdfBitmap1 = await GetPdfBitmap("watch"); graphics.DrawImage(pdfBitmap1, 10, 60, 120, 120); //Creates the PdfGrid PdfGrid pdfGrid = new PdfGrid(); //Adds the columns pdfGrid.Columns.Add(); pdfGrid.Columns.Add(); pdfGrid.Columns[0].Width = 50; //Adding grid cell style PdfGridCellStyle rowStyle = new PdfGridCellStyle(); //Creating Border PdfBorders border = new PdfBorders(); border.All = PdfPens.Blue; //setting border to the style rowStyle.Borders = border; //Adds the row and value to the cell for (int i = 0; i < 10; i++) { PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); pdfGrid.Rows[i].Height = 80; pdfGridRow.Cells[1].Value = "asdf asdf"; //pdfGridRow.Cells[0].Style = rowStyle; pdfGridRow.Cells[1].Style = rowStyle; //Applies the image pdfGrid.Rows[i].Cells[0].Style.BackgroundImage = pdfBitmap1; pdfGrid.Rows[i].Cells[0].Value = ""; } //Draws the Grid pdfGrid.Draw(page, new PointF(10, 200)); await SaveFile(document); }
//[HttpPost] //[ValidateInput(false)] //public FileResult Export(string GridHtml) //{ // using (MemoryStream stream = new System.IO.MemoryStream()) // { // StringReader sr = new StringReader(GridHtml); // Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); // PdfWriter writer = PdfWriter.GetInstance(pdfDoc, stream); // pdfDoc.Open(); // XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr); // pdfDoc.Close(); // return File(stream.ToArray(), "application/pdf", "Grid.pdf"); // } //} public FileResult CreateDocument() { using (PdfDocument document = new PdfDocument()) { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Adds page settings document.PageSettings.Orientation = PdfPageOrientation.Landscape; document.PageSettings.Margins.All = 50; //Add a page. PdfPage page = doc.Pages.Add(); PdfGraphics graphics = page.Graphics; //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); PdfImage image = PdfImage.FromFile(Server.MapPath("../Content/img/índice.png")); RectangleF bounds = new RectangleF(0, 0, 150, 150); //Draws the image to the PDF page page.Graphics.DrawImage(image, bounds); //Create a DataTable. DataTable dataTable = new DataTable(); //Add columns to the DataTable dataTable.Columns.Add("IdVenta"); dataTable.Columns.Add("Nombre Producto"); dataTable.Columns.Add("Descripcion"); dataTable.Columns.Add("Precio"); dataTable.Columns.Add("Fecha"); dataTable.Columns.Add("Cantidad"); dataTable.Columns.Add("Total"); //Add rows to the DataTable. ML.DetalleVenta detalleVenta = new ML.DetalleVenta(); detalleVenta.Venta = new ML.Venta(); detalleVenta.Producto = new ML.Producto(); ML.Result result = BL.DetalleVenta.GetAll(); detalleVenta.DetalleVentas = result.Objects; foreach (ML.DetalleVenta detalle in detalleVenta.DetalleVentas) { dataTable.Rows.Add(new object[] { detalle.Venta.IdVenta, detalle.Producto.Nombre, detalle.Producto.Descripcion, detalle.Producto.Precio, detalle.Venta.Fecha, detalle.Cantidad, detalle.Venta.Total }); } //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new PointF(10, 10)); // Open the document in browser after saving it doc.Save("Output.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save); //close the document doc.Close(true); } return(null); }
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}"); } }
public IActionResult generatePDF() { PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); PdfGraphics graphics = page.Graphics; //Load the image as stream. FileStream imageStream = new FileStream("wwwroot/images/logo2.png", FileMode.Open, FileAccess.Read); PdfBitmap image = new PdfBitmap(imageStream); graphics.DrawImage(image, 0, 0); PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(126, 151, 173)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(126, 151, 173)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f, PdfFontStyle.Regular); //Add values to list //List<object> data = new List<object>(); var list_all = _context.Shop_items.ToList(); //Object row1 = new { ID = "E01", Name = "Clay" }; //Object row2 = new { ID = "E02", Name = "Thomas" }; //Object row3 = new { ID = "E03", Name = "Andrew" }; //Object row4 = new { ID = "E04", Name = "Paul" }; //Object row5 = new { ID = "E05", Name = "Gray" }; //data.Add(row1); //data.Add(row2); //data.Add(row3); //data.Add(row4); //data.Add(row5); //Add list to IEnumerable IEnumerable <object> dataTable = list_all; //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); }
public static PdfPageTemplateElement AddFooter(PdfDocument doc, string strFooterLine1, string strFooterLine2, string strFooterLine3) { RectangleF rect = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50); //Create a page template PdfPageTemplateElement footer = new PdfPageTemplateElement(rect); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); //Add three columns pdfGrid.Columns.Add(1); //create and customize the string formats PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; //Create the font for setting the style PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8, PdfFontStyle.Bold | PdfFontStyle.Italic); //Add rows PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Cells[0].Value = spFooterLine1; pdfGridRow.Cells[0].Style.Font = font; pdfGridRow.Cells[0].Style.TextBrush = PdfBrushes.Red; //Add rows PdfGridRow pdfGridRow1 = pdfGrid.Rows.Add(); pdfGridRow1.Cells[0].Value = spFooterLine2; //Add rows PdfGridRow pdfGridRow2 = pdfGrid.Rows.Add(); pdfGridRow2.Cells[0].Value = spFooterLine3; for (int i = 0; i < pdfGrid.Rows.Count; i++) { PdfGridRow row = pdfGrid.Rows[i]; for (int j = 0; j < row.Cells.Count; j++) { row.Cells[j].StringFormat = format; row.Cells[j].Style.Borders.All = PdfPens.Transparent; } } //Draw grid to the page of PDF document pdfGrid.Draw(footer.Graphics); return(footer); }
public void ExportToPdf(List <T> entities, string reportTitle, ReportRequest reportRequest, List <string> columns) { int paragraphAfterSpacing = 8; int cellMargin = 8; PdfDocument pdfDocument = new PdfDocument(); //Add Page to the PDF document. PdfPage page = pdfDocument.Pages.Add(); //Create a new font. PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); //Create a text element to draw a text in PDF page. PdfTextElement title = new PdfTextElement(reportTitle, font, PdfBrushes.Black); PdfLayoutResult result = title.Draw(page, new PointF(0, 0)); var contentInfo = CreateContentInfo(reportRequest, entities); PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); PdfTextElement content = new PdfTextElement(contentInfo, contentFont, PdfBrushes.Black); PdfLayoutFormat format = new PdfLayoutFormat(); format.Layout = PdfLayoutType.Paginate; //Draw a text to the PDF document. result = content.Draw(page, new RectangleF(0, result.Bounds.Bottom + paragraphAfterSpacing, page.GetClientSize().Width, page.GetClientSize().Height), format); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); pdfGrid.Style.CellPadding.Left = cellMargin; pdfGrid.Style.CellPadding.Right = cellMargin; //Applying built-in style to the PDF grid pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); //Create data to populate table DataTable table = CreateDataSourceTable(entities, columns); //Assign data source. pdfGrid.DataSource = table; pdfGrid.Style.Font = contentFont; //Draw PDF grid into the PDF page. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, result.Bounds.Bottom + paragraphAfterSpacing)); MemoryStream memoryStream = new MemoryStream(); // Save the PDF document. pdfDocument.Save(memoryStream); // Download the PDF document _jsRuntime.SaveAs(reportTitle + ".pdf", memoryStream.ToArray()); }
public MemoryStream CreatePdf(WeatherForecast[] weatherForecasts) { if (weatherForecasts == null) { throw new ArgumentException("Data cannot be null"); } //Create a new PDF document using (PdfDocument pdfDocument = new PdfDocument()) { int paragraphAfterSpacing = 8; int cellMargin = 8; //Add page to the pdf Document PdfPage page = pdfDocument.Pages.Add(); //create New Font PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 16); //Create a text elemet to draw a text in PDf Page PdfTextElement title = new PdfTextElement("Weather Forecast", font, PdfBrushes.Black); PdfLayoutResult result = title.Draw(page, new PointF(0, 0)); PdfStandardFont contentFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 12); PdfLayoutFormat format = new PdfLayoutFormat(); format.Layout = PdfLayoutType.Paginate; //Create PDF PdfGrid pdfGrid = new PdfGrid(); pdfGrid.Style.CellPadding.Left = cellMargin; pdfGrid.Style.CellPadding.Right = cellMargin; //Apply built in Styke to the PDF grid pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1); //Assing Data Source pdfGrid.DataSource = weatherForecasts.ToList(); pdfGrid.Style.Font = contentFont; //Draw PDf Grid into the pdf Page pdfGrid.Draw(page, new PointF(0, result.Bounds.Bottom + paragraphAfterSpacing)); using (MemoryStream stream = new MemoryStream()) { pdfDocument.Save(stream); pdfDocument.Close(true); return(stream); } } }
private void GeneratePDF() { //Stream fontStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("Sample.Assets.arial.ttf"); //PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 12); //Create a new PDF document using (PdfDocument doc = new PdfDocument()) { //Font initialization. System.Drawing.Font tempfont = new System.Drawing.Font("/App_Data/ARIALUNI.ttf", 11, FontStyle.Regular); //Enable unicode to draw unicode characters. PdfTrueTypeFont currentFont = new PdfTrueTypeFont(tempfont, true); //Add a page PdfPage page = doc.Pages.Add(); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); // RSD --PdfFont font = new PdfTrueTypeFont(Server.MapPath("/App_Data/ARIALUNI.ttf"), 24); // Stream fontStream = typeof(SOSubmitChecklist).GetTypeInfo().Assembly.GetManifestResourceStream("Demo.Assets.arial.ttf"); pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12); //Create a DataTable DataTable SO1CheckList = new DataTable(); dsShowAllDocData = dbFamilyDetailsData.getSO1SubmitCheckList(cmbVillage.SelectedValue.ToString(), cmbDocumentNo.SelectedValue.ToString(), "SO1"); if (dsShowAllDocData.Tables[0].Rows.Count > 0) { SO1CheckList = dsShowAllDocData.Tables[0]; } //Assign data source pdfGrid.DataSource = SO1CheckList; //Draw grid to the page of PDF document pdfGrid.Draw(page, new PointF(20, 10)); //Font pdfGrid.Style.Font = new PdfTrueTypeFont(currentFont, 12); //PdfFont font = new PdfTrueTypeFont(new Font("Arial Unicode MS Regular", 12, FontStyle.Regular), true); PdfTextElement textElement = new PdfTextElement("Unicode characters राजेंद्र "); textElement.Font = new PdfTrueTypeFont(currentFont, 12); textElement.Brush = PdfBrushes.Black; textElement.Draw(page, new PointF(10, 10)); //pdfGrid.PDFFonts = new Dictionary<string, Stream>(StringComparer.OrdinalIgnoreCase); //pdfGrid.PDFFonts.Add("MS Mincho", assembly.GetManifestResourceStream("WinRTSampleApplication.Assets.msmincho.ttf")); //Save the document doc.Save(@"F:\\Output.pdf"); } }
private void OnButtonClick(object sender, RoutedEventArgs e) { //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a new PDF page PdfPage page = doc.Pages.Add(); // Create PDF graphics for a page PdfGraphics graphics = page.Graphics; //Set the standard font PdfFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 20); PdfFont font2 = new PdfStandardFont(PdfFontFamily.TimesRoman, 10); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Courier, 7); PdfPen pen = new PdfPen(System.Drawing.Color.Black); //Draw the text graphics.DrawString("High on Flavours", font, PdfBrushes.Black, new PointF(190, 0)); graphics.DrawString("experience India ...", font2, PdfBrushes.Black, new PointF(300, 20)); graphics.DrawString("Bonhoefferstraße 4/1, 69123 Heidelberg", font3, PdfBrushes.Black, new PointF(185, 40)); graphics.DrawString("Ph no: +49 12345678910 Email: [email protected]", font3, PdfBrushes.Black, new PointF(150, 50)); graphics.DrawLine(pen, new PointF(0, 60), new PointF(950, 60)); graphics.DrawLine(pen, new PointF(0, page.Graphics.ClientSize.Height - 100), new PointF(950, page.Graphics.ClientSize.Height - 100)); graphics.DrawString("Total:", font2, PdfBrushes.Black, new PointF(400, page.Graphics.ClientSize.Height - 80)); //Create a new PDF grid PdfGrid grid = new PdfGrid(); //Add the data source grid.DataSource = finalBillOrder; //Apply built-in grid style //grid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable6Colorful); //Creates the layout format for grid PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); //Set the layout type as paginate layoutFormat.Layout = PdfLayoutType.OnePage; //Draws the grid to the PDF page PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, 75), new SizeF(page.Graphics.ClientSize.Width, page.Graphics.ClientSize.Height - 100)), layoutFormat); //Save the PDF stream to physical file doc.Save("outputGRD.pdf"); System.Diagnostics.Process.Start("outputGRD.pdf"); doc.Close(true); }
/// <summary>Creates the PDF summary.</summary> /// <param name="path">The path.</param> /// <param name="Tourlist">The tourlist.</param> /// <returns> /// <para>No Returnvalue, but may throw a Directory not found Exception</para> /// </returns> public static int CreatePdfSummary(string path, ObservableCollection <Tour> Tourlist) { try { FileStream fs = File.Open(Path.Combine(path, "Report.pdf"), FileMode.Create); if (!fs.CanWrite) { return(-1); } PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); graphics.DrawString("Tour Summary", font, PdfBrushes.Black, new PointF(10, 10)); PdfGrid pdfGrid = new PdfGrid(); //Create a DataTable DataTable dataTable = new DataTable(); //Add columns to the DataTable dataTable.Columns.Add("Name"); dataTable.Columns.Add("Description"); dataTable.Columns.Add("Source"); dataTable.Columns.Add("Destination"); dataTable.Columns.Add("Distance"); dataTable.Columns.Add("Number of Logs"); //Add rows to the DataTable foreach (Tour tl in Tourlist) { dataTable.Rows.Add(tl.PrintToPDF()); } //Assign data source pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 40)); document.Save(fs); document.Close(true); fs.Close(); } catch (Exception e) { throw e; } return(0); }
private async void button2_Click(object sender, RoutedEventArgs e) { //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Create the page PdfPage pdfPage = pdfDocument.Pages.Add(); //Create the parent grid PdfGrid parentPdfGrid = new PdfGrid(); parentPdfGrid.Columns.Add(CellGrid.ColumnCount); //Add the rows for (int i = 0; i < CellGrid.RowCount; i++) { PdfGridRow row1 = parentPdfGrid.Rows.Add(); row1.Height = 50; for (int j = 0; j < CellGrid.ColumnCount; j++) { var style = CellGrid.Model[i, j]; PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j]; pdfGridCell.Value = style.CellValue; var brush = (style.Background as SolidColorBrush); //Export with style if (brush != null) { pdfGridCell.Style.BackgroundBrush = new PdfSolidBrush(new PdfColor(System.Drawing.Color.FromArgb(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B))); } } } //Draw the PdfGrid. parentPdfGrid.Draw(pdfPage, PointF.Empty); StorageFile storageFile; StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting); //Save the document. await pdfDocument.SaveAsync(storageFile); FileStream stream = File.OpenRead(storageFile.Path); this.pdfViewer.Unload(); this.pdfViewer.LoadDocument(stream); //Print the pdf file. this.pdfViewer.Print(); this.pdfViewer.Visibility = Visibility.Collapsed; }
public IActionResult Post([FromBody] Prescription prescription) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfGrid pdfGrid = new PdfGrid(); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfGraphics graphics = page.Graphics; graphics.DrawString("Prescription from Dr. Sangeetha generated at " + DateTime.Now, font, PdfBrushes.Black, new PointF(0, 0)); List <object> data = new List <object>(); Object row1 = new { ID = "\n PatientName", Name = "\n " + prescription.Name + "\n" }; Object row2 = new { ID = "\n Age & gender", Name = "\n " + prescription.Age + "\n" }; Object row3 = new { ID = "\n Symptoms", Name = "\n " + prescription.Symptoms + "\n" }; Object row4 = new { ID = "\n Diagnosis", Name = "\n " + prescription.Diagnosis + "\n" }; Object row5 = new { ID = "\n Remarks", Name = "\n " + prescription.Remarks + "\n" }; data.Add(row1); data.Add(row2); data.Add(row3); data.Add(row4); data.Add(row5); //Add list to IEnumerable IEnumerable <object> dataTable = data; //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 20)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Prescription.pdf"; return(File(stream, contentType, fileName)); }
private PdfLayoutResult DrawVendor(PdfPageBase page, DataTable vendors, int index, String title, float y) { //draw title PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold)); DataRow row = vendors.Rows[index]; page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y); y = y + font1.MeasureString(title).Height + 1; //draw table Object[][] data = new Object[vendors.Columns.Count][]; for (int i = 0; i < vendors.Columns.Count; i++) { data[i] = new Object[2]; data[i][0] = vendors.Columns[i].ColumnName; data[i][1] = vendors.Rows[index].ItemArray[i]; } PdfGrid grid = new PdfGrid(); grid.Style.CellPadding = new PdfPaddings(2, 2, 1, 1); grid.DataSource = data; float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1) * 0.75f; grid.Columns[0].Width = width * 0.20f; grid.Columns[1].Width = width * 0.80f; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold)); PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f)); for (int i = 0; i < grid.Rows.Count; i++) { grid.Rows[i].Style.Font = font2; grid.Rows[i].Cells[0].Style.BackgroundBrush = PdfBrushes.CadetBlue; grid.Rows[i].Cells[1].Style.BackgroundBrush = PdfBrushes.SkyBlue; } PdfGridLayoutFormat layout = new PdfGridLayoutFormat(); layout.Break = PdfLayoutBreakType.FitPage; layout.Layout = PdfLayoutType.Paginate; return(grid.Draw(page, new PointF(0, y), layout)); }
private async void button2_Click(object sender, RoutedEventArgs e) { //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); //Create the page PdfPage pdfPage = pdfDocument.Pages.Add(); //Create the parent grid PdfGrid parentPdfGrid = new PdfGrid(); //Add the rows for (int i = 0; i < CellGrid.RowCount; i++) { PdfGridRow row1 = parentPdfGrid.Rows.Add(); row1.Height = 50; parentPdfGrid.Columns.Add(CellGrid.ColumnCount); for (int j = 0; j < CellGrid.ColumnCount; j++) { var style = CellGrid.Model[i, j]; PdfGridCell pdfGridCell = parentPdfGrid.Rows[i].Cells[j]; pdfGridCell.Value = style.CellValue; var brush = (style.Background as SolidColorBrush); //Export with style //if (brush != null) // pdfGridCell.Style.BackgroundBrush } } //Draw the PdfGrid. parentPdfGrid.Draw(pdfPage, PointF.Empty); StorageFile storageFile; StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder; storageFile = await local.CreateFileAsync("Sample.pdf", CreationCollisionOption.ReplaceExisting); //Save the document. await pdfDocument.SaveAsync(storageFile); }
public IActionResult ShowAllAdmins() { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //doc.PageSettings.Orientation = PdfPageOrientation.Landscape; //doc.PageSettings.Margins.All = 50; //PdfBrush solidBrush = new PdfSolidBrush(new PdfColor(126, 151, 173)); //RectangleF bounds = new RectangleF(176, 0, 390, 130); //bounds = new Syncfusion.Drawing.RectangleF(0, bounds.Bottom + 90, graphics.ClientSize.Width, 30); //Add a page. PdfPage page = doc.Pages.Add(); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Add values to list var AdminList = _context.Admins.ToListAsync(); //List<Admin> data = AdminList.ToList(); //Add list to IEnumerable IEnumerable <Admin> dataTable = _context.Admins.ToList(); //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "AdminList.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); //return View(); }
public static void createPDFfromList <T>(List <T> items, string title, string location) { //Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page PdfPage page = doc.Pages.Add(); //Create PDF graphics for the page. PdfGraphics graphics = page.Graphics; //Set the standard font. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); //Draw the text. PdfTextElement textElement = new PdfTextElement(title, font); textElement.Draw(graphics, new PointF(200, 0)); //Create a PdfGrid PdfGrid pdfGrid = new PdfGrid(); //Create table from list var myType = typeof(T); DataTable dataTable = new DataTable(); foreach (PropertyInfo info in myType.GetProperties()) { dataTable.Columns.Add(new DataColumn(info.Name, info.PropertyType)); } foreach (var item in items) { DataRow dr = dataTable.NewRow(); foreach (PropertyInfo info in myType.GetProperties()) { dr[info.Name] = info.GetValue(item); } dataTable.Rows.Add(dr); } //Assign data source pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document pdfGrid.Draw(page, new PointF(0, 50)); //Save the document doc.Save(location); //Close the document doc.Close(true); }
public async Task <SuccessResponseDTO <PrintModel> > Handle(PrintPDFCommand request, CancellationToken cancellationToken) { SuccessResponseDTO <PrintModel> successResponseDTO = new SuccessResponseDTO <PrintModel>(); 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 a DataTable DataTable dataTable = new DataTable(); //Add columns to the DataTable dataTable.Columns.Add("GoldPrice"); dataTable.Columns.Add("Weight"); dataTable.Columns.Add("Discount"); dataTable.Columns.Add("Total Price"); //Add rows to the DataTable dataTable.Rows.Add(new object[] { request.GoldPrice, request.Weight, request.Discount, request.TotalPrice }); //Assign data source pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document pdfGrid.Draw(page, 10, 10, 40); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); PrintModel printModel = new PrintModel() { stream = stream }; successResponseDTO = new SuccessResponseDTO <PrintModel>().CreateSuccessResponse(printModel, "500", "document created", "", "", request.TenantName); } catch (Exception ex) { successResponseDTO = new SuccessResponseDTO <PrintModel>().CreateSuccessResponse(null, "500", ex.ToString(), "", "", request.TenantName); } return(successResponseDTO); }
public IActionResult CreateDocument() { //Create a new PDF document. PdfDocument doc = new PdfDocument(); //Add a page. PdfPage page = doc.Pages.Add(); //Create a PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Add values to list // var data = _Context.Students.ToList(); var data = from student in _Context.Students orderby student.FirstMidName descending select new { student.LastName, student.FirstMidName, student.EnrollmentDate, student.Enrollments.Count }; //Add list to IEnumerable IEnumerable <object> dataTable = data; //Assign data source. pdfGrid.DataSource = dataTable; //Draw grid to the page of PDF document. pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10)); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); doc.Save(stream); //If the position is not set to '0' then the PDF will be empty. stream.Position = 0; //Close the document. doc.Close(true); //Defining the ContentType for pdf file. string contentType = "application/pdf"; //Define the file name. string fileName = "Output.pdf"; //Creates a FileContentResult object by using the file contents, content type, and file name. return(File(stream, contentType, fileName)); }
private async void GeneratePDF_Click(object sender, RoutedEventArgs e) { #region Field Definitions IEnumerable <Adventure> products = Provider.GetProducts(); Stream fontStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("SampleBrowser.Pdf.Assets.verdana.ttf"); PdfStandardFont font = new PdfStandardFont(PdfFontFamily.TimesRoman, 8f); #endregion styleName = this.gridBuiltinstyleComboBox.SelectedItem.ToString(); PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); #region PdfGrid grid = new PdfGrid(); grid.DataSource = products; PdfGridBuiltinStyle style = ConvertToPdfGridBuiltinStyle(styleName); PdfGridBuiltinStyleSettings setting = new PdfGridBuiltinStyleSettings(); setting.ApplyStyleForHeaderRow = true; setting.ApplyStyleForBandedRows = true; grid.Style.CellPadding.All = 2; grid.ApplyBuiltinStyle(style, setting); PdfGridLayoutFormat gridLayoutFormat = new PdfGridLayoutFormat(); gridLayoutFormat.Layout = PdfLayoutType.Paginate; gridLayoutFormat.Break = PdfLayoutBreakType.FitElement; grid.Draw(page, PointF.Empty, gridLayoutFormat); #endregion MemoryStream stream = new MemoryStream(); await document.SaveAsync(stream); document.Close(true); SaveFile(stream, "GridBuiltinStyle.pdf"); }
public async Task <IActionResult> OnPostAsync(int orderId) { order = await orderContext.GetOrderById(orderId); if (order == null) { return(RedirectToPage("./NotFound")); } PdfDocument document = new PdfDocument(); PdfPage page = document.Pages.Add(); PdfGrid pdfGrid = new PdfGrid(); DataTable dataTable = new DataTable(); dataTable.Columns.Add("Whiskey Id"); dataTable.Columns.Add("Whiskey Name"); dataTable.Columns.Add("Amount of whiskey"); foreach (var OIT in order.OrderItems) { dataTable.Rows.Add(new object[] { $"{OIT.Id}", $"{OIT.Whiskey.Name}", $"{OIT.Amount}" }); } pdfGrid.DataSource = dataTable; pdfGrid.Draw(page, new PointF(10, 10)); MemoryStream stream = new MemoryStream(); document.Save(stream); stream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(stream, "SjonnieLoper/Pdf"); fileStreamResult.FileDownloadName = $"{order.Id}.pdf"; return(fileStreamResult); }
public void ConvertToPdf(string source, string destination) { try { var excelEngine = new ExcelEngine(); var application = excelEngine.Excel; var workbook = application.Workbooks.Open(source); var worksheet = workbook.Worksheets[0]; var document = new PdfDocument(); var page = document.Pages.Add(); var pdfGrid = new PdfGrid(); pdfGrid.Columns.Add(worksheet.UsedRange.LastColumn); pdfGrid.Headers.Add(1); var pdfGridHeader = pdfGrid.Headers[0]; for (var i = 0; i < worksheet.UsedRange.LastColumn; i++) { pdfGridHeader.Cells[i].Value = worksheet.UsedRange.Columns[i].DisplayText; } //Add rows for (var row = 2; row <= worksheet.UsedRange.LastRow; row++) { var pdfGridRow = pdfGrid.Rows.Add(); for (var col = 1; col <= worksheet.UsedRange.LastColumn; col++) { var text = worksheet[row, col].Text; pdfGridRow.Cells[col - 1].Value = text; } } pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable5DarkAccent6); pdfGrid.Draw(page, PointF.Empty); document.Save(destination); document.Close(true); } catch (Exception ex) { FileLogger.SetLog(string.Format(ExceptionConstants.ConvertToPdf, source, ex.Message)); } }
public static PdfPageTemplateElement AddHeader(PdfDocument doc, string headerLine1, string headerLine2, string headerLine3, string waterMark, string expiryDays) { RectangleF rect = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 55); PdfPageTemplateElement header = new PdfPageTemplateElement(rect); PdfGrid pdfGrid = new PdfGrid(); //Add three columns pdfGrid.Columns.Add(3); PdfBrush brush = new PdfSolidBrush(Color.Black); PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; string dtNow = DateTime.Now.ToShortDateString(); string strSop = "SOP-2023"; //Add rows PdfGridRow pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Cells[0].Value = headerLine1 + ":" + strSop; pdfGridRow.Cells[1].Value = headerLine1; pdfGridRow.Cells[2].Value = headerLine3 + ":" + dtNow; //Create the font for setting the style PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10, PdfFontStyle.Bold); for (int i = 0; i < pdfGrid.Rows.Count; i++) { PdfGridRow row = pdfGrid.Rows[i]; for (int j = 0; j < row.Cells.Count; j++) { row.Cells[j].Style.Font = font; row.Cells[j].StringFormat = format; row.Cells[j].Style.Borders.All = PdfPens.Transparent; } } pdfGrid.Draw(header.Graphics); return(header); }
private void buttonRun_Click(object sender, RoutedEventArgs e) { SaveFileDialog saveFiledialog = new SaveFileDialog(); saveFiledialog.Filter = "PDF Document (*.pdf)|*.pdf"; bool? result = saveFiledialog.ShowDialog(); if (!result.HasValue || !result.Value) { return; } //create a pdf document PdfDocument document = new PdfDocument(); //margin PdfMargins margin = new PdfMargins(); margin.Top = ConvertUnits(1.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; //create one page PdfPageBase page = document.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape); float y = 0; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfInternalFont(new Font("Arial", 16f, System.Drawing.FontStyle.Bold), true); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Vendor List", format1).Height; y = y + 5; PdfGrid grid = new PdfGrid(); grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1); grid.Columns.Add(this.dataGridVendorList.Columns.Count); float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1); grid.Columns[0].Width = width * 0.25f; grid.Columns[1].Width = width * 0.25f; grid.Columns[2].Width = width * 0.25f; grid.Columns[3].Width = width * 0.15f; grid.Columns[4].Width = width * 0.10f; //header of grid PdfGridRow headerRow = grid.Headers.Add(1)[0]; headerRow.Style.Font = new PdfInternalFont(new Font("Arial", 11f, System.Drawing.FontStyle.Bold), true); String[] header = { "Vendor Name", "Address", "City", "State", "Country" }; for (int i = 0; i < header.Length; i++) { headerRow.Cells[i].Value = header[i]; headerRow.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); } headerRow.Style.BackgroundBrush = PdfBrushes.SeaGreen; //datarow of grid int rowIndex = 1; foreach (Vendor vendor in this.dataSource) { PdfGridRow row = grid.Rows.Add(); row.Style.Font = new PdfInternalFont(new Font("Arial", 10f), true); row.Cells[0].Value = vendor.VendorName; row.Cells[1].Value = vendor.Address; row.Cells[2].Value = vendor.City; row.Cells[3].Value = vendor.State; row.Cells[4].Value = vendor.Country; row.Cells[0].Style.BackgroundBrush = PdfBrushes.LightGray; row.Cells[0].StringFormat = row.Cells[1].StringFormat = row.Cells[2].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); row.Cells[3].StringFormat = row.Cells[4].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); if (rowIndex % 2 == 0) { row.Style.BackgroundBrush = PdfBrushes.YellowGreen; } else { row.Style.BackgroundBrush = PdfBrushes.Bisque; } rowIndex++; } StringBuilder totalAmount = new StringBuilder(); var groupByCountry = this.dataSource.GroupBy(v => v.Country) .Select(g => new { Name = g.Key, Count = g.Count() }); foreach (var item in groupByCountry) { totalAmount.AppendFormat("{0}:\t{1}", item.Name, item.Count); totalAmount.AppendLine(); } PdfGridRow totalAmountRow = grid.Rows.Add(); totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum; totalAmountRow.Cells[0].Value = "Total Amount"; totalAmountRow.Cells[0].Style.Font = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold), true); totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); totalAmountRow.Cells[1].ColumnSpan = 4; totalAmountRow.Cells[1].Value = totalAmount.ToString(); totalAmountRow.Cells[1].Style.Font = new PdfInternalFont(new Font("Arial", 10f, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), true); totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); PdfLayoutResult resultl = grid.Draw(page, new PointF(0, y)); y = y + resultl.Bounds.Height + 5; PdfBrush brush2 = PdfBrushes.Gray; PdfTrueTypeFont font2 = new PdfInternalFont(new Font("Arial", 9f)); resultl.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1), font2, brush2, 5, y); //Save pdf file. using (Stream stream = saveFiledialog.OpenFile()) { document.SaveToStream(stream); } document.Close(); }
private void button1_Click(object sender, EventArgs e) { //Create a pdf document. PdfDocument doc = new PdfDocument(); //margin PdfUnitConvertor unitCvtr = new PdfUnitConvertor(); PdfMargins margin = new PdfMargins(); margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Bottom = margin.Top; margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point); margin.Right = margin.Left; // Create one page PdfPageBase page = doc.Pages.Add(PdfPageSize.A4, margin, PdfPageRotateAngle.RotateAngle0, PdfPageOrientation.Landscape); float y = 10; float x1 = page.Canvas.ClientSize.Width; //title PdfBrush brush1 = PdfBrushes.Black; PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold), true); PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center); page.Canvas.DrawString("Vendor List", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1); y = y + font1.MeasureString("Vendor List", format1).Height; y = y + 5; String[] data = { "VendorName;Address1;City;State;Country", "Cacor Corporation;161 Southfield Rd;Southfield;OH;U.S.A.", "Underwater;50 N 3rd Street;Indianapolis;IN;U.S.A.", "J.W. Luscher Mfg.;65 Addams Street;Berkely;MA;U.S.A.", "Scuba Professionals;3105 East Brace;Rancho Dominguez;CA;U.S.A.", "Divers' Supply Shop;5208 University Dr;Macon;GA;U.S.A.", "Techniques;52 Dolphin Drive;Redwood City;CA;U.S.A.", "Perry Scuba;3443 James Ave;Hapeville;GA;U.S.A.", "Beauchat, Inc.;45900 SW 2nd Ave;Ft Lauderdale;FL;U.S.A.", "Amor Aqua;42 West 29th Street;New York;NY;U.S.A.", "Aqua Research Corp.;P.O. Box 998;Cornish;NH;U.S.A.", "B&K Undersea Photo;116 W 7th Street;New York;NY;U.S.A.", "Diving International Unlimited;1148 David Drive;San Diego;DA;U.S.A.", "Nautical Compressors;65 NW 167 Street;Miami;FL;U.S.A.", "Glen Specialties, Inc.;17663 Campbell Lane;Huntington Beach;CA;U.S.A.", "Dive Time;20 Miramar Ave;Long Beach;CA;U.S.A.", "Undersea Systems, Inc.;18112 Gotham Street;Huntington Beach;CA;U.S.A.", "Felix Diving;310 S Michigan Ave;Chicago;IL;U.S.A.", "Central Valley Skin Divers;160 Jameston Ave;Jamaica;NY;U.S.A.", "Parkway Dive Shop;241 Kelly Street;South Amboy;NJ;U.S.A.", "Marine Camera & Dive;117 South Valley Rd;San Diego;CA;U.S.A.", "Dive Canada;275 W Ninth Ave;Vancouver;British Columbia;Canada", "Dive & Surf;P.O. Box 20210;Indianapolis;IN;U.S.A.", "Fish Research Labs;29 Wilkins Rd Dept. SD;Los Banos;CA;U.S.A." }; PdfGrid grid = new PdfGrid(); grid.Style.CellPadding = new PdfPaddings(1, 1, 1, 1); String[] header = data[0].Split(';'); grid.Columns.Add(header.Length); float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1); grid.Columns[0].Width = width * 0.25f; grid.Columns[1].Width = width * 0.25f; grid.Columns[2].Width = width * 0.25f; grid.Columns[3].Width = width * 0.15f; grid.Columns[4].Width = width * 0.10f; PdfGridRow headerRow = grid.Headers.Add(1)[0]; headerRow.Style.Font = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold), true); headerRow.Style.BackgroundBrush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), Color.Red, Color.Blue); for (int i = 0; i < header.Length; i++) { headerRow.Cells[i].Value = header[i]; headerRow.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); if (i == 0) { headerRow.Cells[i].Style.BackgroundBrush = PdfBrushes.Gray; } } Random random = new Random(); Dictionary<String, int> groupByCountry = new Dictionary<String, int>(); for (int r = 1; r < data.Length; r++) { PdfGridRow row = grid.Rows.Add(); row.Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f), true); byte[] buffer = new byte[6]; random.NextBytes(buffer); PdfRGBColor color1 = new PdfRGBColor(buffer[0], buffer[1], buffer[2]); PdfRGBColor color2 = new PdfRGBColor(buffer[3], buffer[4], buffer[5]); row.Style.BackgroundBrush = new PdfLinearGradientBrush(new PointF(0, 0), new PointF(x1, 0), color1, color2); String[] rowData = data[r].Split(';'); for (int c = 0; c < rowData.Length; c++) { row.Cells[c].Value = rowData[c]; if (c == 0) { row.Cells[c].Style.BackgroundBrush = PdfBrushes.Gray; } if(c < 3) { row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); } else { row.Cells[c].StringFormat = new PdfStringFormat(PdfTextAlignment.Center, PdfVerticalAlignment.Middle); } if (c == 4) { if (groupByCountry.ContainsKey(rowData[c])) { groupByCountry[rowData[c]] = groupByCountry[rowData[c]] + 1; } else { groupByCountry[rowData[c]] = 1; } } } } StringBuilder totalAmount = new StringBuilder(); foreach (KeyValuePair<String, int> country in groupByCountry) { totalAmount.AppendFormat("{0}:\t{1}", country.Key, country.Value); totalAmount.AppendLine(); } PdfGridRow totalAmountRow = grid.Rows.Add(); totalAmountRow.Style.BackgroundBrush = PdfBrushes.Plum; totalAmountRow.Cells[0].Value = "Total Amount"; totalAmountRow.Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold), true); totalAmountRow.Cells[0].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); totalAmountRow.Cells[1].ColumnSpan = 4; totalAmountRow.Cells[1].Value = totalAmount.ToString(); totalAmountRow.Cells[1].Style.Font = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold | FontStyle.Italic), true); totalAmountRow.Cells[1].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); //append product list PdfGrid productList = new PdfGrid(); productList.Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f), true); using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb"; OleDbCommand command = new OleDbCommand(); command.CommandText = " select p.Description " + " from vendors v " + " inner join parts p " + " on v.VendorNo = p.VendorNo " + " where v.VendorName = 'Cacor Corporation'"; command.Connection = conn; using (OleDbDataAdapter dataAdapter = new OleDbDataAdapter(command)) { DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); productList.DataSource = dataTable; } } productList.Headers[0].Cells[0].Value = "Cacor Corporation"; productList.Headers[0].Cells[0].Style.Font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Bold), true); productList.Headers[0].Cells[0].Style.Borders.All = new PdfPen(new PdfTilingBrush(new SizeF(1, 1)), 0); grid.Rows[0].Cells[0].Value = productList; grid.Rows[0].Cells[0].StringFormat.Alignment = PdfTextAlignment.Left; PdfLayoutResult result = grid.Draw(page, new PointF(0, y)); y = y + result.Bounds.Height + 5; PdfBrush brush2 = PdfBrushes.Gray; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 9f)); result.Page.Canvas.DrawString(String.Format("* All {0} vendors in the list", grid.Rows.Count - 1), font2, brush2, 5, y); //Save pdf file. doc.SaveToFile("Grid.pdf"); doc.Close(); //Launching the Pdf file. PDFDocumentViewer("Grid.pdf"); }
private PdfLayoutResult DrawVendor(PdfPageBase page, DataTable vendors, int index, String title, float y) { //draw title PdfTrueTypeFont font1 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold)); DataRow row = vendors.Rows[index]; page.Canvas.DrawString(title, font1, PdfBrushes.Black, 0, y); y = y + font1.MeasureString(title).Height + 1; //draw table Object[][] data = new Object[vendors.Columns.Count][]; for (int i = 0; i < vendors.Columns.Count; i++) { data[i] = new Object[2]; data[i][0] = vendors.Columns[i].ColumnName; data[i][1] = vendors.Rows[index].ItemArray[i]; } PdfGrid grid = new PdfGrid(); grid.Style.CellPadding = new PdfPaddings(2, 2, 1, 1); grid.DataSource = data; float width = page.Canvas.ClientSize.Width - (grid.Columns.Count + 1) * 0.75f; grid.Columns[0].Width = width * 0.20f; grid.Columns[1].Width = width * 0.80f; PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold)); PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f)); for (int i = 0; i < grid.Rows.Count; i++) { grid.Rows[i].Style.Font = font2; grid.Rows[i].Cells[0].Style.BackgroundBrush = PdfBrushes.CadetBlue; grid.Rows[i].Cells[1].Style.BackgroundBrush = PdfBrushes.SkyBlue; } PdfGridLayoutFormat layout = new PdfGridLayoutFormat(); layout.Break = PdfLayoutBreakType.FitPage; layout.Layout = PdfLayoutType.Paginate; return grid.Draw(page, new PointF(0, y), layout); }
void PDFButton_Clicked(object sender, EventArgs e) { PdfDocument document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Portrait; document.PageSettings.Margins.All = 50; PdfPage page = document.Pages.Add(); PdfGraphics g = page.Graphics; PdfTextElement element = new PdfTextElement(@"Syncfusion Software 2501 Aerial Center Parkway Suite 200 Morrisville, NC 27560 USA Tel +1 888.936.8638 Fax +1 919.573.0306"); element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); PdfLayoutResult result = element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width / 2, 200)); Stream imgStream = typeof(App).GetTypeInfo().Assembly.GetManifestResourceStream("XamarinIOInvoice.SyncfusionLogo.jpg"); PdfImage img = PdfImage.FromStream(imgStream); page.Graphics.DrawImage(img, new RectangleF(g.ClientSize.Width - 200, result.Bounds.Y, 190, 45)); PdfFont subHeadingFont = new PdfStandardFont(PdfFontFamily.TimesRoman, 15); g.DrawRectangle(new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(0, result.Bounds.Bottom + 40, g.ClientSize.Width, 30)); element = new PdfTextElement("INVOICE: " + billInfo.InvoiceNumber.ToString(), subHeadingFont); element.Brush = PdfBrushes.White; result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 48)); string currentDate = "DATE: " + billInfo.Date.ToString(); SizeF textSize = subHeadingFont.MeasureString(currentDate); g.DrawString(currentDate, subHeadingFont, element.Brush, new PointF(g.ClientSize.Width - textSize.Width - 10, result.Bounds.Y)); element = new PdfTextElement("BILL TO ", new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(34, 83, 142)); result = element.Draw(page, new PointF(10, result.Bounds.Bottom + 25)); g.DrawLine(new PdfPen(new PdfColor(34, 83, 142), 0.70f), new PointF(0, result.Bounds.Bottom + 3), new PointF(g.ClientSize.Width, result.Bounds.Bottom + 3)); element = new PdfTextElement(billInfo.Name, new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 5, g.ClientSize.Width / 2, 100)); element = new PdfTextElement(billInfo.Address, new PdfStandardFont(PdfFontFamily.TimesRoman, 14)); element.Brush = new PdfSolidBrush(new PdfColor(0, 0, 0)); result = element.Draw(page, new RectangleF(10, result.Bounds.Bottom + 3, g.ClientSize.Width / 2, 100)); PdfGrid grid = new PdfGrid(); grid.DataSource = this.ListSource; PdfGridCellStyle cellStyle = new PdfGridCellStyle(); cellStyle.Borders.All = PdfPens.White; PdfGridRow header = grid.Headers[0]; PdfGridCellStyle headerStyle = new PdfGridCellStyle(); headerStyle.Borders.All = new PdfPen(new PdfColor(34, 83, 142)); headerStyle.BackgroundBrush = new PdfSolidBrush(new PdfColor(34, 83, 142)); headerStyle.TextBrush = PdfBrushes.White; headerStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 15f, PdfFontStyle.Regular); for (int i = 0; i < header.Cells.Count; i++) { if (i == 0) header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else header.Cells[i].StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); } header.Cells[0].Value = "ITEM"; header.Cells[1].Value = "QUANTITY"; header.Cells[2].Value = "RATE"; header.Cells[3].Value = "TAXES (%)"; header.Cells[4].Value = "AMOUNT"; header.ApplyStyle(headerStyle); cellStyle.Borders.Bottom = new PdfPen(new PdfColor(217, 217, 217), 0.70f); cellStyle.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 14f); cellStyle.TextBrush = new PdfSolidBrush(new PdfColor(0, 0, 0)); foreach (PdfGridRow row in grid.Rows) { row.ApplyStyle(cellStyle); for (int i = 0; i < row.Cells.Count; i++) { PdfGridCell cell = row.Cells[i]; if (i == 0) cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); else cell.StringFormat = new PdfStringFormat(PdfTextAlignment.Right, PdfVerticalAlignment.Middle); if (i > 1 && i != 3) { //float val = float.MinValue; //float.TryParse(cell.Value.ToString(), out val); if (cell.Value.ToString().Contains("$")) { cell.Value = cell.Value.ToString(); } else { cell.Value = "$" + cell.Value.ToString(); } } } } PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Layout = PdfLayoutType.Paginate; PdfGridLayoutResult gridResult = grid.Draw(page, new RectangleF(new PointF(0, result.Bounds.Bottom + 40), new SizeF(g.ClientSize.Width, g.ClientSize.Height - 100)), layoutFormat); float pos = 0.0f; for (int i = 0; i < grid.Columns.Count - 1; i++) pos += grid.Columns[i].Width; PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 14f,PdfFontStyle.Bold); gridResult.Page.Graphics.DrawString("TOTAL DUE", font, new PdfSolidBrush(new PdfColor(34, 83, 142)), new RectangleF(new PointF(pos, gridResult.Bounds.Bottom + 10), new SizeF(grid.Columns[3].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); gridResult.Page.Graphics.DrawString("Thank you for your business!", new PdfStandardFont(PdfFontFamily.TimesRoman, 14), new PdfSolidBrush(new PdfColor(0, 0, 0)), new PointF(pos -210, gridResult.Bounds.Bottom + 60)); pos += grid.Columns[4].Width; gridResult.Page.Graphics.DrawString("$" + GetNetAmount().ToString(), font, new PdfSolidBrush(new PdfColor(0, 0, 0)), new RectangleF(new Syncfusion.Drawing.PointF(pos, gridResult.Bounds.Bottom + 10), new Syncfusion.Drawing.SizeF(grid.Columns[4].Width - pos, 20)), new PdfStringFormat(PdfTextAlignment.Right)); MemoryStream data = new MemoryStream(); document.Save(data); document.Close(); DependencyService.Get<ISave>().SaveTextAsync("Invoice.pdf", "application/pdf", data); }