Conversion of HTML page into pdf file in Android - android

We have to generate pdf file using html file.
For e.g. we have file "mypage.html" we have to show all page data as it is in pdf file.
Every time in application we will receive new html pages & we have to show as it is in pdf file.
Can we know how to do this by using iText or any third party libraries ?

Related

Display pdf file within app

I have pdf file download in my device on known location. I want to display it within my application. I tried several pdf viewer libraries like:
https://github.com/JoanZapata/android-pdfview <--- This is deprecated.
https://github.com/jblough/Android-Pdf-Viewer-Library <--- Does not display pdf properly. I mean it has several issues while loading pdf.
https://github.com/barteksc/AndroidPdfViewer <--- So far best I could find over the internet.
But none of the above work on hyperlinks to navigate to certain header within the file.
I know i can display pdf file in Google drive viewer, but I don't want that.
So anyone can suggest me relevant pdf viewer library in android which I can plug in my project?
Use google doc viewer to view pdf without any external library.
String pdf = "http://www.pdf995.com/samples/pdf.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);

Using Pdf.js in Android hybrid app to load local files

I am developing an app for android using Sencha touch and Cordova which needs to load PDF files.I found the Child browser support on PDF is not there for Android.So I decided to use PDF.js.I am using the following line of code to open the PDF file :
window.open(\''+ ROOT_FOLDER+'/app/util/PDFJS/web/viewer.html?file='+ROOT_FOLDER + '<Path to PDF file>\'
ROOT_FOLDER is the local file path URL like file://app/utils.."
But the pdf is not loading in this case and it is throwing an exception like
XMLHttpRequest cannot load file:///android_asset/www/<path to PDF file>. Cross origin requests are only supported for HTTP.
Please let me know how to fix this issue, or how to load PDF files from local location using PDF.js
If you want to load the files from local location, then it should be present in the same folder with viewer.html. In short the PDF should not be outside the main folder where all these html and js files are present.

How to add text as prefix

I wanted to open a file without downloading it so i used window.open in InAppBrowser and it works fine in ios... But i am not able to open a pdf file this way on android.
I was able to open a pdf file using google doc by prefixing like my url:
https://docs.google.com/gview?embedded=true&url=<my_url>
Now its opening pdf files, but files with images (.png) or text (.txt) cannot be opened this way, because they will be shown as html files.
So, when i get a pdf file on an android device it should check if the last three characters are matching (pdf) and in that case add a prefix to open the pdf file. All other files should work fine.
How about:
String url = "my_pdf.pdf";
if(url.endsWith(".pdf")){
url = "https://docs.google.com/gview?embedded=true&url=" + url;
}

how to show Rich text file for offline help in android

I want to save a .rtf Rich text file with my app as offline help. when the user clicks for offline help, the app will show this text file. I don't want to use pdf help file because it wont be accessible on phone with no pdf viewer.
I would like to use html offline page stored in Assets folder if that is a better approach than the RTF file.
I have seen this Loading existing .html file with android WebView just looking for the .rtf file answer now

PhoneGap Android app not displaying pdf data

I have a PhoneGap app for Android which I am trying to run in the Android emulator. The app has a simple html page which has a button. On click, the button calls a RESTful webservice using javascript XMLHttpRequest and the service returns back base 64 encoded data for a pdf. Then from the javascript function, I try to load the pdf data in my html page in the app as below
document.location.href = 'data:application/pdf;base64,' + pdfData.childNodes[0].data;
But this does nothing. The data is returned correctly and I checked the logs for it. But the pdf is not displayed at all. Any idea what is causing the issue?
In Android you not show pdf file in Webview. Have some solution to view pdf file in Android:
Use google pdf view
mWebView.loadUrl("https://docs.google.com/gview?embedded=true&url="+LinkTo_pdfFile);
Download pdf file and view by pdf reader in device. Check this
(My solution) I parse pdf file to image and store onto server and i only download and view image directly.(It have bit complex, but you can view pdf, docx, xls,..). Example here

Categories

Resources