Angular Export to PDF using PDFMake
Generating PDF for reports, forms, invoices, and other data is a common use case for any web application. In a web application, We can generate pdf using various approaches:
- Using browser print function: It is an easy option when you want to print a complete web page as a pdf. You can also customize pdf up to some limits. limitation of this approach is we don’t have strong control on format and design of pdf.
- Generating PDF using Backend application or third-party reporting tools and download it on client-side: You have more control over pdf formatting and design and you can process large amounts of data. Though this type of pdf generation approach required a separate API call for generating the pdf.
We can solve the limitations of both ways by generating pdf at client side. We can format and design pdf as per our requirement without calling separate API.
Following are the two popular open-source javascript libraries available for client-side pdf generation.
In this article, I will show you how to export a pdf file in angular 8 using pdfmake.
Further, Read Below PDFMake Articles
- Loading External Libraries from CDN in Angular Application (Load PDFMake from CDN)
- Insert Image from URL in PDF using PDFMake
Angular 8 Export to PDF using PDFMake
We will cover the following topics in this tutorial
- ✔️ Introduction
- ✔️ Environment Setup
- ✔️ Online Resume Builder using Angular and PDFMake
- 📌 Final Code Review
- 🔗 Git Repository
- 🚀 Live Application
So let’s start with PDFMake introduction,
PDFMake is very popular client-side and server-side pdf generation javascript library. It has 100,000+ weekly downloads from npm. And 7K+ GitHub stars.
It is easy to use and provides all required features for pdf design and formatting with some extraordinary features like QR Code, Table of contents and Helper methods for Opening pdf, download pdf, and pdf printing.
We will create an Online resume builder application in angular 8 and PDFMake. Here we will get the personal details, educational details and experience details and generate pdf at client side. We will provide different options for print pdf and download pdf.
I have published this application on netlify you can check it here https://online-resume-builder.netlify.com/
Create a Angular Project
Use below command to create a new Angular project with Angular CLI.
Install PDFMake Library
Import pdfmake and vfs_fonts
To begin in browser with the default configuration, we should include two files
Now to use this files in angular component or service add below import statement on top of component/service
Generate single line text pdf for testing our environment setup
PDFMake follows a declarative approach. It basically means, you’ll never have to calculate positions manually or use commands like
writeText(text, x, y),moveDownetc…, as you would with a lot of other libraries. The most fundamental concept to be mastered is thedocument-definition-objectwhich can be as simple as:
All the pdf formatting and design configuration are written in document-definition-object. As shown below :
Add
Serve your application and test. This will show pdf as below :

If you can see above pdf on click of Open PDF button then environment setup is done. Now we can start with our resume builder application
PDFMake comes with inbuilt methods :
- Download the PDF : pdfMake.createPdf(docDefinition).download();
- Open the PDF in new window : pdfMake.createPdf(docDefinition).open();
- Open PDF in same window : pdfMake.createPdf(docDefinition).open({}, window);
- Print the PDF: pdfMake.createPdf(docDefinition).print();
PDFMake also provides methods for :
- Put the PDF into your own page as URL data
- Get the PDF as base64 data
- Get the PDF as a buffer
- Get the PDF as Blob
Refer here for more details.
Same as PDF, You can generate excel at client side. Refer Export to Excel in Angular blog for client-side excel generation in Angular.
Now for an online resume builder, I have designed a resume form to get personal details, skills, experience details, education details, and other details. As shown below :

Here I have used the template-driven form and
- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
Comments
Post a Comment