import * as jsPDF from 'jspdf';
toPdf(abc:string){
var doc = new jsPDF()
doc.text(abc, 10, 10)
doc.save('a4.pdf')
}
<div class="my-1">
<input class="form-control" #todoText />
<button class="btn btn-primary mt-1">
Add
</button>
<button class="btn btn-primary mt-1" (click)="toPdf(todoText.value)">
PDF
</button>
</div>
First Try
Windows PowerShell
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS D:\Home\todo> npm install jspdf
npm ERR! code ENOGIT
npm ERR! Error while executing:
npm ERR! undefined ls-remote -h -t ssh://git@github.com/eligrey/FileSaver.js.git
npm ERR!
npm ERR! undefined
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
npm ERR! A complete log of this run can be found in:
Second Try
PS D:\Home\todo> npm install @types/jspdf
npm WARN ajv-keywords@3.4.1 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
added 1 package from 5 contributors and audited 41096 packages in 7.924s
found 8 vulnerabilities (3 low, 3 moderate, 2 high)
run `npm audit fix` to fix them, or `npm audit` for details
___________________
PS D:\Home\todo> ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2020-01-17T06:39:11.440Z
Hash: b734fb7535fc49908081
Time: 8609ms
chunk {main} main.js, main.js.map (main) 14.2 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 241 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 178 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.54 MB [initial] [rendered]
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'jspdf' in 'D:\Home\todo\src\app'
i 「wdm」: Failed to compile.
Third Try
PS D:\Home\todo> ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2020-01-17T06:39:11.440Z
Hash: b734fb7535fc49908081
Time: 8609ms
chunk {main} main.js, main.js.map (main) 14.2 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 241 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 178 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.54 MB [initial] [rendered]
ERROR in ./src/app/app.component.ts
Module not found: Error: Can't resolve 'jspdf' in 'D:\Home\todo\src\app'
i 「wdm」: Failed to compile.
Fourth Try - Compiled successfully...
PS D:\Home\todo> npm install jspdf@1.4.1 --save
npm WARN ajv-keywords@3.4.1 requires a peer of ajv@^6.9.1 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.4.1 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.11 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.11: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
+ jspdf@1.4.1
added 25 packages from 67 contributors and audited 41208 packages in 10.48s
found 8 vulnerabilities (3 low, 3 moderate, 2 high)
run `npm audit fix` to fix them, or `npm audit` for details
____________________________________
PS D:\Home\todo> ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
Date: 2020-01-17T07:40:48.574Z
Hash: 3fee450eb7ef7d427ce0
Time: 6258ms
chunk {main} main.js, main.js.map (main) 14.3 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 241 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.22 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 178 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 3.85 MB [initial] [rendered]
i 「wdm」: Compiled successfully.