I am trying to make an ionic 2 app. I have a pdf generated using jsPDF.
The code for the same is
var doc = new jsPDF();
doc.setFontStyle('Bold');
doc.setFontSize(14);
doc.text('Testing PDFs', 20, 20);
Now I want to save the open the PDF in the mobile app,
but doc.output('save', 'tester.pdf');
doesn't seem to work in the mobile app.
Please can you tell me which plugin can I install so as to view and share the newly made pdf.
it is very simple
step:1) install pdf-viewer plugin:
step:2) in your app.module.ts:
step:3)in app.component.ts:
step:4) in your page html file:
Install plugin :
Ref : link
One has to use jsPDF to create a PDF. Then one has to use
blob
attribute to convert it to the format that can be used by the application to allow passing in the app before putting it on screen.After the blob step, One has to install ng2-pdf-viewer on the command line by the command
npm install ng2-pdf-viewer --save
and use the<pdf-viewer>
to view it on the mobile app screen.Make sure you import the the ng-pdf-viewer in the app.module.ts file in the import statements and in the
@NgModule.
Here is the code for the same,
in the ResumeView
I think includes script via external URL may not a good option in ionic. There is an other way as below:
1-Install ng2-pdf-viewer module
And import PdfViewerComponent in your app.moudle.ts as below:
2- Instead of including jspdf.debug.js via extenal url, you can install jspdf module
3- Implement ionic copy custom script
Create scripts folder in root of your ionic project and create a file name copy-custom-libs.js inside scripts folder.
In package.json, add config attribute at bottom as below:
Update index.html and add jspdf.min.js from your assets folder.
4-Finally, you can write code as below:
The source code of this example can be found here: ionic pdf viewer
I Hope this could help you, Thanks :)
You may try for this:
In Component part:
In HTML part :