The Easiest Way to Create PDFs in .NET

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everybody I'm Nick in this video I'm going to show you how you can get started with creating PDFs in your do net applications very very easily and I think the library we're going to Showcase in this video today is actually an amazing case study in developer experience because it solves all the things in my opinion that makes this sort of thing pretty hard to do PDF Creation in general is a total pain in where you you know where and it usually revolves around having wrappers around other low level libraries and so on but in this video we're going to see how easy it can be if you like content and you want to see more make you subscribe for more training check out my courses on do tr.com okay so let me show you what I have here and actually what I'm going to do in this video is actually just show you how we can build a very simple PDF page and we're going to do that by using a library Called Quest PDF now there other libraries that can sort of create PDFs or convert them from let's say HTML to PDFs but Quest PDF has a very very nice developer experience on creating them through a fluent API which I personally really like and it suits my use cases when I'm creating PDFs especially for invoices and stuff like that programmatically now you can install Quest PDF by simply searching for Quest PDF on new get and then installing the latest version and once you have that you can start working with it in any cop. net context now there's a few things I want to mention first and foremost Quest PDF is an open source Library so please use the link in the description if you like what you're going to see in this video and give it a star because because it really really helps the developers working on this product also they have sponsorships enabled so if you want to support the project financially then you can do it either monthly or with a onetime payment now I've personally decided that every time I'm showcasing a library and open source project on my YouTube videos if they have sponsorships enabled I will go ahead and do a onetime payment so in here I'm going to go ahead and donate a onetime donation of $250 here we go we have sponsored now the project and if you want to do the same then all the details are in the description the other thing I want to mention is that Quest PDF actually has a pricing Model A licensing model it is free for Developers for up to a million doar in annual gross revenue but then if you're a company with up to 10 developers you should pay $500 per year which is basically nothing if you're making the type of money and $2,000 a year for an unlimited amount of developers these are insanely small numbers and I have nothing against libraries that actually have a pricing model in fact I recommend it because we make OSS sustainable that way now with all that out of the way let's go straight into the implementation of creating a PDF and explain why I think quest PDF is so so cool now the first thing we need to do in your applications when you're using something like this is you actually have to specify what type of license you're using in the application and to do that I'm going to say Quest PDF settings and then license and I'm going to select the community license over here the moment we do that we're able to use it in our obligations there's no checking of a license key in our system Quest PDF sort of trust you that you're going to do the right thing and if you need to use um an Enterprise or a professional license you will do that now let's say we want to build a PDF well all we have to do to get started is say document and then use the fluent API and say create the moment we do that we have access to a container and in this top level container we can specify anything about our PDF now in the end you have a couple of options of what you want to do with this PDF for example you can just generate a PDF or you can generate an XPS file as well we're going to say generate PDF or images but the coolest thing about this library is that you can actually have a previewer a way to see how your PDF will look as you're building it and you can do that by saying show in previewer now to install the prevor you have to install a global tool this is very easy to do you just go to your console and you say net tool install Quest pdf. prev and then Global specifying that this is a global tool the moment you do that it's going to be downloaded and installed in your system and then you're able to use the previewer so this will look something like this all I'm going to do here is I'm going to go to the terminal actually and I'm going to say net watch to have hot reload kick in as I'm building my application and what's going to suddenly appear is actually an extra window let's wait for it here you go this is a quest PDF previewer we're going to see the page we're building in the PDF we're building as we're building it it's so so cool so I'm going to separate my PDF viewer and my ID so you can see both on the same page so now that I have both let's go ahead and start building our page so first I'm going to say container and then page to create my page and then I'm going to give this descriptor an alias call it page and start building it so the moment I save as you can see hot reload kicks in and now we have a view of the page over here I should be able to just zoom in a bit so you can see it better first I'm going to say page do size to specify a size and we can specify the page size using page sizes Dot and you can say A4 so paper A4 a01 to three in a bunch of different other sizes we're just going to say A4 here assuming we want to make something that we want to print now right below I'm going to say page do header and I'm going to create a header now the first thing I'm going to say is I want some text that text should be hello from Ryder again the moment I save you can see that the header actually just appears up here now and everything happens in real time now I can customize the text so I can say I want this to be a semi bolt for example and the moment I save that you can see the change then I want to specify a font size of 30 and everything is customizable here so you can also say like font color and say colors do I don't know Amber for some reason and you can use the medium type of Amber well this doesn't show great in the video so maybe change that for something like I don't know yellow that's even worse isn't it yes it is well I'm just going to go with Classic Blue that's better but now this is a bit on the top left corner and nothing really happen happen so let's go ahead and give a bit of structure on our page so we're going to go above this and I'm going to say page do margin and I'm going to give it a margin of two with unit being either centimet feet for some reason I guess if you're printing stuff it makes sense inch meter millimeter or point I'm going to say 2 cm and as you can see this now moves it in 2 cm on an A4 page other things I can do is Page color so I can say that I want this to be colors dot white over here and I want to set a default text style over here so I'm going to say font size 20 as the default font size then let's move into the content of the page so I'm going to say page do content and that's the main thing of the page so I'm going to add some padding I'm going to say padding vertical and you have other types of padding as well if you want to so I'm just going to say padding you know top left horizontal whatever I'm just going to say 1 cm and then I'm going to create a column in that column I can add multiple things for example I can have some spacing I'm going to say 20 and the default 20 is point you can change that to anything you want like centimeters and so on and I'm going to just add a couple of items in my PDF so the first item I want to add is text and you actually have access to a bunch of placeholders if you want to so for example you have lurm ipsum image color integer email so if I say email for example and I save you see a random emailing appear here I'm just going to say lurm ipsum and the moment I save lur makes him appears and the other thing I can add is I guess an image and again I'm going to use a placeholder of an image and I'm going to say at 200 by 100 and you see a randomly generated image appears here so you see how I'm starting to build my page and structure my page now the last thing PDFs usually have is a footer so I'm going to say page do footer over here and I'm going to say align Center because I want to have the page number in the center of my PDF so I'm going to say that the text here is is actually a span with text Page and a space and then follow that up with the page number so get current page number and that's it maybe my face heighted but as you can see now on the bottom over here we now have the page number and the more pages we have the more we're going to add here now you can understand how with this way of programmatically generating the PDF you can do basically anything the page object has anything you will ever need from the content the defaults the margins The Continuous sizes things like this maximum size minimum size it's very very customizable and very very extensible I've been trying to solve this problem for my business myself and Quest PDF for what I've seen and what I've tried is the best experience for my use case of generating PDFs in that way now this is just a way to get started with there's tons of examples on the quest PDF GitHub repo on how you can generate invoices and a bunch of different other stuff and the preview is what the game changer for me because being able to change every everything in real time makes things so so easy of course it goes without saying but if you want to actually generate a PDF you can easily do that by saying generate PDF and I'm going to give it a name called test.pdf save and then if I quickly just uh run this then as you're going to see I have a quest PDF object created over here and if I open it on my browser that PDF is then created and that's exactly what you should expect for your application as well I think quest PDF is a great Library I really don't mind the license in fact I really like that it does have a license meaning that it can be a sustainable project and I highly recommend it to everyone of you but now from you what you using to generate your PDFs and you prefer the iron PDF approach of creating them leave a comment down below and let me know well that's all I had for you for this video thank you very much for watching and as always keep coding
Info
Channel: Nick Chapsas
Views: 76,000
Rating: undefined out of 5
Keywords: Elfocrash, elfo, coding, .netcore, dot net, core, C#, how to code, tutorial, development, software engineering, microsoft, microsoft mvp, .net core, nick chapsas, chapsas, dotnet, .net, create pdf, create pdf in .net, pdf in .net, create pdf in c#, create pdf with c#, open pdf in .net, open pdf in c#, questpdf, quest pdf, quest pdf c#, The Easiest Way to Create PDFs in .NET
Id: _M0IgtGWnvE
Channel Id: undefined
Length: 9min 47sec (587 seconds)
Published: Mon Oct 30 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.