How can I get and view PDF (DocumentViewer) in Ionic 5?
For this solution, What i found out in this project, already have a built in assets folder, where I'm using android studio before running in the emulator then i able to fix it by copy the pdf file from the assets folder (I created), and paste to the original assets folder that already built with the project which result able to view the pdf on emulator. Thanks.
ionic how to open pdf file and see in device for both ios and android
install plugin
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
then try this
<a class="item" href="#" onclick="window.open('http://www.orimi.com/pdf-test.pdf', '_system', 'location=yes'); return false;">
Open pdf
</a>
How to open pdf in ionic
To open existing PDF file, you can use File Opener plugin.
First install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-file-opener2
$ npm install --save @ionic-native/file-opener
Then add this plugin to your app's module (app.module.ts):
...
import { FileOpener } from '@ionic-native/file-opener';
...
@NgModule({
...
providers: [
...
FileOpener
...
]
...
})
export class AppModule { }
Now you can use your plugin:
import { FileOpener } from '@ionic-native/file-opener';
constructor(private fileOpener: FileOpener) { }
...
this.fileOpener.open('path/to/file.pdf', 'application/pdf')
.then(() => console.log('File is opened'))
.catch(e => console.log('Error openening file', e));
Hope I help!
Opening PDF file in ionic 2 app
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 commandnpm 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,
var doc = new jsPDF();
doc.setFontStyle('Bold');
doc.setFontSize(14);
doc.text('Testing PDFs', 20, 20);
var blob = doc.output('blob', {type: 'application/pdf'});
let pdfUrl = {pdfUrl: URL.createObjectURL(blob)};
let modal = this.navCtrl.push(ResumeView, pdfUrl);
in the ResumeView
@Component({
selector: 'page-resume-view',
templateUrl: '<ion-content padding text-center>
<pdf-viewer [src]="pdfUrl"
[page]="page"
[original-size]="false"
style="display: block;">
</pdf-viewer>
</ion-content>',
})
export class ResumeView {
pdfUrl : String;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad ResumeView');
this.pdfUrl = this.navParams.get('pdfUrl');
}
}
Related Topics
Avoiding Repeated Constants in CSS
Why Are Bootstrap's Form Elements Rendered Terribly with Struts2-Boostrap-Plugin
Preserve Line Breaks in Textarea
Bootstrap 3 - Show Collapsed Navigation for All Screen Sizes
How to Remove Background-Image in CSS
@-Moz-Document Url-Prefix() Not Working
How to Set Favicon.Ico Properly on Vue.Js Webpack Project
Mailto Links Do Nothing in Chrome But Work in Firefox
How to Use a Grammar with The HTML 5 Speech Input API
Schema.Org Newsarticle: Invalid Value for Logo Property
How to Remove The Horizontal Scrollbar in a Div
Semantically, Which Is More Correct: a in H2, or H2 in A
Overlapping/Overlaying Multiple Inline Images
How to Print a Portion of an HTML Page
Default Website Image for Social Sharing
Making an Svg Image Object Clickable with Onclick, Avoiding Absolute Positioning