question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PDFView shows garbage or blank screen

See original GitHub issue

I am creating a file object and pass it to PDFView using the following code:

 try {
                URL url = new URL(urls[0]);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.connect();

                if(conn.getResponseCode() != HttpURLConnection.HTTP_OK) {
                    return "Server returned HTTP " + conn.getResponseCode() + " "
                            + conn.getResponseMessage();
                }

                //Useful to display progress
                int fileLength = conn.getContentLength();


                //Download the file
                InputStream input = new BufferedInputStream(conn.getInputStream());
                File dir = new File(getFilesDir(), "/temp");
                dir.mkdir();
                file = new File(dir, "temp.pdf");
                OutputStream output = new FileOutputStream(file);

                byte[] data = new byte[1024];
                long total = 0;
                int count;
                while ((count = input.read(data)) != -1) {
                    if(isCancelled()) {
                        input.close();
                        return null;
                    }
                    total += count;

                  
                    output.write(data);

                }


                output.flush();
                output.close();
                input.close();
            } catch (IOException e) {
                Log.e(LOG_TAG, "IOException: " + e.getMessage());
            }
PDFView pdfView = findViewById(R.id.pdfView);
            pdfView.fromFile(file).load();

The resulting pdf view is blank or shows garbage characters for most pages (I am going to load mostly PDF files containing Persian and Arabic script). How can this be solved?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
hurimengcommented, Jan 10, 2018

maybe,you didn’t put PDFView in a RelativeLayout

0reactions
malwinder-firminiqcommented, Aug 24, 2020

@djnotes I tried writing fos.write(buffer, 0, count); but still, it was showing invalid characters like İ, ş. Does anyone knows how to fix this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

objective c - Printing Off-screen PDFViews - Stack Overflow
When the test program is compiled without the USE_PDF_VIEW preprocessor macro defined, the blank view displays fine. If USE_PDF_VIEW is defined, the document ......
Read more >
Safari - PDF Black Screen... Can't view e… - Apple Community
Using Safari when I go to a website with an embedded PDF it comes up blank (black screen). I've tried with Firefox and...
Read more >
Solved: PDF viewer not working - Power Platform Community
Solved: I have used this tutorial to convert a file into PDF online and then try to show that PDF in my app....
Read more >
Trouble Viewing PDF's in Safari? Blank PDF's ... - Staff Websites
Now in the list that pops up simply delete or drag to Trash any file that shows up that has npapi and the...
Read more >
Fix Display of Linked PDF Files on the Web
A blank (or gray) page in the web browser; PDF files open and then ... control how pop-ups and links from other programs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found