The Easiest Way to Create PDFs in .NET
HTML-код
- Опубликовано: 29 окт 2023
- Get the source code: mailchi.mp/dometrain/h20z44c0vn
Become a Patreon and get special perks: / nickchapsas
Hello, everybody, I'm Nick, and in this video I'll show you the easiest way to create PDFs in .NET using C# and QuestPDF.
Give QuestPDF a star on GitHub: github.com/QuestPDF/QuestPDF
Workshops: bit.ly/nickworkshops
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasGitHub
Follow me on Twitter: bit.ly/ChapsasTwitter
Connect on LinkedIn: bit.ly/ChapsasLinkedIn
Keep coding merch: keepcoding.shop
#csharp #dotnet
The real time viewer is a gamechanger. that amount of time I spend rebuilding, checking only to find that the pdf is out by a few pixels. Amazing!
Nick ,junior developer here - you along with Fireship are the 2 reasons I'm working as a developer today, you guys are clear ,fast paced and great teachers! Keep it up man.
Awesome to see you create a video on this. I've been using this for the last few months for a client. There are still some rough spots, but it has been amazing for creating Pdf's. If you're doing mostly simple things, this will be perfect for you. As you get to some of the complex stuff, specially if it requires measurements due to needing to wrap contests or show them in a non supported layout or ordering type, it can be a bit touch and go to get what you want.
Overall highly recommend this library.
Nick, I get the impression you're reading my mind. Every month you come up at least with one topic that's currently on my learning list. Thank you so much, and keep up reading our minds :)
I am also under this impression, or we are all sharing the same hive mind 😂
Definitely hive mind 😅
It's because he is working on some projects like we all do in our side-hustle and we all face similar challenges
Me too. I was thinking about this topic today for my future hobby project and all of sudden he has made a video on this which is no where related to videos he made recently. I can't believe it.
I gave up on PDF long ago, now I just write HTML and print to pdf using puppeteer
I agree. I am using html to pdf converter all the time. Creating the Html with blazor is very efficient
@@fibs9456 I've been using Fluid for the templates, it is really fast and supports the liquid template language.
Same here. Paged.js is a nice addition if you need more complex headers and footers
Hello, can you share the code snippet? Thanks
@@fibs9456Can you share the code snippet for blazor ? I need this conversion in linux
really cool seeing u support the packages you show to your audience
I remember when this library first came out. So happy to see it featured in a Nick Chapsas video
We've been developing with Quest for a while. Really useful, great for a large number of use cases and a gentle learning curve. Highly recommend for small to mid-tier projects (and maybe beyond)
wow this is an amazing dev experience for something that has always been way too complicated that is used in so many different use cases. Thanks for sharing! adding this to my tool box!!!!.
This is just amazing. Definitely have to keep this in mind in the future. Thanks for sharing!
Me: Trying to convince my multi-million dollar a year client to pay $500/year for the commercial license
Client: Can’t we just build our own from scratch?
Great library! Used it in recent project for (not maybe ideal use case, but still it was best option) to generate photobooks with custom layouts. Works like a charm.
This was amazing. I was actually using a non-standard size for creating PDFs for my last use case. It was much like a classic receipt where it is narrow and long. So the size was variable. And I ended up doing a manual process because I only needed to do it twice a week. I would literally just generate it in HTML and then using imaging software convert the HTML to a picture then a picture to PDF. Very inefficient, but I didn't want to spend money and I was in a hurry for the prototype. But this is so simple, I could have literally done this faster than figuring the manual process out. QuestPDF for the win.
I used this library one of my project and it is really good library and working very stable.
How this is possible 😮. I was thinking about this topic today and all of sudden you have made a video on this which is no where related to videos you have made recently. It's a miracle ✨ 💯
I actually used this library about a year ago to generate mini prints of QR codes and additional information in a two column design and then cut automatically after print. One of the most convenient PDF generation tools I've used and have sent support. The only issue I had with it was generating large PDFs in megabytes because a font set gets embedded with it. At the time I used it, the only fix was embedding a stripped down font set so you can generate PDFs that are kilobytes in size. Otherwise, an amazing library!
I'm a new programmer and haven't been able to manage to create a pdf that will cut automatically. Do you perhaps have any tips on how to do this?
Really awsome Library!
I am using it for some time now and you can fulfill all most common Use Cases with it
This may finally be the thing I needed to rewrite my pdf manipulation tool. 🤩
Seems I as much excited as Nick about this library :) And the pricing model is also REALLY attractive
That looks amazing, thanks for showing!
This is a pretty impressive library, it took me just half a day to recreate a few documents at my work, way less painful than anything else I've used to generate report documents.
This is amazing! That hot reload would've saved me sooo much time years ago when I last had to generate PDFs for a work project, if only it had been around back in the mid 2000s! 😅
This is so cool! Thanks you shared this one! Definitely I'll use it! Many thanks!
Thank you so much for sharing this amazing library.
Very cool, I've been wondering about this for a while
The preview option is amazing, a productivity booster; it eliminates lots of tedious work.
This video is a game changer for me. I finnaly will get rid of Crystal Report and his bad backwards compatibility. Thanks!!
my current approach is to use puppeteer sharp to convert an html page using chromium. the html page is generated by a blazor page / component, this way i can visit the page to see how it displays, also making it user accessible for preview. The downside of this is that puppeteer is very heavy and it is a little complicated (but possible) to write cross platform code due to the native part of the process. QuestPDF looks very interesting!
This is the way. It's way simpler and more powerful to generate a pdf using html than any other medium I've found.
Nice - being playing with Quest - good hints and information - wonderful.
1 of the best pdf library i have seen for creating pdf
The biggest job for me is generating pdfs from templates. The goal is to generate as fast as possible. On the templates there are fields that have to have different values for each pdf file. The fastest I've achieved so far was the Aspose package, generating from MS WORD templates, for the simpler templates I could achieve 1000 pdf/sec.
What my team is currently using is Gotenburg to give html styling together with Scriban to script the different values to generate our pdfs from templates we create ourselves. Has a bit of a learning curve but afterwards it is very easy to use as very fast to generate the pdfs
We are using wkhtmltopdf. As the name implies you can use a html template and replace some variables in there with your wished content. Easy styling, easy layout but I did not check the speed of it.
I haven't worked with it, but I definitely like it)
Thank you so much.
I wasn't expecting this topic but it's amazing 😆
Thanks! Exactly what I needed
Thanks for sharing!!! It would be nice to see a demo with variables instead of writing strings, just an idea!
Super cool - I will check it out for my next project 😍😍
QuestPDF is awesome! Thanks for sharing, Nick!
I've been using SelectPDF for years now. It's not as simple as this but it can take an entire html page with css included and create a PDF from that. It's enough for what I'm doing right now but I might give this a try at a later time.
Great video! There’re also libraries which build PDF based on HTML page. This could be convenient for backend developers with basic frontend knowledge. With HTML template you can gain same preview experience with well-known CSS styling on board
Few examples please 🙏
@@RenjithRs123 I use puppeteersharp in my project, basically it runs a chrome browserless in the background and use the "print" feature of the browser to create the pdf. I can generate some very complex templates and pdf's.
@@guilhermeflores7564can i ise it in production? Like on aws on my server do i need to install chrome ? Or every thing is included in nuger package ?
I use QuestPDF and like it. I love seeing the previewer in action. I knew about it, but didn't know it was that easy to use. The issues I've run into with QuestPDF are situations when content overflows in some way. In a large data-driven pdf, I've found it hard to track down exactly where the failure is. I ended up creating an integration test that does several iterations of my pdf, and I have logic for retrying with smaller data sets to isolate issues. I would rather not have to go to lengths like that, but it's still a good library.
LOL i just found QuestPDF 2 weeks ago. Love how easy it makes woking with PDF.
Looks great. I would have been happy to see how to generate grids. Because for my use cases, it is one of the most difficult things to achieve.
thank you so much that was so helpful!
Thanks for creating this video, we want more video on PDF read, manipulate and re-generate, upload, download and merge pages and split, rotate PDFs. Please.
I create a view, then fill it with it's model, then get it's html and pass it to puppeteer to return a pdf.
Do you mind sharing some code? I like that approach, but my PDF ended up being much larger compared to the same file generated using wkhtmltopdf.
ABCpdf is what the organization I'm affiliated with uses. The API is akin to something from the 1990s. When .NET Core arrived and we inquired when they would support it, their answer was "Why would we do that. You can just use .NET Framework". Eventually they came around on that one, but not until after using having to segment off special services written in legacy frameworks to support functionality.
I came from the same sort of background. I just finished rebuilding our generator from ABCpdf to QuestPdf, and the speed upgrade were so enormous that we didn't even bother to measure it, at the very least 20x faster, might even be 50x.
The biggest problem was that I had to make it 100% backwards compatible, which caused some issues, as we had support for HTML in the ABCpdf library, which QuestPdf doesn't.
Awesome exactly what i was looking for thank you much Nick Chapas. I have tried so many options but i couldn't get anything close to it with community license
Awesome lib: thanks for sharing.
building a github watching bot for my team and it might be nice to output these summaries to pdf thank you Nick! :) Oh seems like a factory pattern might be nice with this one.
We are using stimulsoft for so ling now and the experience was perfect
You gave me hope, and then you killed it when you started talking about a commercial license
Thanks for that very useful package, @Nick Chapsas! Here, I'd like to ask for some .Net solutions but for populating with data of already-defined PDF template files.
I'll check it out, looks promising. My challenge is with headings/references/hyperlinks and a TOC, I hope they have good support for that
Love QuestPDF. Great library
Very cool, thanks
to Generate Pdf's i've using the razorlight lib with wkhtmltoPdf lib, i get the cshtml razor, and trasform in string html to pass as content on wkthml pdf content prop and works well
Looks like a very healthy alternative to telerik reporting which we use at work these days. Although we would lose support for exporting the reports we create to microsoft office formats.
It would be nice in your next video to show how to sign this PDF, as it is something that is becoming a requirement in more and more businesses. Very good video. Keep it up.
Great library. I use IText. But I think I am going to play with quest. Seems much easier. Plus the previewer is spectacular.
Looks awesome
Would like to see how it deals with page overflow and whether you can break up paragraphs or keep paragraphs together
nick would love to see some vids with open apis and gpt..or maybe you can suggest how devs can make some good product with them.
Love this ❤
The best feature is, that it is c# where you can use loops, classes write extensions and allfthat. Passing your models and everything as you know it. Its genious.
Did a lot using PDFSharp to make election maps a while back. This would have been so much better than the way I had to do it back then! Obviously was not available back then.
Wow I've wanted this video for years including a project I just started. Why is this so hard?
I use syncfusion, you can also convert word files to pdf, a few of my customers want to do their own layout, you can then merge data from the word template to a pdf. Doesn't mean it is the best library though but hey i am happy with it.
do you pay for it?
cool man thanks
We use an xsl-fo library for this, but it's really expensive. Not sure if we would get the same functionality here. Wondering if Quest has block containers, blocks and spans. If so then it might be worth a switch, if the speed was on par with the xslt transformation.
Our current solution (legacy which we're maintaining) is using puppeteer to render html and print using the browser's print to pdf function. It's horrible and has a lot of problems with things like webGL components since those never render properly. This is giving me serious considerations of porting that part of the application over. Thanks for the videos Nick!
I'm really sorry, but that is possibly the worst way to solve the PDF generating problem. There are many libraries out there to do this.
> WebGL components
How are you expecting to render those using QuestPDF?
This looks like a great tool for doing what it’s made to do! The visualizer is cool
The only nock I have on this is that it doesn’t have a way to handle variable-length content. You seemingly *have* to know how much fits on a page ahead of time, but in some cases that’s impossible
By looking at the invoice example that has been done here: ruclips.net/video/-iYvZvpLX0g/видео.html it looks like the content will auto-wrap to another line if it won't fit. Not sure what's going to happen if you make width 1px for something like product description ;)
@@elpe21 I should have been more specific. It’s good that lines will auto-wrap to the next line; what I mean is if there is no more space for lines on the page but there is more content, I would presume since you have to explicitly create pages that it won’t wrap to a new page.
If you took the lorem ipsum from this video and used it.. say.. 20 times instead of once. It won’t fit on the page unless you make the font so small you can’t read it
@@the-avid-engineer by looking at the example from the video i've posted it will take the lorem to next page(s) . Check the viedo I gave, time 34:06
@@elpe21 well thats just freaking awesome
Hello Nick!
Idea for next video - Benchamrks: Json vs ProtoBuff vs Cap'n Proto vs MessagePack vs ...
that previewer was nice feature
Great video Nick
Is it possible that Milan Javanovic always publish some video similar to Nick couple days/weeks later 😂
Having a visual "report editor" makes me a lot more productive.
I don't need to waste time working out HOW I put stuff down, I just create it.
I guess that I prefer my productivity over knowing the guts of a system, especially when I need to do so many different jobs.
NOTE: I am NOT saying that there is anything wrong with this approach.
This probably works well for the vast majority of people, and I CAN see where it would.
It is just not something that makes me more productive, and at the end of the day, my time is more valuable.
I love that library, and I am lobbying for my employer to start paying for it so I can get latest and greatest features
Writing markup in code looks fun. I usually write my markup in markup.
Based Nick sponsoring open source projects
What's your take on IronPdf ? Is this supported in Linux containers ?
Hi Nick!
I would be thrilled to see a benchmark on the tool, as well as some form of testing capabilities (snapshots?). In my experience, volume and correctness are common concerns. Third on the list is handing over the design to design-people so that us backend developers dont have to write everything. Are you aware if there are any declarative tools available for designers?
Seems very user friendly - Devexpress also has pdf gen capability
Very nice. Quick iteration is the key. Very soon when ChatGPT will be able to read images I am going to draw the pdf on a napkin, take a photo, upload it and get the code AI spits out, almost ready to go.
I use quest pdf and it is a great tool. It just lacks text justification. But the repo owner is working on it. For everything else is awesome and also works in Linux. Just needs an extra dependency that if you deploy on windows does nothing. So it is very cross platform.
PDFFlow works very similar to that and has almost the same syntax. Testing it out is slightly more cumberstone tho
This library could be great for some prototyping where you don't want to learn/introduce extra programs, or when you're literally building a document from various input data (i.e. no template).
For the other cases, I believe something like LaTeX would be much more fitting. It's not that hard to learn, the templates would be quite concise and you can run it in a Docker container.
I think with PDF generation the hardest part is converting a Word document to a PDF. If an open-source library with cheap licensing can pull that off, literally every dev will lick their feet (metaphorically ofc).
What would be a great library for parsing PDF with a similar licensing model? I've used PdfPig in a commercial project, but it was a bit of a pain to make it work, when the PDFs are structured in a slightly different way.
Latex, 100%. Though I can see the appeal of a library like this. Dynamic generation is actually pretty cool.
We steered away from crystal and ssrs and went to pure HTML and have puppeteer do the rendering and pdf generation. data manipulation is easier because javascript. The library looks promising but keen to know more how it handles complicated datatables
Is there a way to load another PDF as a template then place text over the top?
awesome
We use Devexpress Reports, and build reports, then whenever a user needs a PDF, Excel, word document of whatever is on the screen they have to manually click options to generate files, in my use case reports are the way to go, but when code close source, and only shared with development team, then i think report are the wasy to go, but the moment code is shared in whole team(developers, EDPs, reports & tests and all) then I think you need code based PDF just like quest PDF
Very nice, but are the PDF WCAG complient?
Nice! I wonder why they used callbacks instead of declarative code.
What about reports in your application. Do you use a PDF library most of the time, use Crystal Reports, or code it yourself?
nice they went back on their step and introduced a community license. Was pretty scummy when they went from a free model to a paid model. This is the right license model and i'm happy for their success, pdf generation and processing in .NET has always been a complete overpriced mess with too few library providers
We use the FastReport library.
The most difficult part of generating PDF is to support all encoding and languages including Chinese, Japanes, Korean and ensure that license for all those fonts is legal. And handling that US has different paper layout than Europe.
We generate a temporary html file with our template engine (which is basically a better variable replacer...knows domain objects and such, but nothing super fancy), load that html into aspose and save it into pdf. boom, done.
No need to hard code pdf generation.
Though the api is very cool, I would still prefer html+css to create a pdf.
Programmatically creating all the needed graphical objects seems cumbersome, while a html+css template fits the bill easily.
But great to have options!
Yeah, ATM we're using wkhtmltopdf (xml -> xslt-> html->pdf). And while this library looks awesome you still need to build/deploy the app every time client needs a tiny change in text or layout
Ok, I admit this looks more convenient than interop libraries.