WebView local link - java

I have a WebView which reads local html file. It is a big file, so it is scrollable. I also have a link within WebView which leads to another local html file, which is a lot smaller file. When I enter that link, scroll position from first file is transferred to second file. So, second file is same size (height) as first file. I tried entering an outside link(www link) and it opens normally.
Thanks!

Related

Modify information inside jar file

so my question is about programm written in java. I created sort of top 5 scores ranking using a text file for my game. It reads top scores, that are already saved in a text file, and when you finish the game, it writes to this text file, then reads it and updates top scores shown in the game. But now i'm stuck in packaging my game to a jar file. It seems impossible to modify a text file inside a jar file...
So what are possible solutions here? Forcing a programm to create new text file in a path where jar file is is one of the solutions, but maybe there is some easier solution that won't create additional file on a computer.
I would recommend having an external text file stored somewhere relative to your program. Then have your program modify it as it needs.

How to open local pdf file in WebView Android Studio

I am aware that this question has been asked many times, but I still cannot get it to work. I have a pdf in the raw folder and I am trying to open it in a webview using "https://drive.google.com/viewerng/viewer?embedded=true&url=" to open it in the webview.
I think my problem is I can't get the correct path for the pdf file. I've tried it three different ways, and either the webview says I get an error (the url doesn't exist), or it "opens" the pdf, but the webview displays this text in the middle, "No preview available".
These are the three ways I've tried to get the path of the file.
"android.resource://com.an.example/raw/filename"
"android.resource://" + getPackageName() + "/" + R.raw.filename;
Environment.getExternalStorageDirectory() + "/filename.pdf"
For methods 1 and 3 I have tried "filename" and "filename.pdf"
None of these are allowing the pdf to load in the webview. Below is the code I use to load the pdf. (Note: this method does work if I use a web url and not a local file)
webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setBuiltInZoomControls(true);
String pdf = "one_of_the_above_methods";
webview.loadUrl("https://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);
What am I doing wrong? Is there a better way to load a local pdf inside my app without having it take up the entire activity page?
I have a pdf in the raw folder and I am trying to open it in a webview using "https://drive.google.com/viewerng/viewer?embedded=true&url=" to open it in the webview.
That has never been possible.
Is there a better way to load a local pdf inside my app without having it take up the entire activity page?
The best thing is to not load it inside your app at all. Use the user's preferred PDF viewing app, via ACTION_VIEW.
Beyond that, you could use a slightly modified version of PDF.js on Android 4.4+. Or, use AndroidPdfViewer on a wider range of Android versions, though it makes your APK a lot bigger. See this blog post for more context on these and other (worse) options.
Also, here are sample apps demonstrating:
PDF.js: https://github.com/commonsguy/cw-omnibus/tree/v8.10/PDF/PdfJS
AndroidPdfViewer: https://github.com/commonsguy/cw-omnibus/tree/v8.10/PDF/Pdfium

Can't access image

I am trying to display images on a JSP page.
Two hyperlinks are used to display image.
One of them is as follows:
Image
When one of the links is clicked, the corresponding image is displayed.
In the above case, MyPic.jpg is saved in web\img\MyPic.jpg(Inside the project folder).
In the other case, I saved the image in local disk.
E:\img\MyPic.jpg
and I tried the following code:
Outside image
and
Outside web
But this link is not working and I can't access the image.

How to print entire webpage contents (including dynamic contents)?

I want to read the entire webpage contents including dynamic contents (also HTML contents loaded by JavaScript inside iFrames, nested iFrames). I could simply rebuild the page with printed page contents. I tried using Java here (How to print external script inside iframe using htmlunit?) but did not succeed. Any suggestions?

Printing a pdf file stored on server to client side printer

I am generating PDFs file dynamically in my application using Apache PDFBox library.
I have jsp page which is having Print button.When user click on that print button i want to generate PDF file and at the same time show pdf file on browser and apply window.print() method.
How can i achieve this in my jsp page?
Create a pdf link on your page and the link should be mapped to the actual location the PDF exists on your server.
The browser actually handles what to do with the pdf (based on your browser settings) .... whether to download it or open it via plugin. The bottomline is you cannot control it via server side code.
In either of the case you cannot apply window.print() because that is only applicable to browser window and not pdf plugin functionality or if it gets downloaded then he has to manually open it.
There is an alternate solution to this. That is show the pdf in a div in your html and print that div.
For how to show pdf in a html div you can look Display Adobe pdf inside a div
For printing a div or any other html element there are jquery plugins available. I have used print.js that will print a html div, it will also maintain your css.
So when user clicks the print button first show the pdf in a div and then call the print function to print that div.

Categories

Resources