| This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal. |
| This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal. |
Hi,
If you have a PDF base64 string then we need to use the browser widget to show the PDF in Kony Application.
All we need to do is we need to prepare a htmlString where you can pass you PDF base64 string and pass that htmlString to the Kony browser widget.
For example, if you are getting PDF as a base64 string from the service then the below code snippet will help you open PDF in the browser.
Example Code:
var base64="base64String";
var browserString="<html>\n<body>\n<div id=\"pdf\" >\n<object data=\"data:application/pdf;base64,"+base64+"\""+"width=\"100%\" height=\"1000%\">\n</div>\n</body>\n</html>";
To save the PDF, we do not have straightforward API.
In Android, we cannot open the PDF in the browser widget as it is the native limitation. In order to load you need to do the following as mentioned in the below link
https://kylewbanks.com/blog/Loading-PDF-in-Android-WebView
var myPdfUrl = "http://www.pdf995.com/samples/pdf.pdf "
var url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Give the above url to browser widget.
Hi,
Please try the below steps to save the PDF,
<<Here is example snippet>>.
var rb = kony.convertToRawBytes(base64str);
var path ="";
if( kony.os.deviceInfo().name == platform.ANDROID ){
path = kony.io.FileSystem.getExternalStorageDirectoryPath();
}else{
path = kony.io.FileSystem.getApplicationDirectoryPath();
}
if(kony.io.FileSystem.isExternalStorageAvailable()){
var myfile = new kony.io.File( path +"/Certificate.pdf");
myfile.write(rb, true);
}
Hi,
This is saving the empty pdf page with valid base64 string.
How to open the pdf if we save? myfile.open doesnt support to android and iOS.
Hi,
Thank you for your response, I will try the example you have posted above and I will let you know if I find any issue
Hi,
If you requirement is for Android device then attached sample app might help you. It uses an FFI approach which takes care of saving base64 and showing pdf using third party app.
Thank you
Hi,
Can you attach the sample. I see file attachment is missing.
Hi
i am receiving PDF base64 from webservices. i followed the steps to load pdf in ios. could you elaborate to load pdf base 64 in kony browser widegt for android. i am not able to load pdf base64 in browser.As i understand that there is android restriction. i used below code. but not wroking. please guide me
var mybase64 = "djhfgdfhkdjhdj"
var url = "http://docs.google.com/gview?embedded=true&url=" + mybase64;
frmname.browserwidget.htmlString = url;
frmname.show();