File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Error in generating inline PDF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Error in generating inline PDF" Watch "Error in generating inline PDF" New topic
Author

Error in generating inline PDF

Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
Hi,

In one of my J2ee application i was trying generating PDF when user click on one particular link
for this i used itext pdf utility to generate byte array which then I'm writing to outstream

In IE 6.0 I'm not able to open it as inline content as expected but it's prompting me to save the pdf where as in firefox, i'm getting the below exception

java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:229)
at javax.servlet.ServletResponseWrapper.setBufferSize(ServletResponseWrapper.java:148)
at org.apache.cocoon.Engine.handle(Engine.java:488)
at org.apache.cocoon.Cocoon.service(Cocoon.java:187)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.servlet.SabaCharacterSetFilter.doFilter(SabaCharacterSetFilter.java:95)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.web.security.DataDecryptionFilter.doFilter(DataDecryptionFilter.java:38)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.web.tools.MonitorHttpRequestFilter.doFilter(MonitorHttpRequestFilter.java:57)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.saba.tools.loadtest.ParamCaptureRequestFilter.doFilter(ParamCaptureRequestFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
at org.jboss.web.catalina.security.JBossServletAuthenticator.invoke(JBossServletAuthenticator.java:71)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:534)


Can any body help me out to solve this issue

Thanks in advance
Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
to add on this below is the code that i'm using

response.reset();
response.resetBuffer();

response.setContentType( "application/pdf" );
//response.setHeader("Content-length",Integer.toString(TalentPDFUtil.getEmployeeProfilePDF(id).toByteArray().length()));

response.setHeader("Content-disposition","inline; filename=\"" +"Print.pdf" +"\"");


OutputStream outStream = response.getOutputStream();




outStream.write(TalentPDFUtil.getEmployeeProfilePDF(id).toByteArray());

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
why are you calling these methods, I think there is no need to call them.??




Omar Al Kababji - Electrical & Computer Engineer
[SCJP - 90% - Story] [SCWCD - 94% - Story] [SCBCD - 80% - Story] | My Blog
Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
Thanks for your reply

i tried by removing below two lines

response.reset();
response.resetBuffer();


but still in log, I'm getting that exception

Actually after response.reset(); i was able to open pdf inline in IE otherwise it's always asking me to save

Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
do you flush and close the outStream ??
Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
I'm not calling flush or close on outStream
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
you should call them:

outStream.flush();
outStream.close();
Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
I already tried by calling os. flush() and os.close()
but that exception persists irrespective of it
that's why i removed that from my code
Anuj Pathak
Greenhorn

Joined: Mar 22, 2009
Posts: 6
any other thing that i can add/check in my code to solve this issue

Please suggest
Omar Al Kababji
Ranch Hand

Joined: Jan 13, 2009
Posts: 357
I don't know it should work by setting the content-type and passing the bytes to the outputstream and then flush and close it. am sorry I can't help you. at least could you put the whole code of your servlet here. maybe there is something else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error in generating inline PDF