9

I have used Google Document Viewer to open PDF files in my Android device. A black screen with "No Preview Available" text is shown, instead of opening my PDF files. I have tested with sample PDF files from Google. They are working fine, but not my PDF files. Is there anything that i need to do from code side to view my PDF.

http://docs.google.com/viewer?url=myurl.pdf

enter image description here

msg
  • 1,480
  • 3
  • 18
  • 27
  • Can you please give a link to a PDF that is not working? – firefoxuser_1 Mar 07 '15 at 18:56
  • Sorry, I could not share link. It's like https://xxxx.com/123/test.pdf – msg Mar 07 '15 at 19:11
  • Have you fix this issue. I am also getting this issue. – AndroidLad Jun 23 '15 at 09:48
  • 1
    Yes @ohm. The reason is; my PDF file was hosted in server with some security restrictions. Later we allow permissions to that hosted PDF file & then it works fine. – msg Jun 24 '15 at 19:58
  • 1
    Just in case anyone else has the same issue I did. I was getting this error because I had basic password protection on my folders, to make them private during production. This was not allowing google to get access to the pdf. Once I took the password protection off the folder, it worked as expected. – narco Nov 22 '15 at 13:16

3 Answers3

4

Had a file that showed this problem. Renamed it to remove blanks in the file name, updated my link and it worked. Note that blanks were properly HTML encoded as %20 so this 'fix' shouldn't be necessary. But, I can't argue with success. Good luck.

Deep Mehta
  • 1,250
  • 1
  • 16
  • 29
larry
  • 41
  • 2
  • Yes, this seems to have changed very recently to not allow blankspace and other encoded characters in the filename. Something that is very annoying since we have been using it quite a lot and so are now stuck with a lot of embedded pdf:s that used to work but are now broken. Does anybody have a clue where to bug report this? – Jonatan B Sep 28 '16 at 11:41
  • But in my case, there is no blank space in URL. My URL is like : /storage/emulated/0/Download/ExamPro/file_exam_pro1666056563400.pdf but it is still not working – Abdullah Programmer Oct 18 '22 at 01:32
3

Finally solved this issue. Issue is there in url. In url I replaced %2 to %252 then after 1 week I solved this issue.

In short I want to encode query string.

if (Url != null && Url.contains("=")) {
    String Urll =Url.substring(Url.lastIndexOf("&Signature=") + 1).replace("%2B", "%252B");
    if (null != Urll && Urll.length() > 0 && Urll.contains("%252B")) {
        int endIndex = Url.lastIndexOf("Signature");
        if (endIndex != -1) {
            Url = Url.substring(0, endIndex);
            Url = Url + Urll;
        }
    }
    Url = Url.replace("?AWSAccessKeyId=", "?AWSAccessKeyId%3D")
            .replace("&Expires=", "%26Expires%3D").replace("&Signature=", "%26Signature%3D");
}
Nisarg Shah
  • 14,151
  • 6
  • 34
  • 55
2

Try encoding the url like this

    try {
            encode_url=URLEncoder.encode(url,"UTF-8"); //Url Convert to UTF-8 It important.
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

webView.loadUrl("https://docs.google.com/viewerng/viewer?embedded=true&url="+encode_url);
44kksharma
  • 2,740
  • 27
  • 32