private void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args) { //Set the color of table cell border PdfCellStyle cellStyle = new PdfCellStyle(); cellStyle.BorderPen = new PdfPen(Color.LightBlue, 0.9f); args.CellStyle = cellStyle; }
//在自定义事件中设置单元格字体和文本对齐方式 private static void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args) { PdfCellStyle cellstyle = new PdfCellStyle(); cellstyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); cellstyle.Font = new PdfTrueTypeFont(new Font("Arial Unicode MS", 9f), true); args.CellStyle = cellstyle; }
private static void table_BeginRowLayout(object sender, BeginRowLayoutEventArgs args) { PdfCellStyle cs = new PdfCellStyle(); cs.BorderPen = new PdfPen(Color.Transparent); cs.Font = pageFont; args.CellStyle = cs; }
private void BeginRowLayout(object sender, BeginRowLayoutEventArgs args) { PdfCellStyle cellstyle = new PdfCellStyle(); cellstyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); cellstyle.Font = new PdfTrueTypeFont(new Font("Arial", 8f), true); args.CellStyle = cellstyle; PdfPageSettings ps = new PdfPageSettings(); ps.Orientation = PdfPageOrientation.Landscape; }
public ActionResult InteractiveFeatures(string InsideBrowser) { #region Field Definitions document = new PdfDocument(); document.PageSettings.Margins.All = 0; document.PageSettings.Size = new SizeF(PdfPageSize.A4.Width, 600); interactivePage = document.Pages.Add(); PdfGraphics g = interactivePage.Graphics; RectangleF rect = new RectangleF(0, 0, interactivePage.Graphics.ClientSize.Width, 100); PdfBrush whiteBrush = new PdfSolidBrush(white); PdfPen whitePen = new PdfPen(white, 5); PdfBrush purpleBrush = new PdfSolidBrush(new PdfColor(255, 158, 0, 160)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 25); Syncfusion.Drawing.Color maroonColor = Color.FromArgb(255, 188, 32, 60); Syncfusion.Drawing.Color orangeColor = Color.FromArgb(255, 255, 167, 73); #endregion #region Header g.DrawRectangle(purpleBrush, rect); g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, 35, 700, 200), 20, -180); g.DrawRectangle(whiteBrush, new RectangleF(0, 99.5f, 700, 200)); g.DrawString("Invoice", new PdfStandardFont(PdfFontFamily.TimesRoman, 24), PdfBrushes.White, new PointF(500, 10)); string basePath = _hostingEnvironment.WebRootPath; string dataPath = string.Empty; dataPath = basePath + @"/PDF/"; //Read the file FileStream file = new FileStream(dataPath + "AdventureCycle.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); g.DrawImage(PdfImage.FromStream(file), new RectangleF(100, 70, 390, 130)); #endregion #region Body //Invoice Number Random invoiceNumber = new Random(); g.DrawString("Invoice No: " + invoiceNumber.Next().ToString(), new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(50, 210)); g.DrawString("Date: ", new PdfStandardFont(PdfFontFamily.Helvetica, 14), new PdfSolidBrush(maroonColor), new PointF(350, 210)); //Current Date PdfTextBoxField textBoxField = new PdfTextBoxField(interactivePage, "date"); textBoxField.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); textBoxField.Bounds = new RectangleF(384, 204, 150, 30); textBoxField.ForeColor = new PdfColor(maroonColor); textBoxField.ReadOnly = true; document.Actions.AfterOpen = new PdfJavaScriptAction(@"var newdate = new Date(); var thisfieldis = this.getField('date'); var theday = util.printd('dddd',newdate); var thedate = util.printd('d',newdate); var themonth = util.printd('mmmm',newdate); var theyear = util.printd('yyyy',newdate); thisfieldis.strokeColor=color.transparent; thisfieldis.value = theday + ' ' + thedate + ', ' + themonth + ' ' + theyear ;"); document.Form.Fields.Add(textBoxField); //invoice table PdfLightTable table = new PdfLightTable(); table.Style.ShowHeader = true; g.DrawRectangle(new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(238, 238, 238, 248)), new RectangleF(50, 240, 500, 140)); //Header Style PdfCellStyle headerStyle = new PdfCellStyle(); headerStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Bold); headerStyle.TextBrush = whiteBrush; headerStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Center); headerStyle.BackgroundBrush = new PdfSolidBrush(orangeColor); headerStyle.BorderPen = new PdfPen(whiteBrush, 0); table.Style.HeaderStyle = headerStyle; //Cell Style PdfCellStyle bodyStyle = new PdfCellStyle(); bodyStyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); bodyStyle.StringFormat = new PdfStringFormat(PdfTextAlignment.Left); bodyStyle.BorderPen = new PdfPen(whiteBrush, 0); table.Style.DefaultStyle = bodyStyle; table.DataSource = GetProductReport(_hostingEnvironment.WebRootPath); table.Columns[0].Width = 90; table.Columns[1].Width = 160; table.Columns[3].Width = 100; table.Columns[4].Width = 65; table.Style.CellPadding = 3; table.BeginCellLayout += table_BeginCellLayout; PdfLightTableLayoutResult result = table.Draw(interactivePage, new RectangleF(50, 240, 500, 140)); g.DrawString("Grand Total:", new PdfStandardFont(PdfFontFamily.Helvetica, 12), new PdfSolidBrush(Syncfusion.Drawing.Color.FromArgb(255, 255, 167, 73)), new PointF(result.Bounds.Right - 150, result.Bounds.Bottom)); CreateTextBox(interactivePage, "GrandTotal", "Grand Total", new RectangleF(result.Bounds.Width - 15, result.Bounds.Bottom - 2, 66, 18), true, ""); //Send to Server PdfButtonField sendButton = new PdfButtonField(interactivePage, "OrderOnline"); sendButton.Bounds = new RectangleF(200, result.Bounds.Bottom + 70, 80, 25); sendButton.BorderColor = white; sendButton.BackColor = maroonColor; sendButton.ForeColor = white; sendButton.Text = "Order Online"; PdfSubmitAction submitAction = new PdfSubmitAction("http://stevex.net/dump.php"); submitAction.DataFormat = SubmitDataFormat.Html; sendButton.Actions.MouseUp = submitAction; document.Form.Fields.Add(sendButton); //Order by Mail PdfButtonField sendMail = new PdfButtonField(interactivePage, "sendMail"); sendMail.Bounds = new RectangleF(300, result.Bounds.Bottom + 70, 80, 25); sendMail.Text = "Order By Mail"; sendMail.BorderColor = white; sendMail.BackColor = maroonColor; sendMail.ForeColor = white; // Create a javascript action. PdfJavaScriptAction javaAction = new PdfJavaScriptAction("address = app.response(\"Enter an e-mail address.\",\"SEND E-MAIL\",\"\");" + "var aSubmitFields = [];" + "for( var i = 0 ; i < this.numFields; i++){" + "aSubmitFields[i] = this.getNthFieldName(i);" + "}" + "if (address){ cmdLine = \"mailto:\" + address;this.submitForm(cmdLine,true,false,aSubmitFields);}"); sendMail.Actions.MouseUp = javaAction; document.Form.Fields.Add(sendMail); //Print PdfButtonField printButton = new PdfButtonField(interactivePage, "print"); printButton.Bounds = new RectangleF(400, result.Bounds.Bottom + 70, 80, 25); printButton.BorderColor = white; printButton.BackColor = maroonColor; printButton.ForeColor = white; printButton.Text = "Print"; printButton.Actions.MouseUp = new PdfJavaScriptAction("this.print (true); "); document.Form.Fields.Add(printButton); file = new FileStream(dataPath + "Product Catalog.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); PdfAttachment attachment = new PdfAttachment("Product Catalog.pdf", file); attachment.ModificationDate = DateTime.Now; attachment.Description = "Specification"; document.Attachments.Add(attachment); //Open Specification PdfButtonField openSpecificationButton = new PdfButtonField(interactivePage, "openSpecification"); openSpecificationButton.Bounds = new RectangleF(50, result.Bounds.Bottom + 20, 87, 15); openSpecificationButton.TextAlignment = PdfTextAlignment.Left; openSpecificationButton.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); openSpecificationButton.BorderStyle = PdfBorderStyle.Underline; openSpecificationButton.BorderColor = orangeColor; openSpecificationButton.BackColor = new PdfColor(255, 255, 255); openSpecificationButton.ForeColor = orangeColor; openSpecificationButton.Text = "Open Specification"; openSpecificationButton.Actions.MouseUp = new PdfJavaScriptAction("this.exportDataObject({ cName: 'Product Catalog.pdf', nLaunch: 2 });"); document.Form.Fields.Add(openSpecificationButton); RectangleF uriAnnotationRectangle = new RectangleF(interactivePage.Graphics.ClientSize.Width - 160, interactivePage.Graphics.ClientSize.Height - 30, 80, 20); PdfTextWebLink linkAnnot = new PdfTextWebLink(); linkAnnot.Url = "http://www.adventure-works.com"; linkAnnot.Text = "http://www.adventure-works.com"; linkAnnot.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 8); linkAnnot.Brush = PdfBrushes.White; linkAnnot.DrawTextWebLink(interactivePage, uriAnnotationRectangle.Location); #endregion #region Footer g.DrawRectangle(purpleBrush, new RectangleF(0, interactivePage.Graphics.ClientSize.Height - 100, interactivePage.Graphics.ClientSize.Width, 100)); g.DrawPie(whitePen, whiteBrush, new RectangleF(-20, interactivePage.Graphics.ClientSize.Height - 250, 700, 200), 0, 180); #endregion //Save the PDF to the MemoryStream MemoryStream ms = new MemoryStream(); document.Save(ms); //If the position is not set to '0' then the PDF will be empty. ms.Position = 0; //Close the PDF document. document.Close(true); //Download the PDF document in the browser. FileStreamResult fileStreamResult = new FileStreamResult(ms, "application/pdf"); fileStreamResult.FileDownloadName = "Interactive features.pdf"; return(fileStreamResult); }
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); }
private void ReportButton_Click(object sender, RoutedEventArgs e) { PdfDocument doc = new PdfDocument(); PdfPage page = doc.Pages.Add(); PdfLightTable pdfLightTable = new PdfLightTable(); DataTable table = new DataTable(); pdfLightTable.Style.ShowHeader = true; PdfCellStyle headerStyle = new PdfCellStyle(new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.DarkBlue, PdfPens.DarkBlue); pdfLightTable.Style.HeaderStyle = headerStyle; table.Columns.Add("PONEDELJAK"); table.Columns.Add("UTORAK"); table.Columns.Add("SREDA"); table.Columns.Add("ČETVRTAK"); table.Columns.Add("PETAK"); table.Columns.Add("SUBOTA"); table.Columns.Add("NEDELJA"); DateTime startOfWeek = DateTime.Today.AddDays(-1 * (int)(DateTime.Today.DayOfWeek)); DateTime endOfWeek = startOfWeek.AddDays(7).AddSeconds(-1); List <DateTime> datesCurrentWeek = new List <DateTime>(); List <String> mondayTherapyInfo = new List <String>(); List <String> tuesdayTherapyInfo = new List <String>(); List <String> wednesdayTherapyInfo = new List <String>(); List <String> thursdayTherapyInfo = new List <String>(); List <String> fridayTherapyInfo = new List <String>(); List <String> saturdayTherapyInfo = new List <String>(); List <String> sundayTherapyInfo = new List <String>(); for (var date = startOfWeek; date <= endOfWeek; date = date.AddDays(1)) { datesCurrentWeek.Add(date); } foreach (var therapy in _loggedInPatient.MedicalRecord.getPrescriptions()) { foreach (var currentDate in datesCurrentWeek) { foreach (var therapyDate in GetTherapyDates(therapy)) { if (therapyDate == currentDate) { switch (therapyDate.DayOfWeek) { case DayOfWeek.Monday: mondayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Tuesday: tuesdayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Wednesday: wednesdayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Thursday: thursdayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Friday: fridayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Saturday: saturdayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; case DayOfWeek.Sunday: sundayTherapyInfo.Add(therapy.medicine.Name + "-" + therapy.info); break; } } } } } int[] numberOfTherapiesInDays = { mondayTherapyInfo.Count, tuesdayTherapyInfo.Count, wednesdayTherapyInfo.Count, thursdayTherapyInfo.Count, fridayTherapyInfo.Count, saturdayTherapyInfo.Count, sundayTherapyInfo.Count }; fillTherapyInformation(mondayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(tuesdayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(wednesdayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(thursdayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(fridayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(saturdayTherapyInfo, numberOfTherapiesInDays); fillTherapyInformation(sundayTherapyInfo, numberOfTherapiesInDays); for (int i = 0; i <= numberOfTherapiesInDays.Max(); i++) { table.Rows.Add(new string[] { mondayTherapyInfo[i], tuesdayTherapyInfo[i], wednesdayTherapyInfo[i], thursdayTherapyInfo[i], fridayTherapyInfo[i], saturdayTherapyInfo[i], sundayTherapyInfo[i] }); } pdfLightTable.DataSource = table; pdfLightTable.Draw(page, new PointF(0, 0)); doc.Save(DateTime.Now.Day + "_" + DateTime.Now.Month + "_" + DateTime.Now.Year + ".pdf"); doc.Close(true); }