PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
To get started, you'll need:
npm init @angular compdfkit-appWhen prompted to make a choice, press Enter to accept the default option.
cd compdfkit-appnpm i @compdfkit_pdf_sdk/webviewer --savenode_modules/@compdfkit_pdf_sdk/webviewer/dist.cp -a ./node_modules/@compdfkit_pdf_sdk/webviewer/dist/. ./src/webviewerangular.json file. Angular will copy the ComPDFKit library assets to the assets directory before running your app:"assets": [
// ...others
"src/webviewer",
]Add the PDF document you want to display to the src/webviewer/example directory. You can use our demo document as an example.
Replace the contents of app.component.html with:
<div #viewer class="viewer"></div>path parameter to tell it where the copied static resources are located, if not, they will be relative to the current path.Replace the contents of app.component.ts with:
import { Component, AfterViewInit, ViewChild, ElementRef } from '@angular/core';
import { RouterOutlet } from '@angular/router';
// @ts-ignore
import WebViewer from '@compdfkit_pdf_sdk/webviewer';
@Component({
selector: 'app-root',
standalone: true,
imports: [RouterOutlet],
templateUrl: './app.component.html',
styleUrl: './app.component.css'
})
export class AppComponent implements AfterViewInit{
@ViewChild('viewer') viewer!: ElementRef;
ngAfterViewInit(): void {
let docViewer: any;
WebViewer.init({
path: '/',
pdfUrl: '/webviewer/example/developer_guide_web.pdf',
license: '<Input your license here>'
}, this.viewer.nativeElement).then((instance: any) => {
docViewer = instance.docViewer;
docViewer.addEvent('documentloaded', async () => {
console.log('document loaded');
})
})
}
}src/app/app.component.css file:.viewer { width: 100vw; height: 100vh; }npm start