I'm trying to load a pdf in a WebView with google docs, but the width of the psd is cut in half. I have tried different options but none of them looks great.
This code show what i have already tried:
webView.Settings.JavaScriptEnabled = true;
webView.Settings.SetLayoutAlgorithm (WebSettings.LayoutAlgorithm.Normal);
//webView.Settings.SetLayoutAlgorithm (WebSettings.LayoutAlgorithm.SingleColumn);
//webView.Settings.LoadWithOverviewMode = true;
//webView.Settings.UseWideViewPort = true;
webView.SetWebViewClient(new WebViewClient());
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webView.LoadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
Opening a new intent and downloading the pdf is not an option by the way.
Also, i'm using the Xamarin framework.
I'm also seeing this alot in my application output:
[skia] xxxxxxxxxxxxxxxxxx clip not implemented
try this
wv.getSettings().setJavaScriptEnabled(true);
String pdf = "http://ga.berkeley.edu/wp-content/uploads/2015/02/pdf-sample.pdf";
String urlmain = "https://docs.google.com/viewer?url=" + pdf;
wv.loadUrl(urlmain);
and make your webView height match_parent, it will surely work
Related
i want to show the image on the following link in the webview in my android app. any idea how to do that ?
image link is given below.
image link
Your link is broken.
If you want to show remote images in imageview you can use 3rd party library like Picasso.
Without using 3rd party library check this question
If you want to load image in webview use web.load(url).
Please check below code use into Activity On Create
WebView webView = (WebView) findViewById(R.id.mwebview);
String mStringUrl = "http://api.androidhive.info/images/sample.jpg";
webView.loadDataWithBaseURL(null, "<html><head></head><body><table style=\"width:100%; height:100%;\"><tr><td style=\"vertical-align:middle;\"><img src=\"" + mStringUrl + "\"></td></tr></table></body></html>", "html/css", "utf-8", null);
OR
WebView webView = (WebView) findViewById(R.id.mwebview);
String mStringUrl = "http://api.androidhive.info/images/sample.jpg";
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(mStringUrl);
In XML
<WebView
android:id="#+id/mwebview"
android:layout_width="fill_parent"
android:layout_height="250dp"></WebView>
I have a android web view
webview = FindViewById<WebView>(Resource.Id.webView);
I load the htmlData from the url like so:
webview.LoadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);
The content includes text, images and embedded youtube videos.
In the case above the text and images load correctly but not the videos as i have not enabled Javascript yet.
Therefore i enable JavaScriptEnabled.
webview.Settings.JavaScriptEnabled = true;
webview.Settings.DomStorageEnabled = true;//This does not make any difference
However, when i do enable Javascript the images no longer load within my webview but the videos do.
After debugging, I can see that the entire image tag is being replaced with  
So i would like to know how to have javascript enabled and have my images still load within my htmldata at the same time.
I guess JavaScript may change the src attribete of img tag.
You can do RemoteDebug of webview. Let's check the html dom.
developers.google.com/web/tools/chrome-devtools/debug/…
I have a requirement where there is a URL = "http://www.example/Open.pdf"
Now from my android application I want to open this PDF file directly in the default PDF viewer.
The moment I click on this link on the webpage, user should be presented with a default PDF viewer opened with this document.
Note: This file should not be stored on the SD card.
How do I proceed for this implementation?
We can open PDF file in the webview without caching it. Write below code in "onCreate" method .
Working code :
String url = "http://www.example.com/abc.pdf";
final String googleDocsUrl = "http://docs.google.com/viewer?url=";
WebView mWebView=new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return false; // then it is not handled by default action
}
});
mWebView.loadUrl((googleDocsUrl + url));
setContentView(mWebView);
What happens here is you open the PDF using Google Docs. Best Advantage of using above method is the lazy loading of PDF. Does not matter how heavy the PDF is. Google Docs takes care of it.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
There is no way you can open a default PDF view from your application.
If your file is on the server and you want to open it without downloading then this might also pose a greater security concern. If external applications like default adobe reader can access the content on your server, then this is breaking the security framework altogether.
So, best option would be to launch a new instance of browser or webview and show the PDF document in google docs to the user.
This way user can read the document and get back to the recent state of the application as well.
You can view the pdf in the WebView using googleDocs.
WebView webView = (WebView) findViewById(R.id.my_webview);
webView.setWebViewClient(new MyWebViewClient());
webView.addView(webView.getZoomControls());
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");
do you have the others solution besides view pdf file using http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf
I am trying to set an image to a WebView for my app.
I am using the below code to set the image to my WebView,
String imageUrl = " file:///android_res/drawable/dinner_menu.png";
WebView wv = (WebView) findViewById(R.id.yourwebview);
wv.getSettings().setBuiltInZoomControls(true);
wv.loadUrl(imageUrl);
This works fine for Android 2.2 and higher.
But if I try to run the code in 2.1 or lower, it shows an error as,
The requested file was not found /android_res/drawable/dinner_menu.png.
Can anyone help me out.
Try putting your image in your assets folder, and load it using:
WebView webView = new WebView(this);
webView.loadUrl("file:///android_asset/dinner_menu.png");
setContentView(webView);
It should work on earlier versions of Android, but you'll need to manually manage using different versions of your image for different screen sizes / densities.
Is there any way to load PDF file from Asset/URL in Browser or WebView or any other way?
There is no native way to do this at the moment. However, you could write your own pdf viewer activity. Also, check out RepliGo Reader and PDF GView.
Instead loading PDF file from local resource, you can think about open it online using Google Docs Viewer:
WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);