Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Can not load pdf in Chrome
Can not load pdf in Chrome [message #1746699] Thu, 03 November 2016 07:59 Go to next message
Eclipse UserFriend
hi,

In my RAP project, pdf file is created by iText dynamically as inputstream and displayed in browser. it can work well in IE with Adobe Reader, but Chrome gives errors as below:

rap-client.js:106 Resource interpreted as Document but transferred with MIME type application/pdf


the code snippet is:

InputStream pdfData = (InputStream) RWT.getUISession().getHttpSession().getAttribute(PrintDialog.PDF_KEY);
		//HttpServletResponse resp = RWT.getResponse();
		
		response.setContentType("application/pdf");
		response.setHeader("Cache-Control", "no-cache"); // HTTP 1.1
		//response.setHeader("Cache-Control", "max-age=0");
		response.setHeader("Content-Disposition", "inline");
		//response.setHeader("content-length", pdfData.);
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		int next = pdfData.read();
		while (next > -1) {
			bos.write(next);
			next = pdfData.read();
		}
		bos.flush();
		byte[] result = bos.toByteArray();

		try {
			ServletOutputStream out = response.getOutputStream();
			out.write(result);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}


ServiceManager manager = RWT.getServiceManager();
manager.registerServiceHandler(SERVICE_HANDLER, new PDFServiceHandler());
browser.setUrl(manager.getServiceHandlerUrl(SERVICE_HANDLER)+"&random="+RandomUtils.nextLong()+"#toolbar=1&view=FitH,top");


Thanks
Re: Can not load pdf in Chrome [message #1746767 is a reply to message #1746699] Fri, 04 November 2016 07:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi,
it seems that it's a Chrome issue, not directly related to RAP. There are lot of similar questions in SO.
Regards,
Ivan
Re: Can not load pdf in Chrome [message #1755197 is a reply to message #1746767] Tue, 28 February 2017 19:38 Go to previous messageGo to next message
Eclipse UserFriend
Ivan Furnadjiev wrote on Fri, 04 November 2016 07:14
Hi,
it seems that it's a Chrome issue, not directly related to RAP. There are lot of similar questions in SO.
Regards,
Ivan



Thanks Ivan, but Is there any way to avoid this Chrome problem? This has been bothering me for a long time.

Regards
Daivd
Re: Can not load pdf in Chrome [message #1755640 is a reply to message #1755197] Mon, 06 March 2017 08:24 Go to previous messageGo to next message
Eclipse UserFriend
Hi David,
I am using RAP (3.0) for displaying PDFs in the browser widget as you do, but in my case it works both in IE and in Chrome.
Here is my code:
(I keep a reference to the file absolute path to be shown = completeFilePath)
				File file = new File(completeFilePath);
				FileInputStream fileInputStream = new FileInputStream(file);
				OutputStream fileOutputStream = response.getOutputStream();
				int bufferSize = 512 * 1024;
				byte[] buf = new byte[bufferSize];
				int len;
				while ((len = fileInputStream.read(buf)) > 0) {
					fileOutputStream.write(buf, 0, len);
				}
				fileInputStream.close();
				fileOutputStream.close();

as you can see I do not use neither
response.setContentType()

nor
response.setHeader()


but it works, at least with IE 11 and Chrome 56, on Windows 10.
Can you do a test with exactly this approach and see what happens?
Re: Can not load pdf in Chrome [message #1756094 is a reply to message #1755640] Fri, 10 March 2017 22:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi Vincenzo,

Thanks for your reply.

When application reads the server-side fixed entity file as pdf , it can be displayed normally in Chrome. But Chrome visit will be reported org.eclipse.jetty.io.EofException exception in eclipse rap console window, Firefox works well and no exception. But changed to read the dynamically generated stream will be wrong, the pdf can not shown, while Google Chrome console error: rap-client.js: 106 copy of the file but transferred with MIME type application / pdf, but Firefox is still working properly.

Regards,
David

Vincenzo Caselli wrote on Mon, 06 March 2017 08:24
Hi David,
I am using RAP (3.0) for displaying PDFs in the browser widget as you do, but in my case it works both in IE and in Chrome.
Here is my code:
(I keep a reference to the file absolute path to be shown = completeFilePath)
				File file = new File(completeFilePath);
				FileInputStream fileInputStream = new FileInputStream(file);
				OutputStream fileOutputStream = response.getOutputStream();
				int bufferSize = 512 * 1024;
				byte[] buf = new byte[bufferSize];
				int len;
				while ((len = fileInputStream.read(buf)) > 0) {
					fileOutputStream.write(buf, 0, len);
				}
				fileInputStream.close();
				fileOutputStream.close();

as you can see I do not use neither
response.setContentType()

nor
response.setHeader()


but it works, at least with IE 11 and Chrome 56, on Windows 10.
Can you do a test with exactly this approach and see what happens?

Re: Can not load pdf in Chrome [message #1756130 is a reply to message #1756094] Sun, 12 March 2017 15:50 Go to previous message
Eclipse UserFriend
Quote:
When application reads the server-side fixed entity file as pdf , it can be displayed normally in Chrome
If you can get Chrome displaying the PDF, check the response headers Chrome gets when it's working.

Replicate those headers with your service handler that delivers the PDF.

The EofException is most likely caused by Chrome terminating the network connection before it downloads the content
Previous Topic:ClientFileLoader of fonts as registered resource
Next Topic:Use web.xml with the RAP launcher
Goto Forum:
  


Current Time: Tue Jul 01 12:11:34 EDT 2025

Powered by FUDForum. Page generated in 0.05751 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top