Reputation: 374
I'm trying to open a locally stored PDF using the following plug-in for PhoneGap build. This is on an iOS project.
https://github.com/pebois/phonegap-plugin-PDFViewer
I've installed the plug-in using the code provided on the PGB site, and can initiate a PDF viewer sheet using the JS included in the plug-in documentation, but it doesn't seem to point to a real file.
PDFViewer.open("file://sample.pdf","sample.pdf", function (msg) {
console.log(msg);
});
My understanding is that the first parameter is the location of the file, the second is the name that should appear across the top of the PDF sheet, and the third is a function to be called upon closing the sheet.
Thus far, I've placed a file named sample.pdf at www/sample.pdf in my project and attempted to point at it as both file://sample.pdf and simply sample.pdf.
Can anyone point me in the right direction as to how to point to this file?
Thank you!
Upvotes: 0
Views: 3311
Reputation: 1444
@Steven You can try to access the PDF in Android device in the following manner
PDFViewer.open("file:///android_asset/www/pdfs/sample.pdf","sample.pdf", function (msg) {
console.log(msg);
});
In this case I have put it in pdfs folder in the www folder.
You need to replace line number 20 in PDFViewer.m under the plugin src directory
NSURL *fileURL = [NSURL fileURLWithPath:[url stringByReplacingOccurrencesOfString:@"file://" withString:@""]];
with the line below.
NSString *fileURL = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www/%@",url];
You then need to invoke the plugin in this way
PDFViewer.open("pdfs/sample.pdf","sample.pdf", function (msg) {
console.log(msg);
});
Upvotes: 1