okay, so i am making an app (i am new to android) which will have notes of a particular subject. I'll be creating these notes in PDF format.
Now i have implemented points system in my app,
So with 100 points you can unlock the notes and read it in app and with 1000 points you can save it on your device (locally).
So now PDF viewers and all are complicated, so I'll be converting these notes from PDF to HTML and I'll put all the resources and HTML in assets folder. I will display these html notes in a WebView. So now my question is should i use an external library for WebView ?
What i basically want is :
- User should be able to zoom in and out (as he is comfortable reading the notes)
- Scrolling should work in webview(which usually does natively)
- User should not be able to select text in the webview (read only mode type) so that he can just not share the content.. if he wants to share, use 1000 points and download the PDF...
how do i implement this ? downloading the PDF is a later part, right now i am more concerned about
User should not be able to select text in the webview
Is this possible ? Screenshots are okay. (i know its not but notes will be huge so screenshot will be a task too :P)
I think you can do one thing which is you may use this following approach if it suits all of your requirements:
1] You can get the PDF downloaded in the end user's phone via hitting some URL (you will need an API for this) or you may place it in the app's storage:
i) Assets folder - If you want to keep/store some PDF already in the app (this may increase your APK size as well as you cannot write something to the assets folder but you can read from it) or,
ii) Use SQLite database - You can manage your own SQLite database for Android for storing PDFs (this is an effective approach as you can read as well as write data to this database, if implementing this), both of these storage options are fully secure unless the device is rooted i.e. data cannot be accessed from outside the app unless the device is rooted and when the user uses/grants his 1000 points wanting to save a file (PDF) on his device (locally), you can then write that file to the external storage of the respective user's device from your app's database thereby making it accessible outside of your app.
2] You may use the PdfRenderer class (present in Android), which enables rendering a PDF document (which was added in API level 21 i.e. Lollipop). If you use this, then only users having Lollipop and above in their Android devices can be converted as your app's end users. So, keep this thing in mind. What PdfRenderer does is, it renders every page of the given PDF into a bitmap image which can then be displayed in an ImageView, this can fulfill your requirement of the content must not be copied from the given PDF's pages as each page of the PDF is a bitmap image now that's displayed in an ImageView.
References:
a] PdfRenderer theory - https://developer.android.com/reference/android/graphics/pdf/PdfRenderer
b] PdfRenderer sample (using Java code) - https://github.com/googlesamples/android-PdfRendererBasic/#readme
c] PdfRenderer sample (using Kotlin code) - https://github.com/googlesamples/android-PdfRendererBasic/tree/master/kotlinApp/#readme
3] Then, you can apply ScrollView as the parent if your rendered bitmap image (single bitmap image for a single page) is large enough than the respective device's dimension.
4] For the zoom in and zoom out effects to be applied on that bitmap image you can use the Chrisbane's PhotoView instead of using the normal ImageView.
Reference:
a] Chrisbane's PhotoView - https://github.com/chrisbanes/PhotoView
Note: Orientation handling of the app should also be done as to give a better UX to the respective users of the to be made app. Wishing you good luck!
Related
I am currently using Xfinium PDF to generate pdf into images and do some drawing on to the pdf using their Graphics api e.g. drawing cubic paths.
There is a constructor PdfFixedDocument which I used it to load the document. The problem is when I tried to load a 30mbyte document to get the page information it would take 10+second to call the PdfFixedDocument constructor which is quite inefficient if I just want to fetch the page information or just loading a single page.
Does anyone have any better idea? I can't use PDFRender on android because I am running kitkat. Will there be a better api which can give me a better efficiency.
For extracting a single page you can open the file using the PdfFile class and then extract the page using the PdfFile.ExtractPage method.
You can also extract the basic page information (width, height, rotation) using the PdfFile.ExtractPageInfo method.
The PdfFixedDocument constructor loads the entire file into memory and maps it to XFINIUM.PDF object model so that any object can be easily updated and depending on the objects in the PDF file this can take some time.
Disclaimer: I work for the company that develops XFINIUM.PDF library.
I have a xamarin forms project for the company I work for. I have 6000+ images used in two ways : a thumbnail page and a full size page. I have both the thumbnail image and the full size image. The thumbnail page shows 12 products at a time, but it lives in a carousel page so it could have up to 18 content pages within the carousel.
I've tried three ways of saving/accessing the images:
Including them as bundle/android resources. This works the best but takes forever to build the project and on android will mean I have to use expansion files.
Included the binary image from the database when downloading the product listing. Causes the app to crash randomly on download.
Downloading all of the files from the web. This works, but on both Android and iOS, the thumbnail screen slows to a crawl and half of the time crashes on Android.
Has anyone had to do something similar and if so, what way did you decide to go? Unfortunately, this app does have to be usable offline so I need the images local. I'm kind of in a time crunch so any help would be appreciated!!
I had similar issues someday back and understood that it won't be successful with standard Image class with such a large amount of images (no memory caching, no task queueing, etc). Then I made CachedImage. It's basically an API compatible replacement for Image with advanced caching capabilities (and some other features). You could try that.
Just remember to use:
Downsampling feature : that way image would be resized to view size to save memory
Caching feature (it's enabled by default not including StreamImageSource for which you have to provide custom cache key factory)
Use FileImageSource (app dir) or StreamImageSource (eg. from image database) with custom cache keys
https://github.com/molinch/FFImageLoading (See WIKI for docs)
I plan to use the built-in android pdf library. In my app I need to display a pdf report that may consist of several pages. Users should be able to print those pages. Printing with the PrintDocumentAdapter seems pretty straight forward, but what's unclear to me is what is the best way to create the pdf. I know that you can generate a PdfDocument with simply a View/canvas and or take more "low-level" approach where you draw lines,text, paint, etc.
I see three possibilities:
Create a view for each page. The user can navigate between the views as needed and print. However it's unclear to me how to generate a pdf for each page/view. What I mean by this is if I'm viewing page/view 1, yes I can easily create a pdf from this, but what about the other pages? Yes I can have this in memory, but what I've found is if they aren't actively being displayed on screen, they create empty pdfs. I don't want to have the user print each page individually.
Create the pdf documents (low-level approach), integrate a pdf reader and just display/print the pdf from there.
Create a view for each page that the user can navigate through. When the print option is invoked, generate the pdf documents again (low-level approach)
Obviously option 1 is the preferred approach, but I'm not clear on how I can do that. Of course, I could be missing something here so any help would be appreciated!
Android didn't have built in pdf genaration library, but in API19 android provided an api https://developer.android.com/reference/android/graphics/pdf/PdfDocument.html
But as #Ivan Wooll said itext is a nice pdf generation library if you want to use.
...but what's unclear to me is what is the best way to create the pdf...
Yet, it is relative. It really is a matter of what library/framework you find more convenient to work with, because each of them offers quit the same functionality with its own disadvantages. For instance, those I worked with, have the following ones:
iText - you must buy a licenece for comircial use (see What is latest version of itext that is not AGPL?);
Android Print Framework - no built-in pdf preview before printing as you mentioned in the 2nd item (you can use built-in PdfRenderer though for API 21+; also see Display PDF within app on Android?). Another disadvantage is the disturbing system dialogs when you'd like to save/print "silently" :)
Even the official documentation states that "You can use any PDF generation library to generate a PDF document and pass it to the Android print framework for printing."
...Yes I can have this in memory, but what I've found is if they aren't actively being displayed on screen, they create empty pdfs...
The reason for empty pdfs when you keep the views that have been left by a user in memory is their 0-dimension because of not being laied out (see Android: PdfDocument generates empty pdf). The same will happen if you try to inflate the views that haven't been reached by a user yet... In fact, there is nothing you can do about it, this is how Android works.
I don't want to have the user print each page individually.
In this case I suggest you to create pdf pages in advance for each content view a user is currently interacting with, just make sure that the view is still laied out when drawing it on canvas. For the views that aren't currently laied out use the "low-level approach". And once printing requested pass the output pdf to Android Print Framework.
There are a few pdf generation libraries out there. Itext being the simplest to use but it's ludicrously expensive. Pdfjet is another one which is reasonably priced. A quick google will provide you with more i'm sure.
We have a mobile workforce using Android Galaxy tabs and use the MobiControl MDM product to sync detailed briefing files to and from the devices on a constant basis.
Rather than having the user search through a sea of irrelevant briefs in order to find the one they want, and to provide a nicer more activity specific UI, I would like to create an app which allows a user to tap a client from a list and then show links to the relevant files plus custom content such as recent news and summaries of activity.
I started to create locally stored HTML files (saved on the internal sdcard) with the idea of creating an app to access them using webviewer but have ran into a few problems...
1) What is the best way to access files that are stored on the sdcard using webviewer? loadData? string?
2) Although the files will be stored in client specific folders, the file names will change on a ongoing basis and these ever changing file names should be the titles of the links to allow the user to identify what they need.
Still very much at the preliminary stages of thinking and r&d so suggestions on the best route to take to achieve my goal is very much appreciated.
Ad
1) What is the best way to access files that are stored on the sdcard using webviewer? loadData? string?
loadUrl() should work.
BTW, your item "2)" is not a question.
I am managing a bunch of PDF files in an android application maintaining a list of records in a SQLite database as well as storing the pdf files on the external storage.
Now I would like to present a thumbnail of the first page of the pdf in my list view as part of each cell representing a pdf.
I am aware of libraries like iText, fop.. on the JavaSE side that can render a PDF but I would rather not delve into embedding a large library like that. On a similar approach I would also rather not embed a native PDF viewer like droidreader, apv or vudroid.
Otherwise I could of course also get it rendered on a server via some webservice but that is a lot of headache as well.
I am already using intents to get the pdf's displayed for the user so I was thinking it would be great if I could get a thumbnail via a intent call as a result somehow. However I found nothing on the web (e.g. on openintents) that indicates something like that exists ..
So I am a bit at a loss on what to do? What do you think is the best approach to get these thumbnails into my app? Are there any public intents available? Or did I just totally miss something and the SDK provides features for that already (it should imho but currently does not)?
You are going to get a lot faster resopnse rasterizing the PDFs on the server and there are lots of libraries to do this in C, Java, Php.