Open pdf with AMedia is not working - Page is blank

asked 2013-08-14 21:09:46 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2013-08-14 21:13:28 +0800

I'm trying to open and display a PDF file stored in an external folder which is mapped in tomcat. However when I read the file, convert it to byte array and set it to be displayed in an iFrame, the browser's pdf plugin shows a blank page Please check my code:

PS: I can open the same file by placing the url in the browser. So I believe I'm missing something in my code for sure.

PS2: I'm working with Safari browser.

                String strUrlFile = "http://localhost:8080/myapp/docs/10/myfile.pdf";
                URL url = new URL(strUrlFile);
                InputStreamReader isr = new InputStreamReader(url.openStream());
                byte[] buffer = IOUtils.toByteArray(isr);

                AMedia amedia = new AMedia("myfile.pdf",
                        "pdf", "application/pdf", buffer);
                Iframe frame = new Iframe();
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-08-14 21:33:47 +0800

gyowanny gravatar image gyowanny
283 1 2 6

updated 2013-08-14 21:34:16 +0800

lol Too early.

I was missing the OutputStream loading. The code excerpt below did the trick:

                ByteArrayOutputStream bios = new ByteArrayOutputStream();
                byte[] ba1 = new byte[1024];
                int baLength;
                while ((baLength = is.read(ba1)) != -1) {
                    bios.write(ba1, 0, baLength);
                AMedia amedia = new AMedia("myfile.pdf",
                    "pdf", "application/pdf", bios.toByteArray());

I hope this code can help another dudes with the same problem.

Thank you,


link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2013-08-14 21:09:46 +0800

Seen: 28 times

Last updated: Aug 14 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More