public void MultipleExportToPdf(string[] GanttModel) { PdfExport exp = new PdfExport(); var PlanData = this.GetPlanDataSource(); var DesignData = this.GetDesignDataSource(); var ImplementationData = this.GetImplementationDataSource(); PdfDocument document = null; GanttPdfExportSettings settings = new GanttPdfExportSettings(); settings.Theme = GanttExportTheme.FlatSaffron; settings.Locale = Request.Form["locale"]; //Create footer template RectangleF bounds = new RectangleF(0, 0, 762, 25); PdfSolidBrush brush = new PdfSolidBrush(new PdfColor(51, 51, 51)); PdfPen pen = new PdfPen(new PdfColor(200, 200, 200)); PdfFont font = new PdfTrueTypeFont(new Font("Segoe UI", 10), true); PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0}", pageNumber); compositeField.StringFormat = format; compositeField.Bounds = footer.Bounds; footer.Graphics.DrawRectangle(pen, bounds); compositeField.Draw(footer.Graphics, new PointF(0, 0)); PdfDocumentTemplate footerTemplate = new PdfDocumentTemplate(); footerTemplate.Bottom = footer; settings.PdfDocumentTemplate = footerTemplate; int count = 1; foreach (string gridProperty in GanttModel) { GanttProperties gridProp = this.ConvertGanttObject(gridProperty); if (count == 1) { document = exp.Export(gridProp, (IEnumerable)PlanData, settings, false); } else if (count == 2) { document = exp.Export(gridProp, (IEnumerable)DesignData, settings, document, false); } else { exp.Export(gridProp, (IEnumerable)ImplementationData, settings, "Gantt", document, true); } count++; } }
private void createFooter() { //footer PdfPageTemplateElement footer = new PdfPageTemplateElement(new RectangleF(new PointF(0, _document.PageSettings.Height - heightFooter), new SizeF(_document.PageSettings.Width, heightFooter))); footer.Graphics.DrawString(System.DateTime.Now.ToString(), smallFont, brushBlack, new PointF(marginLeft, 15)); //Creates page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(smallFont, brushBlack); //Creates page count field. PdfPageCountField count = new PdfPageCountField(smallFont, brushBlack); //Adds the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(smallFont, brushBlack, "Pagina {0} di {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; //Draws the composite field in footer. compositeField.Draw(footer.Graphics, new PointF(_document.PageSettings.Width - marginRight * 2, 15)); _document.Template.Bottom = footer; }
private void AddFooter(PdfDocument doc, string footerText) { RectangleF rect = new RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50); PdfColor blueColor = new PdfColor(System.Drawing.Color.FromArgb(255, 0, 0, 255)); PdfColor GrayColor = new PdfColor(System.Drawing.Color.FromArgb(255, 128, 128, 128)); //Create a page template PdfPageTemplateElement footer = new PdfPageTemplateElement(rect); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 8); PdfSolidBrush brush = new PdfSolidBrush(GrayColor); PdfPen pen = new PdfPen(blueColor, 3f); font = new PdfStandardFont(PdfFontFamily.Helvetica, 6, PdfFontStyle.Bold); PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Center; format.LineAlignment = PdfVerticalAlignment.Middle; footer.Graphics.DrawString(footerText, font, brush, new RectangleF(0, 18, footer.Width, footer.Height), format); format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Right; format.LineAlignment = PdfVerticalAlignment.Bottom; //Create page number field PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field PdfPageCountField count = new PdfPageCountField(font, brush); PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; compositeField.Draw(footer.Graphics, new PointF(470, 40)); //Add the footer template at the bottom doc.Template.Bottom = footer; }
private void GenerateFooter(GenerateInvoiceContext request, PdfGenerator pdf) { //https://help.syncfusion.com/file-formats/pdf/working-with-headers-and-footers RectangleF bounds = new RectangleF(0, 0, pdf.PageWidth, FOOTER_HEIGHT); PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); //BUG: NullReferenceException when trying to put a web link into the footer - drawing web links using footer graphics not supported yet by syncfusion //pdf.DrawWebLink(0, 35, "http://www.syncfusion.com", "Awesome control library for your mobile cross platform needs", pdf.NormalFont, footer.Graphics); //pdf.DrawWebLinkPageBottom(0, 35, "http://www.syncfusion.com", "Awesome control library for your mobile cross platform needs", pdf.NormalFont); PdfCompositeField compositeField = new PdfCompositeField(pdf.NormalFont, pdf.AccentBrush, "http://www.syncfusion.com Awesome control library for your mobile cross platform needs"); compositeField.Bounds = footer.Bounds; //Draw the composite field in footer. compositeField.Draw(footer.Graphics, new PointF(0, 0)); pdf.DrawHorizontalLine(0, pdf.PageWidth, 0, 0.7f, pdf.AccentColor, footer.Graphics); pdf.Document.Template.Bottom = footer; }
protected void Grid1_ServerPdfExporting(object sender, GridEventArgs e) { PdfExport exp = new PdfExport(); SummaryGridBind(); if (dsSummary.Tables[0].Rows.Count > 0) { DataTable dtSummary = dsSummary.Tables[0]; //List<DataRow> list = FamilyDetails.AsEnumerable().ToList(); List <DataRow> list = new List <DataRow>(dtSummary.Select()); PdfPageSettings pageSettings = new PdfPageSettings(50f); pageSettings.Margins.Left = 15; pageSettings.Margins.Right = 15; pageSettings.Margins.Top = 10; pageSettings.Margins.Bottom = 10; PdfDocument pdfDocument = exp.Export(Grid1.Model, (IEnumerable)list, "FindDocumentStatus.pdf", true, true, "flat-lime", true); RectangleF rect = new RectangleF(0, 0, pdfDocument.PageSettings.Width, 50); RectangleF rect1 = new RectangleF(0, 0, pdfDocument.PageSettings.Width, 50); //create a header pager template PdfPageTemplateElement header = new PdfPageTemplateElement(rect); PdfPageTemplateElement header1 = new PdfPageTemplateElement(rect1); //create a footer pager template PdfPageTemplateElement footer = new PdfPageTemplateElement(rect); Font f = new Font("Arial", 11, FontStyle.Bold); PdfFont font = new PdfTrueTypeFont(f, true); //header.Graphics.DrawString("Land Aquisition", font, PdfBrushes.Black, new Point(250, 0)); //Add custom text to the Header //pdfDocument.Template.Top = header; //Append custom template to the document //header1.Graphics.DrawString("All Family Details", font, PdfBrushes.Black, new Point(0, 3)); //Add custom text to the Header //pdfDocument.Template.Top = header1; //Append custom template to the document PdfBrush brush = new PdfSolidBrush(Color.Black); //Add the fields in composite fields PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Land Aquisition - SEZ Thane"); PdfCompositeField compositeField1 = new PdfCompositeField(font, brush, "Find Document Status"); //PdfCompositeField compositeField2 = new PdfCompositeField(font, brush, "Report"); //PdfCompositeField compositeField3 = new PdfCompositeField(font, brush, "Family Details"); compositeField.Bounds = header.Bounds; //Draw the composite field in footer compositeField.Draw(footer.Graphics, new PointF(200, 0)); compositeField1.Draw(footer.Graphics, new PointF(230, 10)); //compositeField2.Draw(footer.Graphics, new PointF(205, 20)); //compositeField3.Draw(footer.Graphics, new PointF(228, 40)); //Add the footer template at the bottom pdfDocument.Template.Top = header; footer.Graphics.DrawString("CopyRights", font, PdfBrushes.Gray, new Point(250, 0)); //Add Custom text to footer pdfDocument.Template.Bottom = footer; //Add the footer template to document pdfDocument.Save("FindDocumentStatus.pdf", Response, HttpReadType.Save); } else { } }
public ActionResult CreateDocumentWithoutFilter() { PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); 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(); //Load the image as stream. FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read); PdfBitmap image = new PdfBitmap(imageStream); graphics.DrawImage(image, 200, 200); //Draw the image Syncfusion.Drawing.RectangleF bounds = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50); PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); PdfCompositeField compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o referentnim tipovima"); compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0)); //Add the header at the top. doc.Template.Top = header; //Save the PDF document to stream //Create a Page template that can be used as footer. PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, brush); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; //Draw the composite field in footer. compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40)); //Add the footer template at the bottom. doc.Template.Bottom = footer; MemoryStream stream = new MemoryStream(); List <object> data = new List <object>(); var oprema = _context.ReferentniTip .AsNoTracking() .OrderBy(o => o.Id) .ToList(); foreach (var komad in oprema) { var row = new { Naziv = komad.Naziv, }; data.Add(row); } //Add list to IEnumerable IEnumerable <object> dataTable = data; //Assign data source. pdfGrid.DataSource = dataTable; pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50)); 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 = "Referentni tipovi-Reports.pdf"; return(File(stream, contentType, fileName)); }
private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin) { PdfPageTemplateElement leftSpace = new PdfPageTemplateElement(margin.Left, pageSize.Height); doc.Template.Left = leftSpace; PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, margin.Top); topSpace.Foreground = true; doc.Template.Top = topSpace; //draw header label PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic)); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right); String label = "Demo of Spire.Pdf"; SizeF size = font.MeasureString(label, format); float y = topSpace.Height - font.Height - 1; PdfPen pen = new PdfPen(Color.Black, 0.75f); topSpace.Graphics.SetTransparency(0.5f); topSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y); y = y - 1 - size.Height; topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format); PdfPageTemplateElement rightSpace = new PdfPageTemplateElement(margin.Right, pageSize.Height); doc.Template.Right = rightSpace; PdfPageTemplateElement bottomSpace = new PdfPageTemplateElement(pageSize.Width, margin.Bottom); bottomSpace.Foreground = true; doc.Template.Bottom = bottomSpace; //draw footer label y = font.Height + 1; bottomSpace.Graphics.SetTransparency(0.5f); bottomSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y); y = y + 1; PdfPageNumberField pageNumber = new PdfPageNumberField(); PdfPageCountField pageCount = new PdfPageCountField(); PdfCompositeField pageNumberLabel = new PdfCompositeField(); pageNumberLabel.AutomaticFields = new PdfAutomaticField[] { pageNumber, pageCount }; pageNumberLabel.Brush = PdfBrushes.Black; pageNumberLabel.Font = font; pageNumberLabel.StringFormat = format; pageNumberLabel.Text = "page {0} of {1}"; pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - margin.Right, y); PdfImage headerImage = PdfImage.FromFile(@"..\..\..\..\..\..\..\Data\Header.png"); PointF pageLeftTop = new PointF(-margin.Left, -margin.Top); PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension); header.Foreground = false; header.Graphics.SetTransparency(0.5f); header.Graphics.DrawImage(headerImage, 0, 0); doc.Template.Stamps.Add(header); PdfImage footerImage = PdfImage.FromFile(@"..\..\..\..\..\..\..\Data\Footer.png"); y = pageSize.Height - footerImage.PhysicalDimension.Height; PointF footerLocation = new PointF(-margin.Left, y); PdfPageTemplateElement footer = new PdfPageTemplateElement(footerLocation, footerImage.PhysicalDimension); footer.Foreground = false; footer.Graphics.SetTransparency(0.5f); footer.Graphics.DrawImage(footerImage, 0, 0); doc.Template.Stamps.Add(footer); }
private ActionResult ExportPdfLINEPayRemittance(List <LINEPayRemittance> LINEPayRemittance, DateTime RemittanceDate) { // Load the PDF Template Stream pdfStream = System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + @"\assets\templates\LINEPayRemittance.pdf"); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, (float)6.5); PdfFont fontRemittanceDate = new PdfStandardFont(PdfFontFamily.Helvetica, (float)8); // Load a PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream); //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); pdfDocument.ImportPage(loadedDocument, 0); PdfPage pdfPage = pdfDocument.Pages[0]; //Create a new PdfGrid. PdfGrid pdfGrid = new PdfGrid(); //Add three columns. pdfGrid.Columns.Add(9); //Add header. pdfGrid.Headers.Add(1); PdfGridRow pdfGridHeader = pdfGrid.Headers[0]; string[] headerStr = { "ERP ID", "Branch ID", "Report Date", "Branch Name", "TUC DCSP", "TUC", "TUP", "TUD", "Captured" }; int[] columnsWidth = { 40, 40, 50, 0, 50, 50, 50, 50, 30 }; pdfGridHeader.Style.Font = font; pdfGridHeader.Style.BackgroundBrush = PdfBrushes.LightGray; pdfGridHeader.Height = (float)11; for (int i = 0; i < headerStr.Count(); i++) { if (!i.Equals(3)) { pdfGrid.Columns[i].Width = columnsWidth[i]; } pdfGridHeader.Cells[i].StringFormat.Alignment = PdfTextAlignment.Center; pdfGridHeader.Cells[i].Value = headerStr[i]; pdfGridHeader.Cells[i].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridHeader.Cells[i].Style.Borders.Left.Width = (float)0.5; pdfGridHeader.Cells[i].Style.Borders.Right.Width = (float)0.5; pdfGridHeader.Cells[i].Style.Borders.Top.Width = (float)0.5; pdfGridHeader.Cells[i].Style.Borders.Bottom.Width = (float)0.5; } pdfGridHeader.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridHeader.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridHeader.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right; PdfGridRow pdfGridRow; LINEPayRemittance.ForEach(line => { //Add rows. pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Style.Font = font; pdfGridRow.Height = (float)11; pdfGridRow.Cells[0].Value = line.ERP_ID; pdfGridRow.Cells[1].Value = line.BranchID; pdfGridRow.Cells[2].Value = line.ReportDate.ToString("dd/MM/yyyy", enUS); pdfGridRow.Cells[3].Value = line.BranchName; pdfGridRow.Cells[4].Value = line.branch_type.Equals("DCSP-SHOP") ? line.TUC.ToString("#,0.00"):"-"; pdfGridRow.Cells[5].Value = !line.branch_type.Equals("DCSP-SHOP") ? line.TUC.ToString("#,0.00") : "-"; pdfGridRow.Cells[6].Value = line.TUP.ToString("#,0.00"); pdfGridRow.Cells[7].Value = line.TUD.ToString("#,0.00"); pdfGridRow.Cells[8].Value = line.TUDVerifyDate == null ? line.Captured : "Yes"; pdfGridRow.Cells[0].StringFormat.Alignment = PdfTextAlignment.Center; pdfGridRow.Cells[2].StringFormat.Alignment = PdfTextAlignment.Center; pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[7].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[8].StringFormat.Alignment = PdfTextAlignment.Center; for (int i = 0; i < pdfGridRow.Cells.Count; i++) { pdfGridRow.Cells[i].Style.Borders.Left.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Right.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Top.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Bottom.Width = (float)0.5; pdfGridRow.Cells[i].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); } }); //Add rows Sum pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Cells[4].Value = LINEPayRemittance.Where(line => line.branch_type.Equals("DCSP-SHOP")).Sum(line => line.TUC).ToString("#,0.00"); pdfGridRow.Cells[5].Value = LINEPayRemittance.Where(line => !line.branch_type.Equals("DCSP-SHOP")).Sum(line => line.TUC).ToString("#,0.00"); pdfGridRow.Cells[6].Value = LINEPayRemittance.Sum(line => line.TUP).ToString("#,0.00"); pdfGridRow.Cells[7].Value = LINEPayRemittance.Sum(line => line.TUD).ToString("#,0.00"); pdfGridRow.Cells[4].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridRow.Cells[5].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridRow.Cells[6].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridRow.Cells[7].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); for (int i = 0; i < pdfGridRow.Cells.Count; i++) { pdfGridRow.Cells[i].Style.Borders.Left.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Right.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Bottom.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Left.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Right.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Top.Width = (float)0.5; pdfGridRow.Cells[i].Style.Borders.Bottom.Width = (float)0.5; } pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[5].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[6].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[7].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Height = (float)11; pdfGridRow.Style.Font = font; for (int i = 4; i <= 7; i++) { pdfGridRow.Cells[i].Style.Borders.Top.Color = new PdfColor(Color.Black); pdfGridRow.Cells[i].Style.Borders.Left.Color = new PdfColor(Color.Black); pdfGridRow.Cells[i].Style.Borders.Right.Color = new PdfColor(Color.Black); pdfGridRow.Cells[i].Style.Borders.Bottom.Color = new PdfColor(Color.Black); } //Add rows Total pdfGridRow = pdfGrid.Rows.Add(); pdfGridRow.Cells[3].Value = "Total"; pdfGridRow.Cells[4].Value = ( LINEPayRemittance.Sum(line => line.TUC) + LINEPayRemittance.Sum(line => line.TUP) + LINEPayRemittance.Sum(line => line.TUD)).ToString("#,0.00"); pdfGridRow.Cells[4].ColumnSpan = 4; pdfGridRow.Cells[3].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridRow.Cells[4].Style.CellPadding = new PdfPaddings((float)1.5, (float)1.5, (float)1.5, (float)1.5); pdfGridRow.Cells[3].StringFormat.Alignment = PdfTextAlignment.Right; pdfGridRow.Cells[4].StringFormat.Alignment = PdfTextAlignment.Center; pdfGridRow.Height = (float)11; pdfGridRow.Style.Font = font; for (int i = 0; i < pdfGridRow.Cells.Count; i++) { pdfGridRow.Cells[i].Style.Borders.Top.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Left.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Right.Color = PdfColor.Empty; pdfGridRow.Cells[i].Style.Borders.Bottom.Color = PdfColor.Empty; } pdfGridRow.Cells[4].Style.Borders.Top.Color = new PdfColor(Color.Black); pdfGridRow.Cells[4].Style.Borders.Left.Color = new PdfColor(Color.Black); pdfGridRow.Cells[4].Style.Borders.Right.Color = new PdfColor(Color.Black); pdfGridRow.Cells[4].Style.Borders.Bottom.Color = new PdfColor(Color.Black); pdfGridRow.Cells[4].Style.Borders.Left.Width = (float)0.5; pdfGridRow.Cells[4].Style.Borders.Right.Width = (float)0.5; pdfGridRow.Cells[4].Style.Borders.Top.Width = (float)0.5; pdfGridRow.Cells[4].Style.Borders.Bottom.Width = (float)0.5; //Create PDF graphics for the page. PdfGraphics graphics = pdfPage.Graphics; //Draw the text. graphics.DrawString(RemittanceDate.ToString("dd MMM yyyy", enUS), fontRemittanceDate, PdfBrushes.Black, new PointF((float)458, (float)57.5)); //Draw the PdfGrid. //pdfGrid.Draw(pdfPage, (float)20, (float)90, (float)555.28,); //pdfGrid.Draw(pdfPage, new RectangleF(20, 90, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 140)); //Set properties to paginate the table. PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Break = PdfLayoutBreakType.FitElement; layoutFormat.Layout = PdfLayoutType.Paginate; layoutFormat.PaginateBounds = new RectangleF(20, 20, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 50); //Draw PdfLightTable. pdfGrid.Draw(pdfPage, 20f, 90f, (pdfDocument.Pages[0].GetClientSize().Width - 40), layoutFormat); //Create a Page template that can be used as footer. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50); PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); PdfBrush brush = new PdfSolidBrush(Color.Black); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, brush); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); string printDate = DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", enUS); PdfCompositeField compositePrintDate = new PdfCompositeField(font, brush, string.Format("Printed Date : {0}", printDate)); compositeField.Bounds = footer.Bounds; //Draw the composite field in footer. compositeField.Draw(footer.Graphics, new PointF(pdfDocument.Pages[0].GetClientSize().Width - 50, 30)); compositePrintDate.Draw(footer.Graphics, new PointF(20, 30)); //Add the footer template at the bottom. pdfDocument.Template.Bottom = footer; MemoryStream ms = new MemoryStream(); pdfDocument.Save(ms); ms.Position = 0; //Close the document pdfDocument.Close(true); //Save the document. return(File(ms, "Application/pdf")); }
public ActionResult CreateDocument(string id, string vrsta, string znak) { PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10); PdfFont bigFont = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfBrush brush = new PdfSolidBrush(Syncfusion.Drawing.Color.Black); 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(); //Load the image as stream. FileStream imageStream = new FileStream("logo.png", FileMode.Open, FileAccess.Read); PdfBitmap image = new PdfBitmap(imageStream); graphics.DrawImage(image, 200, 200); //Draw the image Syncfusion.Drawing.RectangleF bounds = new Syncfusion.Drawing.RectangleF(0, 0, doc.Pages[0].GetClientSize().Width, 50); PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); PdfCompositeField compField = new PdfCompositeField(bigFont, brush, "OZO - Izvjestaj o natjecajima"); compField.Draw(header.Graphics, new Syncfusion.Drawing.PointF(120, 0)); //Add the header at the top. doc.Template.Top = header; //Save the PDF document to stream //Create a Page template that can be used as footer. PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, brush); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Stranica {0} od {1}", pageNumber, count); compositeField.Bounds = footer.Bounds; //Draw the composite field in footer. compositeField.Draw(footer.Graphics, new Syncfusion.Drawing.PointF(450, 40)); //Add the footer template at the bottom. doc.Template.Bottom = footer; MemoryStream stream = new MemoryStream(); //Add values to list List <object> data = new List <object>(); switch (vrsta) { case "Naziv": var natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Naziv.Equals(id)) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); break; case "Cijena": int cijena = int.Parse(id); if (znak == "manje") { natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Cijena < cijena) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); } else if (znak == "vise") { natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Cijena > cijena) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); } else { natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Cijena.Equals(cijena)) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); } break; case "Poslodavac": natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Poslodavac.Equals(id)) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); break; case "Status": bool stanje = bool.Parse(id); natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Status.Equals(stanje)) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); break; case "Lokacija": natječaji = _context.Natječaj .AsNoTracking() .Where(n => n.Lokacija.Equals(id)) .OrderBy(o => o.Id) .ToList(); ispisi(natječaji, data); break; default: Console.WriteLine("Niste unijeli string"); break; } //Add list to IEnumerable IEnumerable <object> dataTable = data; //Assign data source. pdfGrid.DataSource = dataTable; pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(50, 50)); 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 = "Natječaji-Reports.pdf"; return(File(stream, contentType, fileName)); }
void DrawAutomaticField(String fieldName, PdfPageBase page, RectangleF bounds) { PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic)); PdfBrush brush = PdfBrushes.OrangeRed; PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Middle); if ("DateTimeField" == fieldName) { PdfDateTimeField field = new PdfDateTimeField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.DateFormatString = "yyyy-MM-dd HH:mm:ss"; field.Draw(page.Canvas); } if ("CreationDateField" == fieldName) { PdfCreationDateField field = new PdfCreationDateField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.DateFormatString = "yyyy-MM-dd HH:mm:ss"; field.Draw(page.Canvas); } if ("DocumentAuthorField" == fieldName) { PdfDocumentAuthorField field = new PdfDocumentAuthorField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("SectionNumberField" == fieldName) { PdfSectionNumberField field = new PdfSectionNumberField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("SectionPageNumberField" == fieldName) { PdfSectionPageNumberField field = new PdfSectionPageNumberField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("SectionPageCountField" == fieldName) { PdfSectionPageCountField field = new PdfSectionPageCountField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("PageNumberField" == fieldName) { PdfPageNumberField field = new PdfPageNumberField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("PageCountField" == fieldName) { PdfPageCountField field = new PdfPageCountField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Draw(page.Canvas); } if ("DestinationPageNumberField" == fieldName) { PdfDestinationPageNumberField field = new PdfDestinationPageNumberField(); field.Font = font; field.Brush = brush; field.StringFormat = format; field.Bounds = bounds; field.Page = page as PdfNewPage; field.Draw(page.Canvas); } if ("CompositeField" == fieldName) { PdfSectionPageNumberField field1 = new PdfSectionPageNumberField(); field1.NumberStyle = PdfNumberStyle.LowerRoman; PdfSectionPageCountField field2 = new PdfSectionPageCountField(); PdfCompositeField fields = new PdfCompositeField(); fields.Font = font; fields.Brush = brush; fields.StringFormat = format; fields.Bounds = bounds; fields.AutomaticFields = new PdfAutomaticField[] { field1, field2 }; fields.Text = "section page {0} of {1}"; fields.Draw(page.Canvas); } }
private void GeneratePDF_Click(object sender, RoutedEventArgs e) { //Create a new PDF document. PdfDocument document = new PdfDocument(); //Add a page to the document. PdfPage page = document.Pages.Add(); //Create bounds to draw a image. RectangleF imageRect = new RectangleF(50, 50, 425, 642); //Get the image file stream from assembly. Stream imageStream = typeof(EBook).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Pdf_Succinctly_img_1.jpg"); //Create new image from stream. PdfBitmap image = new PdfBitmap(imageStream); //Draw image to PDF page. page.Graphics.DrawImage(image, imageRect); //Add a page to the document. PdfPage titlePage = document.Pages.Add(); //Create font, string format and text bounds. PdfStandardFont times30Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 30); RectangleF textRect = new RectangleF(0, 60, titlePage.GetClientSize().Width, titlePage.GetClientSize().Height); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Center); //Draw a text to PDF page. titlePage.Graphics.DrawString("PDF Succinctly", times30Font, PdfBrushes.Black, textRect, format); //Create bounds to draw a image. imageRect = new RectangleF(40, 110, 435, 5); //Get the template PDF file stream from assembly. imageStream = typeof(EBook).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Pdf_Succinctly_img_5.jpg"); //Create new image from stream. image = new PdfBitmap(imageStream); //Draw image to PDF page. titlePage.Graphics.DrawImage(image, imageRect); //Create font, text bounds to draw a string to PDF page. PdfFont helvetica16 = new PdfStandardFont(PdfFontFamily.Helvetica, 16, PdfFontStyle.Bold); textRect = new RectangleF(0, 130, titlePage.GetClientSize().Width, titlePage.GetClientSize().Height); titlePage.Graphics.DrawString("By\nRyan Hodson", helvetica16, PdfBrushes.Black, textRect, format); //Create font, text bounds to draw a string to PDF page. PdfFont helvetica20 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); textRect = new RectangleF(0, 220, titlePage.GetClientSize().Width, titlePage.GetClientSize().Height); titlePage.Graphics.DrawString("Foreword by Daniel Jebaraj", helvetica20, PdfBrushes.Black, textRect, format); //Add new section to PDF document. PdfSection section = document.Sections.Add(); //Add a new page to section. PdfPage contentPage = section.Pages.Add(); //Add a new text content to PDF page. AddParagraph(contentPage, "Table of Contents", new RectangleF(20, 60, 495, contentPage.GetClientSize().Height), true, true); //Create a header template and draw a text. PdfPageTemplateElement headerElement = new PdfPageTemplateElement(new Rectangle(0, 0, 515, 50), contentPage); //Set transparency to header graphics. headerElement.Graphics.SetTransparency(0.6F); //Create alignment and string format for header content. PdfTextAlignment textAlingment = PdfTextAlignment.Right; PdfVerticalAlignment verticalAlignment = PdfVerticalAlignment.Middle; format = new PdfStringFormat(textAlingment, verticalAlignment); //Draw text to header template. headerElement.Graphics.DrawString("PDF Succinctly", new PdfStandardFont(PdfFontFamily.Helvetica, 10), PdfBrushes.Black, new RectangleF(0, 0, 515, 50), format); //Draw line to header template. headerElement.Graphics.DrawLine(PdfPens.Gray, new PointF(0, 49), new PointF(515, 49)); //Set the top page template. section.Template.Top = headerElement; //Create a footer template and draw a text. PdfPageTemplateElement footerElement = new PdfPageTemplateElement(new RectangleF(0, 0, 515, 50), contentPage); //Set transparency to header graphics. footerElement.Graphics.SetTransparency(0.6F); //Create new font to draw the content in footer template. PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 7); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, PdfBrushes.Black); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, PdfBrushes.Black); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, PdfBrushes.Black, "Page {0} of {1}", pageNumber, count); compositeField.Bounds = footerElement.Bounds; //Draw the composite field in footer. compositeField.Draw(footerElement.Graphics, new PointF(450, 35)); //Set the bottom page template. section.Template.Bottom = footerElement; //Add a new PDF page to PDF document. page = document.Pages.Add(); SizeF pageSize = page.GetClientSize(); //Add a new text content to PDF page and get layout result. PdfLayoutResult result = AddParagraph(page, "Introduction", new RectangleF(20, 25, 495, pageSize.Height), true, true); //Add to table of content and get layout result. PdfLayoutResult tableContent = AddTableOfContents(contentPage, "Introduction", new RectangleF(20, 110, 470, result.Page.GetClientSize().Height), true, 4, 20, result.Bounds.Top, result.Page); //Create color for bookmark. PdfColor bookmarkColor = new PdfColor(0, 0, 0); //Add bookmark to PDF page. AddBookmark(page, "Introduction", result.Bounds.Location, document, null, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Adobe Systems Incorporated\'s Portable Document Format (PDF) is the de facto standard for the accurate, reliable, and platform-independent representation of a paged document. It\'s the only universally accepted file format that allows pixel-perfect layouts. In addition, PDF supports user interaction and collaborative workflows that are not possible with printed documents.\n\nPDF documents have been in widespread use for years, and dozens of free and commercial PDF readers, editors, and libraries are readily available. However, despite this popularity, it\'s still difficult to find a succinct guide to the native PDF format. Understanding the internal workings of a PDF makes it possible to dynamically generate PDF documents. For example, a web server can extract information from a database, use it to customize an invoice, and serve it to the customer on the fly.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false, false); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "The PDF Standard", new RectangleF(20, result.Bounds.Bottom + 25, 495, pageSize.Height), true, false); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "The PDF Standard", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 4, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "The PDF Standard", result.Bounds.Location, document, null, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "The PDF format is an open standard maintained by the International Organization for Standardization. The official specification is defined in ISO 32000-1:2008, but Adobe also provides a free, comprehensive guide called PDF Reference, Sixth Edition, version 1.7.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Chapter 1 Conceptual Overview", new RectangleF(20, result.Bounds.Bottom + 25, 495, pageSize.Height), true, true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Chapter 1 Conceptual Overview", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), true, 4, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. PdfBookmark standardBookmark = AddBookmark(result.Page, "Chapter 1 Conceptual Overview", result.Bounds.Location, document, null, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "We\'ll begin with a conceptual overview of a simple PDF document. This chapter is designed to be a brief orientation before diving in and creating a real document from scratch.\nA PDF file can be divided into four parts: a header, body, cross-reference table, and trailer. The header marks the file as a PDF, the body defines the visible document, the cross-reference table lists the location of everything in the file, and the trailer provides instructions for how to start reading the file.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new PDF page to PDF document. PdfPage page2 = document.Pages.Add(); //Get the image file stream from assembly. Stream imageStream1 = typeof(EBook).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Pdf_Succinctly_img_2.jpg"); //Create PDF bitmap image from stream. PdfBitmap bitmap = new PdfBitmap(imageStream1); //Draw the image to PDF page. page2.Graphics.DrawImage(bitmap, new RectangleF(10, 0, 495, 600)); //Add a new text content to PDF page and get layout result. result = AddParagraph(page2, "Every PDF file must have these four components.", new RectangleF(20, 620, 495, page2.GetClientSize().Height), false); //Add a new text content to PDF page and get layout result. result = AddParagraph(document.Pages.Add(), "Header", new RectangleF(20, 15, 495, pageSize.Height), true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Header", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 6, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "Header", result.Bounds.Location, null, standardBookmark, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "The header is simply a PDF version number and an arbitrary sequence of binary data. The binary data prevents na�ve applications from processing the PDF as a text file. This would result in a corrupted file, since a PDF typically consists of both plain text and binary data (e.g., a binary font file can be directly embedded in a PDF).", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Body", new RectangleF(20, result.Bounds.Bottom + 25, 495, pageSize.Height), true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Body", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 6, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "Body", result.Bounds.Location, null, standardBookmark, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "The body of a PDF contains the entire visible document. The minimum elements required in a valid PDF body are:\n\n1. A page tree \n2. Pages \n3. Resources \n4. Content \n5. The catalog \n\nThe page tree serves as the root of the document. In the simplest case, it is just a list of the pages in the document. Each page is defined as an independent entity with metadata (e.g., page dimensions) and a reference to its resources and content, which are defined separately. Together, the page tree and page objects create the \"paper\" that composes the document.\n\nResources are objects that are required to render a page. For example, a single font is typically used across several pages, so storing the font information in an external resource is much more efficient. A content object defines the text and graphics that actually show up on the page. Together, content objects and resources define the appearance of an individual page.\nFinally, the document\'s catalog tells applications where to start reading the document. Often, this is just a pointer to the root page tree.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new PDF page to PDF document. PdfPage page3 = document.Pages.Add(); //Get the image file stream from assembly. Stream imageStream2 = typeof(EBook).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Pdf_Succinctly_img_3.jpg"); //Create PDF bitmap image from stream. PdfBitmap bitmap2 = new PdfBitmap(imageStream2); //Draw the image to PDF page. page3.Graphics.DrawImage(bitmap2, new RectangleF(20, 0, 300, 400)); //Add a new text content to PDF page and get layout result. result = AddParagraph(page3, "Cross-Reference Table", new RectangleF(20, 425, 495, pageSize.Height), true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Cross-Reference Table", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 7, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "Cross-Reference Table", result.Bounds.Location, null, standardBookmark, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "After the header and the body comes the cross-reference table. It records the byte location of each object in the body of the file. This enables random-access of the document, so when rendering a page, only the objects required for that page are read from the file. This makes PDFs much faster than their PostScript predecessors, which had to read in the entire file before processing it.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Trailer", new RectangleF(20, result.Bounds.Bottom + 25, 495, pageSize.Height), true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Trailer", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 7, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "Trailer", result.Bounds.Location, null, standardBookmark, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Finally, we come to the last component of a PDF document. The trailer tells applications how to start reading the file. At minimum, it contains three things:\n\n\n1. A reference to the catalog which links to the root of the document.\n2. The location of the cross-reference table.\n3. The size of the cross-reference table.\n\nSince a trailer is all you need to begin processing a document, PDFs are typically read back-to-front: first, the end of the file is found, and then you read backwards until you arrive at the beginning of the trailer. After that, you should have all the information you need to load any page in the PDF.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "Summary", new RectangleF(20, result.Bounds.Bottom + 25, 495, pageSize.Height), true); //Add to table of content and get layout result. tableContent = AddTableOfContents(tableContent.Page, "Summary", new RectangleF(20, tableContent.Bounds.Bottom, 470, result.Page.GetClientSize().Height), false, 8, 20, result.Bounds.Top, result.Page); //Add bookmark to PDF page. AddBookmark(result.Page, "Summary", result.Bounds.Location, null, standardBookmark, bookmarkColor); //Add a new text content to PDF page and get layout result. result = AddParagraph(result.Page, "To conclude our overview, a PDF document has a header, a body, a cross-reference table, and a trailer. The trailer serves as the entryway to the entire document, giving you access to any object via the cross-reference table, and pointing you toward the root of the document. The relationship between these elements is shown in the following figure.", new RectangleF(20, result.Bounds.Bottom + 20, 495, pageSize.Height), false); //Get the image file stream from assembly. Stream imageStream3 = typeof(EBook).GetTypeInfo().Assembly.GetManifestResourceStream("syncfusion.pdfdemos.winui.Assets.Pdf_Succinctly_img_4.jpg"); //Create PDF bitmap image from stream. PdfBitmap bitmap3 = new PdfBitmap(imageStream3); //Draw the image to PDF page. result.Page.Graphics.DrawImage(bitmap3, new RectangleF(20, result.Bounds.Bottom + 20, 495, 400)); //Creating the stream object. using (MemoryStream stream = new MemoryStream()) { //Save the document into stream. document.Save(stream); document.Close(); stream.Position = 0; //Save the output stream as a file using file picker. PdfUtil.Save("E-Book.pdf", stream); } }
private void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin) { PdfPageTemplateElement leftSpace = new PdfPageTemplateElement(margin.Left, pageSize.Height); doc.Template.Left = leftSpace; PdfPageTemplateElement topSpace = new PdfPageTemplateElement(pageSize.Width, margin.Top); topSpace.Foreground = true; doc.Template.Top = topSpace; //draw header label PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic)); PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Right); String label = "Demo of Spire.Pdf"; SizeF size = font.MeasureString(label, format); float y = topSpace.Height - font.Height - 1; PdfPen pen = new PdfPen(Color.Black, 0.75f); topSpace.Graphics.SetTransparency(0.5f); topSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y); y = y - 1 - size.Height; topSpace.Graphics.DrawString(label, font, PdfBrushes.Black, pageSize.Width - margin.Right, y, format); PdfPageTemplateElement rightSpace = new PdfPageTemplateElement(margin.Right, pageSize.Height); doc.Template.Right = rightSpace; PdfPageTemplateElement bottomSpace = new PdfPageTemplateElement(pageSize.Width, margin.Bottom); bottomSpace.Foreground = true; doc.Template.Bottom = bottomSpace; //draw footer label y = font.Height + 1; bottomSpace.Graphics.SetTransparency(0.5f); bottomSpace.Graphics.DrawLine(pen, margin.Left, y, pageSize.Width - margin.Right, y); y = y + 1; PdfPageNumberField pageNumber = new PdfPageNumberField(); PdfPageCountField pageCount = new PdfPageCountField(); PdfCompositeField pageNumberLabel = new PdfCompositeField(); pageNumberLabel.AutomaticFields = new PdfAutomaticField[] { pageNumber, pageCount }; pageNumberLabel.Brush = PdfBrushes.Black; pageNumberLabel.Font = font; pageNumberLabel.StringFormat = format; pageNumberLabel.Text = "page {0} of {1}"; pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - margin.Right, y); PdfImage headerImage = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Header.png"); PointF pageLeftTop = new PointF(-margin.Left, -margin.Top); PdfPageTemplateElement header = new PdfPageTemplateElement(pageLeftTop, headerImage.PhysicalDimension); header.Foreground = false; header.Graphics.SetTransparency(0.5f); header.Graphics.DrawImage(headerImage, 0, 0); doc.Template.Stamps.Add(header); PdfImage footerImage = PdfImage.FromFile(@"..\..\..\..\..\..\Data\Footer.png"); y = pageSize.Height - footerImage.PhysicalDimension.Height; PointF footerLocation = new PointF(-margin.Left, y); PdfPageTemplateElement footer = new PdfPageTemplateElement(footerLocation, footerImage.PhysicalDimension); footer.Foreground = false; footer.Graphics.SetTransparency(0.5f); footer.Graphics.DrawImage(footerImage, 0, 0); doc.Template.Stamps.Add(footer); }
private FileStreamResult ExportPDF(List <EOD> edo) { // Load the PDF Template Stream pdfStream = System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + @"\assets\templates\CloseShop2.pdf"); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, (float)8); //PdfFont fontText = new PdfStandardFont(PdfFontFamily.Helvetica, (float)12); PdfFont fontTextTHSarabunNew = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\THSarabunNew\THSarabunNew Bold.ttf"), 15); PdfFont fontTextCalibri = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\calibri\Calibri.ttf"), 13); PdfFont fontTextCalibriBold = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\calibri\Calibri.ttf"), 13, PdfFontStyle.Bold); // Load a PDF document. PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream); //Create a new PDF document. PdfDocument pdfDocument = new PdfDocument(); int numPage = 1; PdfPage pdfPage; //Set the format for string. PdfStringFormat formatAlignRight = new PdfStringFormat(PdfTextAlignment.Right); PdfStringFormat formatAlignCenter = new PdfStringFormat(PdfTextAlignment.Center); edo.ForEach(e => { pdfDocument.ImportPage(loadedDocument, 0); pdfPage = pdfDocument.Pages[numPage - 1]; // Create PDF graphics for the page PdfGraphics graphics = pdfPage.Graphics; float xPosition = 105; float yPosition = (float)85.5;//106.5; float gap = (float)20.5; #region Header Left // Branch Name graphics.DrawString(e.BranchName.Replace("KERRY EXPRESS", "Kerry Express"), fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition)); // Date yPosition += gap; graphics.DrawString(e.Report_Date.ToString("dd-MMMM-yyyy", _cultureTHInfo), fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition)); // Branch ID yPosition += gap + (float)1; graphics.DrawString(e.BranchID, fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition)); // Cost Center yPosition += gap + (float)1; graphics.DrawString(e.ERPID, fontTextTHSarabunNew, PdfBrushes.Black, new PointF(xPosition, yPosition)); #endregion #region Header Right // Branch Type xPosition = (float)464; yPosition = (float)107; graphics.DrawString(e.BranchType.Split('-')[0], fontTextCalibri, PdfBrushes.Black, new PointF(xPosition - (float)14.5, yPosition), formatAlignCenter); // Total Transfer xPosition = (float)555.31; yPosition = (float)107; graphics.DrawString(e.TotalTransfer.ToString("N"), fontTextCalibriBold, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Shipment yPosition += gap; graphics.DrawString(e.TotalShipments.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Boxes yPosition += gap; graphics.DrawString(e.TotalBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #endregion #region Detail Service xPosition = (float)281.585; yPosition = (float)219; gap = (float)19; // Transport Service graphics.DrawString(e.TransportService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // AM Service yPosition += gap - 1; graphics.DrawString(e.AMService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // PUP Service yPosition += gap - 2; graphics.DrawString(e.PUPService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // SAT Service yPosition += gap - 1; graphics.DrawString(e.SATService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // RAS Service yPosition += gap - 1; graphics.DrawString(e.RASService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // COD Service yPosition += gap - 1; graphics.DrawString(e.CODService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // INSUR Service yPosition += gap - 1; graphics.DrawString(e.INSURService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Package Service yPosition += gap - 2; graphics.DrawString(e.PACKAGEService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Sale Package Service yPosition += gap - 1; graphics.DrawString(e.SALEService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Discount yPosition += gap + 1; graphics.DrawString(e.Discount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Line Top-up Service yPosition += gap - 1; graphics.DrawString(e.LNTUPService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); //rabbitTopUp yPosition += gap + 2; graphics.DrawString(e.rabbitTopUp.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); //mPayService yPosition += gap - 1; graphics.DrawString(e.mPayService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Shipments yPosition += gap; graphics.DrawString(e.Shipment.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Boxes yPosition += gap + 2; graphics.DrawString(e.Boxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Drop-off Boxes yPosition += gap + 2; graphics.DrawString(e.DropOffBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Detail Service yPosition += (float)34.5; graphics.DrawString(e.TotalDetailService.ToString("N"), fontTextCalibriBold, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #endregion // Total Freight Revenue yPosition += (float)26; graphics.DrawString(e.TotalFreightRevenue.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #region Detail Pay xPosition = (float)555.31; yPosition = (float)219.5; gap = (float)19; // Cash graphics.DrawString(e.Cash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Rabbit yPosition += gap + 2; graphics.DrawString(e.Rabbit.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Credit Card BBL yPosition += gap + 2; graphics.DrawString(e.CreditBBL.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Credit Card SCB yPosition += gap + 2; graphics.DrawString(e.CreditSCB.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Credit QR Payment yPosition += gap + 2; graphics.DrawString(e.QRPay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // LinePay yPosition += gap + 2; graphics.DrawString(e.LinePay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Detail Pay yPosition += (float)32; graphics.DrawString(e.TotalDetailPay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #endregion #region Detail Surcharge yPosition = (float)439.5; gap = (float)19; // Transportation graphics.DrawString(e.Transportation.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // VAS Surcharge yPosition += gap + 2; graphics.DrawString(e.VASSurcharge.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Discount yPosition += gap + 2; graphics.DrawString(e.Discount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Vat yPosition += gap + 2; graphics.DrawString(e.VAT.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Detail Surcharge yPosition += (float)29; graphics.DrawString(e.TotalDetailSurcharge.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #endregion #region BSD Surcharge xPosition = (float)281.585; yPosition = (float)632.5; gap = (float)19; // CITY graphics.DrawString(e.BSDCity.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // CITYN yPosition += gap + 2; graphics.DrawString(e.BSDCityn.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // CITYS yPosition += gap + 2; graphics.DrawString(e.BSDCitys.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Grab yPosition += gap + 2; graphics.DrawString(e.BSDGrab.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Discount yPosition += gap + 2; graphics.DrawString(e.BSDDiscount.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total yPosition += gap + (float)12.5; graphics.DrawString(e.BSDTotalDetailService.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Consignment yPosition += gap + 12; graphics.DrawString(e.BSDConsignment.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); #endregion #region BSD Surcharge xPosition = (float)555.31; yPosition = (float)632.5; gap = (float)19; // Cash graphics.DrawString(e.BSDCash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Line Pay yPosition += gap + 2; graphics.DrawString(e.BSDLinePay.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Payment yPosition += gap + 2; graphics.DrawString(e.BSDTotalPayment.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Line Topup yPosition += gap + 2; graphics.DrawString(e.BSDLineTopUp.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Dummy yPosition += gap + 2; graphics.DrawString("", fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Payment Cash yPosition += gap + (float)12.5; graphics.DrawString(e.BSDTotalPaymentCash.ToString("N"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Total Payment Boxes yPosition += gap + 12; graphics.DrawString(e.BSDBoxes.ToString("N0"), fontTextCalibri, PdfBrushes.Black, new PointF(xPosition, yPosition), formatAlignRight); // Lasted Update string closedDate = e.LastedUpdate.HasValue ? e.LastedUpdate.Value.ToString("dd MMM yyyy HH:mm:ss", _cultureENInfo) : "N/A"; yPosition += gap + (float)7.8; xPosition = pdfDocument.Pages[0].GetClientSize().Width - 24; graphics.DrawString($"Closed Date/Time : {closedDate}", font, PdfBrushes.Red, new PointF(xPosition, yPosition), formatAlignRight); #endregion if (!(e.TotalDetailService.Equals(e.TotalDetailPay) && e.TotalDetailSurcharge.Equals(e.TotalDetailPay))) { //watermark text. PdfFont fontTextTHSarabunNewBold = new PdfTrueTypeFont(System.IO.File.OpenRead(_hostingEnvironment.WebRootPath + $@"\assets\fonts\THSarabunNew\THSarabunNew Bold.ttf"), 48); PdfGraphicsState state = graphics.Save(); graphics.SetTransparency(0.50f); graphics.RotateTransform(-40); graphics.DrawString("ข้อมูลไม่ถูกต้อง โปรดติดต่อผู้ดูแลระบบ", fontTextTHSarabunNewBold, PdfPens.Red, PdfBrushes.Red, new PointF(-300, 460)); } numPage++; }); //Set properties to paginate the table. PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); layoutFormat.Break = PdfLayoutBreakType.FitElement; layoutFormat.Layout = PdfLayoutType.Paginate; layoutFormat.PaginateBounds = new RectangleF(20, 20, pdfDocument.Pages[0].GetClientSize().Width - 40, pdfDocument.Pages[0].GetClientSize().Height - 50); //Create a Page template that can be used as footer. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 50); PdfPageTemplateElement footer = new PdfPageTemplateElement(bounds); PdfBrush brush = new PdfSolidBrush(Color.Black); //Create page number field. PdfPageNumberField pageNumber = new PdfPageNumberField(font, brush); //Create page count field. PdfPageCountField count = new PdfPageCountField(font, brush); //Add the fields in composite fields. PdfCompositeField compositeField = new PdfCompositeField(font, brush, "Page {0} of {1}", pageNumber, count); string printDate = DateTime.Now.ToString("dd MMM yyyy HH:mm:ss", _cultureENInfo); PdfCompositeField compositePrintDate = new PdfCompositeField(font, brush, string.Format("Printed from PDC/CloseShop Printed Date/Time : {0}", printDate)); compositeField.Bounds = footer.Bounds; //Draw the composite field in footer. compositeField.Draw(footer.Graphics, new PointF(pdfDocument.Pages[0].GetClientSize().Width - (float)63.5, 30)); compositePrintDate.Draw(footer.Graphics, new PointF((float)24, 30)); //Add the footer template at the bottom. pdfDocument.Template.Bottom = footer; MemoryStream ms = new MemoryStream(); pdfDocument.Save(ms); ms.Position = 0; //Close the document pdfDocument.Close(true); // Close file pdfStream.Dispose(); //Save the document. return(File(ms, "Application/pdf")); }