Posts

Showing posts from April, 2022

HTML to PDF

Add this nuget package HtmlRenderer.PdfSharp Generate a PDF document string htmlString = "<h1>Document</h1> <p>This is an HTML document which is converted to a pdf file.</p>"; PdfDocument pdfDocument = PdfGenerator.GeneratePdf(htmlString, PageSize.A4); To save to disk pdfDocument.Save("C:/temp/HTML to PDF Document.pdf"); To convert to byte array using (MemoryStream ms = new MemoryStream()) { pdfDocument.Save(ms); byte[] byteArray = ms.ToArray(); .... }

MiniProfiler in ASP.NET Core

 To install dotnet add package MiniProfiler.AspNetCore.Mvc dotnet add package MiniProfiler.EntityFrameworkCore To configure public void ConfigureServices(IServiceCollection services) { .... services.AddMiniProfiler(options => options.RouteBasePath = "/profiler").AddEntityFramework(); .... } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseMiniProfiler(); /* Code removed for brevity. */ } To access a list of all requests, navigate to /profiler/results-index To profile methods in a class libray, add this nuget package MiniProfiler.AspNetCore Wrap the piece of code like this using (MiniProfiler.Current.Step("InsertUpdateBillAsync")) { ..... } To wrap a single line await MiniProfiler.Current.Inline(async () => await ProcessCommitteeAsync(bill.committee), "ProcessCommitteeAsync");

Adding CKEditor 4 to Angular

You can add CKEditor 4 to angular following instruction from here . Add ckeditor using npm: npm install ckeditor4-angular After installing, import CKEditorModule to your application: import { CKEditorModule } from 'ckeditor4-angular'; @NgModule( { imports: [ ... CKEditorModule, ... ], … } ) Use the  CKEditor 4 online builder to quickly customize and generate ckeditor files. Unzip the generated file and copy the ckeditor folder into your projects assets folder.  In index.html, add a script reference to ckeditor: <script src="assets/ckeditor/ckeditor.js"></script> Then in a component, you can use ckeditor like this: <ckeditor data="<p>Hello, world!</p>"></ckeditor>