8000 GitHub - egor-miasnikov/angular-pdf-printing: Angular PDF printing snippet
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

egor-miasnikov/angular-pdf-printing

Repository files navigation

Angular PDF printing snippet

This project was generated with angular-cli version 1.0.0-beta.26.

Usage

Development server

Run ng serve for a dev server. Navigate to http://localhost:4200/. The app will automatically reload if you change any of the source files.

Basic printing

Install jsPDF and types

$ npm install jspdf --save
$ npm install @types/jspdf --save

Then need to add script path to angular-cli.json into apps section

"scripts": [
    "../node_modules/jspdf/dist/jspdf.min.js"
],

Then go to your component and declare jsPDF on it

declare let jsPDF;

And use it inside you component

let doc = new jsPDF();
doc.text(20, 20, 'Hello world.');
doc.save('Test.pdf');

Advanced printing

Install jsPDF, types and rasterizeHTML

$ npm install jsp
82C1
df --save
$ npm install @types/jspdf --save
$ npm install rasterizehtml --save

Add scripts to angular-cli.json into apps section

"scripts": [
    "../node_modules/jspdf/dist/jspdf.min.js",
    "../node_modules/rasterizehtml/dist/rasterizeHTML.allinone.js"
],

Then go to your component and declare jsPDF on it

declare let jsPDF;

Import ElementRef

import { Component, ElementRef, AfterViewInit} from '@angular/core';

Get current element into component

constructor(private elementRef: ElementRef) {
    super()
  }

And finally use jsPDF inside you component

let doc = new jsPDF('p', 'px', 'a4');
let options = {
  pagesplit: true
};
doc.fromHTML(this.elementRef.nativeElement, 0, 0, options, () => {
    doc.save('Test.pdf');
  });
}

About

Angular PDF printing snippet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  
0