Angular | Creating PDF Documents

Inhaltsverzeichnis

Create App

ng new app
cd app

Additional modules

Install jsPDF for creating PDF documents with JavaScript

npm install       jspdf --save
npm install types/jspdf --save

Demo Page

Create demo page

ng generate component pages/PDF

Add demo page to routing

src/app/app-routing.modules.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { PDFComponent } from './pages/pdf/component';

const routes: Routes = [
	{	path: '',	redirectTo: 'pdf',	pathMatch: 'full',	},
	{	path: 'pdf',	component: PDFComponent,			},
];

@NgModule({
	imports: [RouterModule.forRoot(routes)],
	exports: [RouterModule],
})
export class AppRoutingModule {}

Add PDF functionality

Modify pdf.component.html

src/app/pages/pdf/pdf.component.html

Modify pdf.component.ts

src/app/pages/pdf/pdf.component.ts

Add import for jsPDF

import { jsPDF } from 'jspdf';