Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Can not load pdf in Chrome
Can not load pdf in Chrome [message #1746698] Thu, 03 November 2016 11:59
David Song is currently offline David SongFriend
Messages: 211
Registered: April 2011
Senior Member
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
Previous Topic:link widget has no markup???
Next Topic:[ANN] RAP 3.2 M3 published
Goto Forum:
  


Current Time: Fri Feb 23 05:24:39 GMT 2018

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

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