zotero / zotero-android

Zotero for Android

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lower image-annotation thumbnail resolution

dstillman opened this issue · comments

I'm seeing much lower resolution in the sidebar than on iOS for the same annotations. @michalrentka, any guidance on sizing?

We can directly set the render resolution on iOS, not sure how it's on Android.

commented

A while ago I've sent them this email:

Greetings!
I am Dmitrii and I work for Zotero. We are using PSPDFKit for our iOS and Web applications. I am building an Android version of the Zotero app.

Here is the problem I am trying to solve:
PDF viewer screen in Zotero app, aside from showing PDF itself also displays a sidebar with a list of all annotations that PDF contains and allows navigating PDF by selecting an annotation in the sidebar (please see attached screenshot).

The list item in that sidebar is basically an annotation preview bitmap which displays the annotation itself (for example ink or image annotation) and the raw pdf content displayed behind it.

If you look closely at the screenshot you will notice that for previews of annotations that occupy a small area of the screen the display quality of the raw pdf content is quite low.

On iOS we do not have such an issue.
This is because implementations of Annotation Preview Renderer on Android and iOS are different due to either limitations of PSPSDFKIT’s render capabilities on Android’s version of PSPSDFKIT’s library or me simply not finding an appropriate way to make PSPDFKit draw the higher quality result.

To explain the situation better let’s compare how iOS and Android render Annotation previews in the Zotero app.
Basically the way iOS does it:

  1. Takes the bounding box of a given annotation. It’s simply an area which the given annotation occupies.
  2. Asks PSPSDFKIT to draw the contents of the PDF document located inside of this bounding box into a UIImage of desired resolution.
    There are 2 important nuances here.
    First, when making such a rendering request iOS is able to ask PSPSDFKIT to include the raw document’s content plus only the given annotation (well technically to achieve this we ask PSPDFKit to exclude all annotations aside from a given when rendering).
    Second nuance is that on iOS PSPSDFKIT is able to tune its output image result per desired UIImage resolution.
    In other words if you want to draw a given 64 by 35 pixels area of a PDF document with some annotation into UIImage of say 300x200 pixels you can indeed do that and you will get a very good high quality picture.

On Android’s PSPDFKit there doesn’t seem to be a way to achieve the same result with the same steps. So instead I had to figure out and piece together a different approach.
When you try asking PSPSDFKIT to draw a given bounding box into a Bitmap there is no way to tell it to just draw raw PDF content plus given annotation. It can only draw everything a PDF document has (all annotations included) in the bounding box you request.
So to sidestep it I have to separately instantiate another instance of PSPSDFKIT Document object without adding any annotations to it and ask PSPSDFKIT to draw a given bounding box into a bitmap (using renderPageToBitmap). This gives us a Bitmap containing just raw PDF document content.
When making such a request there is no option to specify target resolution. So. If you want to draw a bounding box that is 64 by 35 pixels the only thing you will get is a result bitmap that also has 64 by 35 pixels.

Ok so we have a bitmap with raw PDF content. We now need to create a second bitmap with annotation itself.
There is a PSPSDFKIT API that allows you to just draw a given annotation into a bitmap (annotation.renderToBitmap). Interestingly enough this api does allow you to specify target resolution, so we can make a high fidelity bitmap of just the annotation itself.

Now we merge those two bitmaps together and we get the result we need.
But the end result is a bitmap, where you can see raw PDF’s content being low quality with a high quality annotation sitting on top.
I’ve been trying to figure out how to make it better, browsed PSPSDFKIT’s documentation and looked through examples project but couldn’t find a better solution.

Could you please either confirm that Android’s version PSPDFKit indeed doesn’t currently allow to achieve the same high quality result as its iOS version and if so could you please give estimates on when you guys are planning to implement it.
Or if there is already a way to achieve what we need with PSPDFKit on Android then please advise on how I would implement this.

Cheers!

commented

To which I got a reply like this:
"Thanks for getting in touch. In order to help you further, could you please provide a sample app to reproduce this? If possible, include the problem in the app as well for easier debugging and helping you."

The things is:

  1. It might take me a good while to create a separate sample app that showcases this situation.
  2. I am not sure why they need a sample app to resolve this.

I don't think the questions that I raise at the end of my email require any sample apps as there is nothing to debug or fix. I have simple questions of whether you have that functionality on Android or not. And if you do then explain how would i go about implementation.
My email contains lots of tech details that explains the issue with pointers on how this is achieved on iOS.
They just need to check their documentation and ask their Android & iOS folks to resolve it.
I am not sure how should I proceed.

@Dima-Android I probably wouldn't mention iOS at all, just ask them how to render parts of pdf on android in higher resolution. But since you're already here, why is making a demo app difficult? I've provided some demo apps for them before, it helps them because they can debug the app with their internal tools and see what's going on better.

Just create a sample app with single window which contains PSPDFKit with some hardcoded opened PDF file. Then add a button which does the background processing (which you can mostly copy from our existing app) and show the resulting image above the PDF in some hardcoded place.

Or maybe just try simplifying the question to something like:

Thanks for getting back to me,

creating a sample app might take some time, so I'd like to make sure we understand each other first. 

Is there a way on Android PSPDFKit to render parts of PDF in custom resolution? We'd like to be able to render parts of PDF in higher resolution and I wasn't able to find a way to do this in the Android SDK. 
On iOS we use "RenderTask" and "MutableRenderRequest" to do this. Does Android SDK have a counterpart to "RenderTask"?