예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            var engine = new RazorLightEngineBuilder()
                         //.UseEmbeddedResourcesProject(typeof(PdfTemplatesPlaceholder))
                         .UseFileSystemProject($"{RootPath}/PdfTemplates")
                         .UseMemoryCachingProvider()
                         .Build();

            services.AddSingleton <IRazorLightEngine>(engine);

            var nrecoConfig = Configuration.GetSection(nameof(NRecoConfig)).Get <NRecoConfig>();

            services.AddSingleton(nrecoConfig);

            var htmlToPdf = new HtmlToPdfConverter();

            htmlToPdf.License.SetLicenseKey(
                nrecoConfig.UserName,
                nrecoConfig.License
                );
            htmlToPdf.BeginBatch();
            services.AddSingleton(htmlToPdf);

            services.AddTransient <IPdfGeneratorService, PdfGeneratorService>();
            services.AddTransient <IHtmlGenerationService, HtmlGenerationService>();
        }
예제 #2
0
 public void GenerateInBatchModeTest()
 {
     _generator.BeginBatch();
     _generator.GeneratePdfFromFile("https://yandex.ru", null, Path.Combine(PDF_DIRECTORY, "yandex.pdf"));
     _generator.GeneratePdfFromFile("https://lenta.ru", null, Path.Combine(PDF_DIRECTORY, "lenta.pdf"));
     _generator.GeneratePdfFromFile("https://meduza.io", null, Path.Combine(PDF_DIRECTORY, "meduza.pdf"));
     _generator.EndBatch();
 }