jeffleus / ionic-pdf

sample use of pdfMake.org library to generate a pdf and display in iFrame or save as local file
58 stars 21 forks source link

On Android the file isn't create #5

Open szanellato93 opened 8 years ago

szanellato93 commented 8 years ago

I have a problem with this plugin. On iOS all work well, but on Android probably my pdf isn't created. I receive a blank page when it is opened. And with some try to attach it to a email, it dosn't work. I post here my console log:

2 332189 log SaveFile: requestFileSystem 3 332481 error SaveFile: gotFS --> getFile 4 332501 error SaveFile: gotFileEntry --> (filePath) --> createWriter 5 332518 error SaveFile: gotFileWriter --> write --> onWriteEnd(resolve) 6 332666 log report run on device using File plugin 7 332670 log ReportCtrl: Opening PDF File (file:///data/data/com.ionicframework.ambra611013/cache/rptSample.pdf)

plugin installed:

cordova-plugin-console 1.0.2 "Console" cordova-plugin-device 1.1.1 "Device" cordova-plugin-file 4.1.1 "File" cordova-plugin-file-opener2 2.0.2 "File Opener2" cordova-plugin-inappbrowser 1.2.1 "InAppBrowser" cordova-plugin-splashscreen 3.1.0 "Splashscreen" cordova-plugin-statusbar 2.1.1 "StatusBar" cordova-plugin-whitelist 1.2.1 "Whitelist" de.appplant.cordova.plugin.email-composer 0.8.2 "EmailComposer" ionic-plugin-keyboard 1.0.8 "Keyboard"

jeffleus commented 8 years ago

Thanks for the console log entries @szanellato93. They appear to show that service is actually building the report file. I know there are are (3) lines that report out errors, but this is a bug in my code. If you check out the lines in source that print these to console, you can see I call "console.error" where I should call "console.log". I will work on fixing those today.

So, my guess is that that file was correctly written, but perhaps the File plugin is failing to load the pdf for viewing. Part of the problem could be the lack of built-in PDF viewing in the Android platform. The iOS platform has PDF viewing built into the browser, so it works out-of-the-box. Perhaps you need to install a PDF viewer on your Android test platform? Is it an emulator or a physical device? Also, can you browse the file system on the test platform and find the created file (rptSample.pdf)? This will help to troubleshoot if it is PDF creation or PDF viewing.

MrShakes commented 8 years ago

Similar problem but I could find the file on the test Android device, will you be able to fix this?

MrShakes commented 8 years ago

screen shot 2016-10-26 at 18 58 00

jeffleus commented 8 years ago

There appears to be a bug in my code on the call to hideLoading on line 46 of controllers.js

Try changing the call to use _hideLoading(); Or, you could rename the function on line 64 to be hideLoading w/out the underscore.

I think I made some changes to the library and broke this a little while ago. I haven't touched things in a while. I will take a look at it later this week and see there is anything else wrong. I notice you also have a FileError higher up in the log that shows "ENCODING_ERR" not sure about that one. Like you said, the file appears to have been created each time as the log shows "Opening PDF File (file:///storage/emulated/0/rptSample.pdf"

The only other note is the possible need to whitelist the file type. I have has trouble in another Ionic project because of the need to include a whitelist cordova plugin to be able to use external resource files (images in my specific case). You might try adding this plugin as well...

https://www.npmjs.com/package/cordova-plugin-whitelist

On Wed, Oct 26, 2016 at 10:59 AM, Ola notifications@github.com wrote:

[image: screen shot 2016-10-26 at 18 58 00] https://cloud.githubusercontent.com/assets/12875016/19738153/37c1c096-9bae-11e6-8cca-0549dec394b8.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeffleus/ionic-pdf/issues/5#issuecomment-256428370, or mute the thread https://github.com/notifications/unsubscribe-auth/AFMmxTKvS9ET-pukhYCchYCm14CEsQ6Yks5q35TtgaJpZM4H1EyT .

MrShakes commented 8 years ago

I tried using another means while yours gets fixed, slightly off-topic but please could you help me take a look at this question, I would really appreciate it: http://stackoverflow.com/questions/40292173/uncaught-typeerror-object-object-has-no-method-writefile

jeffleus commented 8 years ago

The issue is probably a plugin problem. I just posted on your SO post.

-Jeff

On Thu, Oct 27, 2016 at 12:07 PM, Ola notifications@github.com wrote:

I tried using another means while yours gets fixed, slightly off-topic but please could you help me take a look at this question, I would really appreciate: http://stackoverflow.com/questions/40292173/uncaught- typeerror-object-object-has-no-method-writefile

On Thu, Oct 27, 2016 at 4:49 PM, Jeff Leininger notifications@github.com wrote:

There appears to be a bug in my code on the call to hideLoading on line 46 of controllers.js

Try changing the call to use _hideLoading(); Or, you could rename the function on line 64 to be hideLoading w/out the underscore.

I think I made some changes to the library and broke this a little while ago. I haven't touched things in a while. I will take a look at it later this week and see there is anything else wrong. I notice you also have a FileError higher up in the log that shows "ENCODING_ERR" not sure about that one. Like you said, the file appears to have been created each time as the log shows "Opening PDF File (file:///storage/emulated/0/rptSample.pdf"

The only other note is the possible need to whitelist the file type. I have has trouble in another Ionic project because of the need to include a whitelist cordova plugin to be able to use external resource files (images in my specific case). You might try adding this plugin as well...

https://www.npmjs.com/package/cordova-plugin-whitelist

On Wed, Oct 26, 2016 at 10:59 AM, Ola notifications@github.com wrote:

[image: screen shot 2016-10-26 at 18 58 00] https://cloud.githubusercontent.com/assets/ 12875016/19738153/37c1c096- 9bae-11e6-8cca-0549dec394b8.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/jeffleus/ionic-pdf/issues/5#issuecomment-256428370 , or mute the thread https://github.com/notifications/unsubscribe-auth/AFMmxTKvS9ET- pukhYCchYCm14CEsQ6Yks5q35TtgaJpZM4H1EyT .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeffleus/ionic-pdf/issues/5#issuecomment-256684770, or mute the thread https://github.com/notifications/unsubscribe-auth/ AMR1CC7iAYkbcVUjiHVYBjlQyr5idduLks5q4Mf4gaJpZM4H1EyT .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeffleus/ionic-pdf/issues/5#issuecomment-256739305, or mute the thread https://github.com/notifications/unsubscribe-auth/AFMmxf1DW4cQtSgQwojVJN_nhhvXAyElks5q4PZXgaJpZM4H1EyT .

MrShakes commented 8 years ago

This is what I get in the console, the service.js is the $cordovaFile.writeFile line, I'll file a bug issue, thanks for the help. screen shot 2016-10-27 at 22 12 03