Google Document Viewer shows “No Preview Available” - android

I have a problem with google doc viewer for display xls file get from my server.
Currently when i try to display my xls file get from my server in my android app with a webview, i have a grey page with no preview available
(I can download the xls from my server with the url).
Sorry, I could not share link but It's like xxxx.com/123/DownloadExcel_GET?paraOne=%s&paraTwo=%s&paraThree=%s.
But when i try with xls exemple file in internet like http://lecompagnon.info/demos/demoxl3.xls , i don't have this problem. The xls is display succesfully.
Same it's working if i try with a googleDrive url like "drive.google.com/file/t/myfile/view?usp=sharing".
The only difference with the exemple file in internet and my file from my server, is the time to start the download.
With the exemple file is instant, but with my xls i have to wait more than 10sec to start the download.
I think google doc viewer return no preview available, because for him 10sec to get the file is too long and he return a time out. But it's a supposition...
I found nothing about this problem, only this topic Google Document Viewer shows "No Preview Available" .
Here is my code :
String urlgoogle = "https://docs.google.com/gview?embedded=true&url=";
String completeURL = urlgoogle + query;
Log.i("completeURL", completeURL);
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(completeURL);
//wv.loadUrl("https://docs.google.com/gview?embedded=true&url=" + "http://lecompagnon.info/demos/demoxl3.xls"); working
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
edit
I add more information.
The grey page with no preview available not always showing, sometimes my xls file is display successfully the first time.
If i have the grey page, i can refresh, and after one or two refresh, the file is display. The refresh just call again the url in the webview
The file is dynamically create and generated from the serveur, this is why for download or get the file i must wait 10 sec.
Do Google doc viewer have a timeout if the time to get the file to display is too long ?

Related

All webview content printed in one page

Case: User should be able to view and print pdf
My solution: I am opening PDF inside Webview with the help of docs.google.com/gview. Below is my code
Set up Webview
string url = "http://www.africau.edu/images/default/sample.pdf";
string gview = $"https://docs.google.com/gview?embedded=true&url={url}";
mWebView.LoadUrl(gview);
Print PDF
var printMgr = (PrintManager)GetSystemService(PrintService);
printMgr.Print("print", mWebView.CreatePrintDocumentAdapter("print"), null);
Below is the screenshot. As you can see PDF loads just fine
Problem
When I want to print PDF, all the PDF pages are printed in one paper which you can see below
I would appreciate any suggestion, including different library for displaying/printing pdf or suggestion in Java or Kotlin, I can convert them to C#.
I would not print the web page but print the PDF directly as when printing the web page it just sees it as a longer web page and knows nothing about the content.
Use a custom print adapter instead, but instead of drawing a PDF to print you can just use the existing PDF you already have.
See for details https://developer.android.com/training/printing/custom-docs.html

Android open pdf file from Url and diaplay in web view?

I know this question has been asked so many time , but i didn't get any proper and satisfactory solution. I want to show the Pdf file in web view , which is coming from the url ,when i click on the URL , my pdf downloads. Currently i am usinghtml following code for showing pdf file in web view , but it is opening the html file. I am getting stuck in this since 4 hours.Kindly suggest me where i am doing wrong.
Thanks in advance.
mWebview.getSettings().setJavaScriptEnabled(true);
WebSettings settings = mWebview.getSettings();
settings.setDefaultTextEncodingName("utf-8");
mWebview.loadData(response, "application/pdf; charset=utf-8",null);
i have following response coming in following format :-
**%PDF-1.4%���5 0 obj<</E 74937/H [ 1453 173 ]/L 75330/Linearized 1/N 1/O 8/T 75180>>**
I want to show the Pdf file in web view
WebView does not have a PDF renderer.
Kindly suggest me where i am doing wrong.
You are attempting to load a PDF directly into a WebView. Use something else to render the PDF.
For show pdf in webview use Direct url:
https://docs.google.com/gview?embedded=true&url="PDF_FILE_URL"
Now load above url in webview.
mWebview.loadUrl("https://docs.google.com/gview?embedded=true&url="PDF_FILE_URL"");

POST to Android Webview where the response is a PDF file

I am performing a POST to the Android webview where the expected response is a PDF file. However the webview just shows a blank page. I realise that PDF files cannot be rendered in the webview but would expect the file to start downloading or show some response at least.
Does anyone know if its possible to POST to a webview to initiate download of a (pdf) file?
_webView = FindViewById<WebView>(Resource.Id.ebookWebview);
_webView.SetWebViewClient(webviewClient);
_webView.SetWebChromeClient(new WebChromeClient());
_webView.Settings.AllowFileAccess = true;
_webView.Settings.JavaScriptEnabled = true;
_webView.PostUrl(_postUrl, EncodingUtils.GetBytes(_postData, "BASE64"));
Have you tried registering a DownloadListener on the WebView? That is needed to handle the download. Please see http://developer.android.com/reference/android/webkit/WebView.html#setDownloadListener(android.webkit.DownloadListener)

how to display a pdf file in Web view without storing it in SDCard

I am realizing an android project I am blocked that one I wanted to show a pdf in webview .the pdf file is accessible via an URL in localhost.
when I use this code, webView.loadUrl("https://docs.google.com/gview?embedded=true&url="+pdfurl);
it shows :
"Sorry, we were unable to find the document at the original source. Verify that the document still exists.You can also try to download the original document by clicking here."
Help me to solve this.Thanks in advance.
Your file is located in your local server.It cant accessed from outside your network.Upload your pdf file to any website like this or this.And get the public url from there.Then try to access that url from your application.
You can use the google's document viewer service for viewing the pdf,ppt contents in the webview if your document resource is on online.
create following HTML string like :
String googleDocUrl ="<iframe src='http://docs.google.com/gview?url="
+ YOUR_ONLINE_PDF_DOC_URL
+ "&embedded=true' width='100%' height='100%'style='border: none;'></iframe>";
call webviews loadData() method :
mWebView.loadData(googleDocUrl ,"text/html","UTF-8");
Hope this might help you :)

Android - Problem in using the Google pdf viewer in webview

I have seen lot of threads about loading a PDF in Android Webview. But I didn't see the issue what I am getting.
I am using Google PDF viewer to load the URL in the Webview which will give a PDF as response.
I am setting the following properties to my webview
mWebview.setWebViewClient(new WebViewClient());
mWebview.setVerticalScrollBarEnabled(false);
mWebview.getSettings().setJavaScriptEnabled(true);
Webview.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
String url = "http://docs.google.com/viewer?embedded=true&url=" + "my url";
mWebview.loadUrl(url);
I am able load the PDF with the above given code. The issue I have is,
Once after loading the full page, a empty line is keep on getting inserted in top and bottom of page. So my page is looking like the one given below.
empty line
empty line
empty line
....
pdf content
empty line
empty line
empty line
....
The page is keep on increasing with empty lines.
There was something wrong with Google only, now I am not getting this issue, it works fine.

Categories

Resources