-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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();
frame.setWidth("100%");
frame.setHeight("100%");
frame.setParent(center);
frame.setContent(amedia);
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,
Gyo
Asked: 2013-08-14 21:09:46 +0800
Seen: 28 times
Last updated: Aug 14 '13
composite component help [closed]
EL in a forEach @command not working?
Different template for each grid row
Cardlayout animation is broken
Grid RowRender slow using 6.5.1 and sizable=true
setVisible(false), component will load or not
Decimalbox and doublebox value rounded on iPad
history management with page status