コード例 #1
0
        /// <summary>
        /// 添加Excel功能
        /// </summary>
        /// <param name="services"></param>
        /// <param name="cfg"></param>
        /// <returns></returns>
        public static IServiceCollection AddPdf(this IServiceCollection services, IConfiguration cfg)
        {
            var config  = new PdfConfig();
            var section = cfg.GetSection("Pdf");

            if (section != null)
            {
                section.Bind(config);
            }

            services.AddSingleton(config);

            var assembly = AssemblyHelper.LoadByNameEndString($".Lib.Pdf.{config.Provider.ToString()}");

            if (assembly == null)
            {
                return(services);
            }

            var handlerType = assembly.GetTypes().FirstOrDefault(m => m.Name.EndsWith("PdfHandler"));

            if (handlerType != null)
            {
                services.AddSingleton(typeof(IPdfHandler), handlerType);
            }

            return(services);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: sbc77/templator
        private static void GenerateInvoice()
        {
            var data = GetInvoiceData();

            var cfg = new PdfConfig
            {
                FontPaths = new [] { "/Library/Fonts" } // this is configured for mac, on windows you have to change it
            };

            var bytes = Templator.Create("Template/invoice.xml")
                        .UsePdfRenderer(cfg)
                        .Render(data);

            File.WriteAllBytes("Result/invoice.pdf", bytes);
        }
コード例 #3
0
ファイル: Index.cshtml.cs プロジェクト: sbc77/templator
        public async Task <IActionResult> OnGetAsync()
        {
            var cfg = new PdfConfig
            {
                FontPaths = new[] { "/Library/Fonts" },
            };

            var bytes = Templator
                        .Create("print.xml")
                        .UsePdfRenderer(cfg)
                        .Render(GetData());

            await Task.CompletedTask;

            return(this.File(bytes, "application/pdf"));
        }
コード例 #4
0
ファイル: ScriptingEngine.cs プロジェクト: Maasik/ax-toolbox
        private PdfHelper NewEmptyPdfFlightReport(string pdfFileName)
        {
            var assembly   = GetType().Assembly;
            var aName      = assembly.GetName();
            var aTitle     = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            var aCopyright = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);

            Debug.Assert(aTitle.Length > 0 && aCopyright.Length > 0, "Assembly information incomplete");

            var programInfo = string.Format("{0} {2}",
                                            ((AssemblyTitleAttribute)aTitle[0]).Title,
                                            aName.Version,
                                            ((AssemblyCopyrightAttribute)aCopyright[0]).Copyright);

            var config = new PdfConfig(PdfConfig.Application.FlightAnalyzer)
            {
                HeaderLeft  = Settings.Title,
                HeaderRight = Settings.Subtitle,
                FooterRight = programInfo
            };

            var helper = new PdfHelper(pdfFileName, config);

            helper.Document.Add(new Paragraph("Automatic Flight Report", config.TitleFont));

            var table = helper.NewTable(null, new float[] { 1, 1 });

            table.WidthPercentage     = 50;
            table.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(helper.NewLCell("Flight Date:"));
            table.AddCell(helper.NewLCell(Settings.Date.GetDateAmPm()));
            table.AddCell(helper.NewLCell("Pilot number:"));
            table.AddCell(helper.NewLCell(Report.PilotId.ToString()));
            table.AddCell(helper.NewLCell("Logger serial number:"));
            table.AddCell(helper.NewLCell(Report.LoggerSerialNumber));
            table.AddCell(helper.NewLCell("Debriefers:"));
            table.AddCell(helper.NewLCell(Report.Debriefers.Aggregate((acc, item) => acc + ", " + item)));
            helper.Document.Add(table);

            return(helper);
        }
コード例 #5
0
 public TemplateGenerator(IService <Konsultant> service, IMapper mapper, IOptions <PdfConfig> options)
 {
     _service = service;
     _mapper  = mapper;
     _options = options.Value;
 }
コード例 #6
0
ファイル: PdfTest.cs プロジェクト: Maasik/ax-toolbox
        public PdfTestClass(string pdfFileName)
        {
            var config = new PdfConfig(PdfConfig.Application.Scorer)
            {
                MarginTop    = 1.5f * PdfHelper.cm2pt,
                MarginBottom = 1.5f * PdfHelper.cm2pt,

                HeaderLeft  = "Sun table",
                HeaderRight = loc,
                FooterLeft  = string.Format("Printed on {0:yyyy/MM/dd HH:mm}", DateTime.Now),

                TitleFont    = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD),
                SubtitleFont = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD),
                BoldFont     = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD),
                NormalFont   = new Font(Font.FontFamily.HELVETICA, 6.5f, Font.NORMAL),
                HeaderFont   = new Font(Font.FontFamily.HELVETICA, 6.5f, Font.NORMAL),
                FooterFont   = new Font(Font.FontFamily.HELVETICA, 6.5f, Font.NORMAL)
            };
            var helper   = new PdfHelper(pdfFileName, config);
            var document = helper.Document;

            //title
            //document.Add(new Paragraph("Sun table", config.TitleFont)
            //{
            //    Alignment = Element.ALIGN_LEFT,
            //    SpacingAfter = 10
            //});

            //line separator
            //document.Add(new Paragraph(new Chunk(new LineSeparator())) { SpacingBefore = -10, SpacingAfter = 10 });

            //table
            var headers   = new string[] { "Date", "Dawn", "Dusk", "Outdoor activity time" };
            var relWidths = new float[] { 8, 2, 2, 3 };
            var table     = helper.NewTable(headers, relWidths);
            //var table = helper.NewTable(headers, relWidths, "Sun table"); //with table title

            //table body

            //compute cells
            var sun   = new Sun(lat, lng, DateTime.Now - DateTime.UtcNow);
            var today = DateTime.Now;
            //var from = today - new TimeSpan(10, 0, 0, 0);
            //var to = today + new TimeSpan(30, 0, 0, 0);

            var from = new DateTime(today.Year, 1, 1);
            var to   = new DateTime(today.Year, 12, 31);

            for (var date = from; date <= to; date += new TimeSpan(1, 0, 0, 0))
            {
                var dawn = sun.Sunrise(date, Sun.ZenithTypes.Custom);
                var dusk = sun.Sunset(date, Sun.ZenithTypes.Custom);
                var span = dusk - dawn;

                //strings
                var strDate = date.ToString("D", DateTimeFormatInfo.InvariantInfo);
                var strDawn = dawn.ToString("HH:mm");
                var strDusk = dusk.ToString("HH:mm");
                var strSpan = span.ToString("hh\\:mm");

                //place cells in table
                table.AddCell(helper.NewLCell(strDate));
                table.AddCell(helper.NewRCell(strDawn));
                table.AddCell(helper.NewRCell(strDusk));
                table.AddCell(helper.NewRCell(strSpan));

                //var cell = helper.NewCell("Cell with colspan 2");
                //cell.Colspan = 2;
                //table.AddCell(cell);
            }

            //Place table on document

            ////normal layout
            //document.Add(table);

            ////page break
            //document.NewPage();

            //multicolumn layout
            MultiColumnText columns = new MultiColumnText();

            columns.AddRegularColumns(
                PdfHelper.cm2pt,                           //L-margin in pt
                document.PageSize.Width - PdfHelper.cm2pt, //R-margin in pt
                0.35f * PdfHelper.cm2pt,                   //separation in pt
                4);                                        //# of cols
            columns.AddElement(table);
            document.Add(columns);

            document.Close();
        }
コード例 #7
0
        private void SavePdf_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var fileName = Helper.SaveFile(".pdf files (*.pdf)|*.pdf");

            if (!string.IsNullOrEmpty(fileName))
            {
                var config = new PdfConfig(PdfConfig.Application.Scorer)
                {
                    MarginTop    = 1.5f * PdfHelper.cm2pt,
                    MarginBottom = 1.5f * PdfHelper.cm2pt,

                    HeaderLeft = Competition,
                    FooterLeft = "Datum " + DatumName + ", zone " + UtmZone
                };
                var helper = new PdfHelper(fileName, config);

                //title
                helper.Document.Add(new Paragraph("OFFICIAL WAYPOINT LIST", config.TitleFont)
                {
                    Alignment    = Element.ALIGN_CENTER,
                    SpacingAfter = 10
                });

                //line separator
                //document.Add(new Paragraph(new Chunk(new LineSeparator())) { SpacingBefore = -10, SpacingAfter = 10 });

                //table
                var headers   = new string[] { "Name", "Coordinates", "Altitude" };
                var relWidths = new float[] { 1, 2, 1 };
                var table     = helper.NewTable(headers, relWidths);
                //var table = helper.NewTable(headers, relWidths, "Sun table"); //with table title

                //table body

                foreach (var wp in Waypoints.Select(p => p.ToPdfWaypoint(DatumName, UtmZone, AltitudeUnits.Meters)))
                {
                    //place cells in table
                    table.AddCell(helper.NewLCell(wp.Name));
                    table.AddCell(helper.NewCCell(wp.CompetitionCoords));
                    table.AddCell(helper.NewRCell(wp.Altitude));
                }

                //Place table on document

                ////normal layout
                //helper.Document.Add(table);

                ////page break
                //document.NewPage();

                //multicolumn layout
                MultiColumnText columns = new MultiColumnText();
                columns.AddRegularColumns(
                    PdfHelper.cm2pt,                                  //L-margin in pt
                    helper.Document.PageSize.Width - PdfHelper.cm2pt, //R-margin in pt
                    0.35f * PdfHelper.cm2pt,                          //separation in pt
                    int.Parse(Columns));                              //# of cols
                columns.AddElement(table);
                helper.Document.Add(columns);

                helper.Document.Close();

                helper.OpenPdf();
            }
        }