DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.15k stars 1.9k forks source link

Doesn't Render Modified PDF Text #230

Open Papabrose opened 7 years ago

Papabrose commented 7 years ago

Hello,

The pdf viewer doesn't render a pdf that has "flattened"/modified text in it on devices like the Nexus 6P and many other google phones.

What it should look like: image

What it does look like: image

Any idea how this could be fixed or when you may be able to make a fix for it?

1stmetro commented 7 years ago

can u post the pdf to test this?

Papabrose commented 7 years ago

Unfortunately I can't post the specific PDF (as it belongs to one of our customers) but we have found that it happens with any modified PDF on a Nexus 6P device. Any advice?

1stmetro commented 7 years ago

if you wish to post any pdf that is doing the same i would be happy to test it on my interface for you, just replicate the issue on your own pdf and post it.

Papabrose commented 7 years ago

@1stmetro Hey I was told these are generic and so I can give you an example so here you go! 06_Guarantee Agreement-modified.pdf

Let me know what you find if its a setting I can use or if its the PDF itself. If you open it up in a PDF reader you will see that it as text but as I showed in the picture above its not rendering that text in your control.

Thank you so much for your help!

1stmetro commented 7 years ago

Okay I see your issue mines does the same although there are some settings I may have to enable to fix this will keep you posted.

This appears to be a completed pdf form convert to standard pdf it will be ok since its completed you wouldnt want to edit anyway bit like layers within an image that you flatten I would flatten the pdf so to speak and try again as its a form the over lay is removed as this is a reader not a form pdf development i believe it may not be suported but the way around is convert to standard pdf.

Papabrose commented 7 years ago

Hey now that you mention it I forgot to tell you that we are flattening the pdfs before sending them to the viewer. Here is the flattened one. We have found that this displays on some android devices but not others. flattened PDF.pdf

1stmetro commented 7 years ago

Yeah flattened works fine, i can see all the information without any issues the device is a galaxy tab ermmm A on nougat OS if it runs on that it will run on all the devices i use, and i use 5 or 6.

You can test multiple devices via developer console if i remember correctly this may help you with different devices.

Papabrose commented 7 years ago

@1stmetro We have many physical devices we test on. This doesn't work on the Nexus 6P is there any way to figure out why it would not be working on a Nexus 6P?

1stmetro commented 7 years ago

What errors are shown when scrolling thought the monitor, sometimes it moves very fast so expand and run with device connected

Papabrose commented 7 years ago

It doesn't show any errors at all, it just doesn't show the text in the flattened PDF. On a Nexus 6P on android 7.1.1

1stmetro commented 7 years ago

your welcome to post your code that loads the pdf

Papabrose commented 7 years ago

Here it is, Let me know if this helps.

final byte[] bytes = Library.HttpGetByteArray(url);

 final PDFView pdfView = (PDFView) panelPDF.findViewById(R.id.defaultPdfShowPage);
        pdfView.setVisibility(View.VISIBLE);

        pdfView.fromBytes(bytes)
                .enableAnnotationRendering(true)
                .enableSwipe(true)
                .swipeHorizontal(false)
                .enableDoubletap(true)
                .defaultPage(0)
                .password(null)
                .scrollHandle(null)
                .onLoad(new OnLoadCompleteListener() {
                    @Override
                    public void loadComplete(int nbPages) {
                        pdfView.enableAnnotationRendering(true);
                        pdfView.zoomTo(3);
                        pdfView.setPositionOffset(0);
                        pdfView.loadPages();
                    }
                })
                .load();
1stmetro commented 7 years ago

Have you tried it without your code to resizing the screen ?

and enableAnnotationRendering(true) - false ?

just a thought if i use your pdf and test online with google devices using my interface it would prove if your code has issues or if it doesnt work on my code either, just an ideal?

Papabrose commented 7 years ago

Here is the code with the changes you suggested and I still have the same issue of it not rendering.

final byte[] bytes = Library.HttpGetByteArray(url);

  pdfView.fromBytes(bytes)
                .enableAnnotationRendering(false)
                .enableSwipe(true)
                .swipeHorizontal(false)
                .enableDoubletap(true)
                .defaultPage(0)
                .password(null)
                .scrollHandle(null)
                .onLoad(new OnLoadCompleteListener() {
                    @Override
                    public void loadComplete(int nbPages) {
//                        pdfView.enableAnnotationRendering(true);
//                        pdfView.zoomTo(3);
//                        pdfView.setPositionOffset(0);
//                        pdfView.loadPages();
                    }
                })
                .load();
1stmetro commented 7 years ago

take a peek at the link, maybe an issue with the support libraries used on other devices when viewing pdfs not included on the 6p. view pdf online with the with google docs probably be ok.

http://forums.androidcentral.com/ask-question/608099-why-doesn-t-nexus-6p-want-open-pdfs.html

Papabrose commented 7 years ago

Something interesting I just found. So if I run our app in an emulator then the flattened text shows up. Also it shows up if I use another PDFViewer like PSPDFKit. Would I have to manually install a library on the 6P to get it to work?

The PDF also opens on the device inside of Adobe Reader

1stmetro commented 7 years ago

what actually doesnt work on the nexus, is it a blank white page ?

A blank page could be the best quality setting as it uses a different image format its a simple switch.

pdfView.useBestQuality(true)

Believe the default is false setting so worth a try.

Papabrose commented 7 years ago

@1stmetro The flattened text does not render using this PDFViewer. The rest of it renders find just not the flattened part. It is not a blank white page.

I tried setting pdfView.userBestQuality(true) and it still does not render the flattened text from the PDF i posted earlier.

The whole PDF shows up except any of that flattened text. Any other thoughts? Its like I said this seems to be the only device that is having a problem but I assume since other PDFViewers work then this one can too.

We know this has to be a problem with the your PDFViewer on the Nexus 6 as other Viewers work. We were just hoping that yours could be made to work too.

EDIT: Also we just tested on a Samsung Galaxy S6 (Android 6.0.1), Samsung Galaxy Note 5 (Android 6.0.1), and One Plus One (Android 6.0.1) and they the same issues of the flattened text not displaying.

1stmetro commented 7 years ago

Take a look here it will explain test different types until one works

en.m.wikipedia.org/wiki/Portable_Document_Format

The Forms Data Format (FDF) is based on PDF, it uses the same syntax and has essentially the same file structure, but is much simpler than PDF, since the body of an FDF document consists of only one required object.

Papabrose commented 7 years ago

I don't think you quite understand, We don't make these PDF's we get them from our customers who use them with our app. So the PDF Viewer needs to be able to support and render any type of PDF that we give it from the customers.

Currently we are paying for PSPDFKit as it seems to work on all devices. I would love if this one could work similar to that one so we don't have to pay so much for a PDF Viewer.

The fact of the matter is that these PDF's work with other viewers and not this one. If you want to try and fix it that would be great. If not then I guess we will be stuck paying for one as we don't have the resources to download an open source one and manage it ourselves.

Papabrose commented 7 years ago

@1stmetro @barteksc Any thoughts on this? Any more information I can give you?

1stmetro commented 7 years ago

I have seen apps that use the web to convert docs such as word excel etc before sending the doc to the client in a useable format.

Ideally once your client competes the form you then encapsulate it into a pdf that works with pdfviewer either within an app or php asp etc depends how the pdf is generated as once the form is completed it doesnt matter on the pdf format.

I did look at the library you are paying for the price is too much !

Papabrose commented 7 years ago

I accidentally clicked the close button. You even said it yourself once the form is completed and the pdf is flattened and rendered it shouldn't matter. A PDF is a PDF which is why I'm saying this PDFViewer doesn't work as well as it could for some devices. I would love to be able to download the source and try to fix it but it would take me a lot more time than someone who already understands the code.

Maybe some day in the future it will get fixed but right now we are forced to pay for that pdfviewer as it is the best one we have used that actually works on 95% of devices where this PDFViewer works on about 75% of devices we test on.

Unfortunately we pass that cost onto our customers as well but I guess that is just part of the business. I feel like this ticket should stay open until the issue is fixed.

1stmetro commented 7 years ago

As a work around I guess i would look at the code that generates the PDF so upon completion generate a more usable standard basic pdf that is more reliably supported, just a case of finding the format it's happy with.

tentenponce commented 6 years ago

Hi @Papabrose , from my end, it works by adding enableAnnotationRendering(true). Here's my complete code:

pdfView.fromFile((File) getIntent().getSerializableExtra(FILE))
                .swipeHorizontal(true)
                .enableDoubletap(true)
                .scrollHandle(new CustomScrollHandle(this))
                .onError(t -> showErrorDialog(t.getMessage()))
                .onPageError((page, t) -> showErrorDialog(t.getMessage()))
                .enableAnnotationRendering(true)
                .load();
oncealong commented 4 years ago

renderPageBitmap also can renderAnnot

public void renderPageBitmap(PdfDocument doc, Bitmap bitmap, int pageIndex,
                                 int startX, int startY, int drawSizeX, int drawSizeY,
                                 boolean renderAnnot)