![]() Create a new PDF document setting the size to A4 Using (FileStream fs = new FileStream(outputFile, FileMode.Create, FileAccess.Write, FileShare.None)) Net FileStream for the file, setting various flags String outputFile = Path.Combine(Environment.GetFolderPath(), "Sample.pdf") This is the absolute path to the PDF that we will create Private void Form1_Load(object sender, EventArgs e) See the comments in the code for more of an explanation. Then use the following code which is a full-working WinForms app that creates a very basic table in an A4 document. In here, we are creating an instance of the CustomAssemblyLoadContext class and just call the LoadUnmanagedLibrary method with the path of the libwkhtmltox.dll file.As Skeet said, you can use iTextSharp (which is a C# port of the Java iText).įirst, download iTextSharp (currently 5.1.2), extract itextsharp.dll to some location and add a reference to it in Visual Studio. Services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())) Var context = new CustomAssemblyLoadContext() Ĭontext.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), "libwkhtmltox.dll")) Public void ConfigureServices(IServiceCollection services) Protected override Assembly Load(AssemblyName assemblyName)Īfter that, let’s modify the ConfigureServices method in the StartUp class: Return LoadUnmanagedDllFromPath(unmanagedDllName) Protected override IntPtr LoadUnmanagedDll(string unmanagedDllName) Public IntPtr LoadUnmanagedLibrary(string absolutePath) ![]() Let’s do that step by step.įirst, in the Utility folder we are going to add a new class CustomAssemblyLoadContext and modify it: internal class CustomAssemblyLoadContext : AssemblyLoadContext If we want to deploy this application, we have to make some changes. New Employee Įverything is working as it supposed to. NET/C# content and get paid? > JOIN US! GetAllEmployees() => Wanna join Code Maze Team, help us produce more awesome.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |