Stream a PDF to response

Hello...
I'm trying to stream a generated pdf file (jasperreports) to the response in an AbstractPortalComponent. The Code looks like follows...
public class HelloWorld extends AbstractPortalComponent
    JasperPrint jprint;
    JasperReport report;
    Map parameters;
    public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
try
  //input parameters
  parameters = new HashMap();                                                                     
  //path to report
  IResource res = request.getResource(IResource.SCRIPT, "reports/SAPPortalPDF.jasper");
  String path = res.getResourceInformation().getSource();
  //jasper print object
  jprint = JasperFillManager.fillReport(path, parameters, new JREmptyDataSource());
//output data in byte[]-object                                   
byte[] bytes = JasperExportManager.exportReportToPdf(jprint);
Writer w = response.getWriter();
//Content-Type setzen
PortalComponentContentType content = PortalComponentContentType.parse("application/pdf");               
response.setContentType(content);                                                            
response.write(response.getContentType().toString());                         
catch(Exception e)
               response.write(e.toString());
               response.write(e.getLocalizedMessage());
               response.write(e.getCause().toString());
It seems to work fine, but the data is not shown as a pdf file. I get all the characters displayed, which are in the byte array. So there are two possibilities... either the way I stream the data to the response is not correct or there are problemes concerning the mime-type. If I put out the mime-type of the response, it says "application/pdf". So this seems to be correct...
any ideas ????
Greets, Jochen

Hi
Hope the following will help. it's based on some code i writed some times ago.
If i remember, the idea is to write into a response object that is not the one given as a parameter.
regards
Guillaume
//output data in byte[]-object                                   
byte[] bytes = JasperExportManager.exportReportToPdf(jprint);
// write bytes to response stream
HttpServletResponse res = request.getServletResponse(true);
res.setContentType("application/pdf");
ServletOutputStream os = res.getOutputStream();
os.write(bytes);
os.close();

Similar Messages

  • When Streaming a PDF from a java servlet I get a grey screen on the Adobe Reader X plugin.

    I work on a webapp where we serve pdfs to clients by streaming via java servlets. Once we began to use Reader X we noticed that in IE the pdf will load Reader X with a grey screen. Chrome and firefox both work perfectly fine. If we use Adobe 9 it also works fine. We have no control over what our users use so any client side fix is not useful.
    We serve these pdfs to our user by opening a popup window to a url that streams the pdf directly to the response. We have noticed that if we have one popup window that has hit the grey screen - each new pdf in a popup works correctly - as long as the original grey screen is up, once all popups are closed the problem happends again. Refreshing the window with the grey screen will also show the pdf correctly.
    The problem is very similar to what is described here:
          http://forums.adobe.com/message/3335266
    However, we are not setting any caching headers - I have full control over what we can send and I have tried the suggestions - nothing works. Any ideas how to resolve this?

    You are prevented from Airplay mirroring certain things like DVD content as the material is usually protected so you get a checkerboard type display.  I think there is a theoretical risk that the Airplay stream could be intercepted and the protected video copied, albeitin lower quality.
    Apple may be being cautious or are required to do so with the DVD player app by movie studios/licensing authorities.  It makes no sense to the average consumer who is just trying to send their purchased DVD to the TV via the computer and AppleTV.
    Playback in something like VLC should work - not tried it myself but others have commented it doesn't have the restriction.

  • Acrobat Plugin should first open, then I want to stream a PDF

    Hi,
    when I stream a PDF (which is packaged in a ByteArrayOutputStream) to the Browser, the Acrobat Reader plugin opened not until the whole document
    is loaded. Is there a header, or anything else I have to set in my servlet to make sure that first the Acrobat plugin open and then the streaming starts. I need this behaviour, because if my user have a slow internet connection, he should have the chance to see the first page of the document during the rest of the document is still loaded in the backround.
    code:
    //document = PDF as ByteArrayOutputStream
    ServletOutputStream servletOut = response.getOutputStream();
    response.setContentType("application/pdf");
    response.setContentLength(document.size());
    document.writeTo(servletOut);
    response.flushBuffer();
    servletOut.flush();

    So that's my last post to this topic. For all, which have a similar problem, in future : It's not a Java problem, it's a problem of the PDF document. If you want the behaviour that the Acrobat Plugin opened first you have to make sure that you have a "Linearized PDF". I use iText to create a PDF, but it's a pity that iText don't support Linearization.

  • Stream a pdf file But want it to open in the browser automatically.

    Hi all,
    I have successfully stream a pdf file to the browser. But it ask the user to save the pdf. This is not what i intended to do. I would like the browser to automatically load the pdf file.
    How could i do that?
    I already added the setContentType to "application/pdf".
    Following is portion of my code:
    JasperReport jasperReport = (JasperReport)JRLoader.loadObject(preprintedForm);
              JasperPrint jasperPrint =JasperFillManager.fillReport(jasperReport, paramMap ,new JREmptyDataSource());
              response.setContentType("application/pdf");
              response.setHeader("Content-Disposition","attachment; filename=test.pdf");
              JRPdfExporter exporter = new JRPdfExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
              OutputStream ouputStream = response.getOutputStream();
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);
              try
                                     exporter.exportReport();
                                catch (JRException e)
                                     throw new ServletException(e);
                                finally
                                     if (ouputStream != null)
                                          try
                                               ouputStream.close();
                                          catch (IOException ex)
                                }Thanks in advance.

    Hi,
    Try this
    response.setHeader("Content-Disposition","inline; filename=test.pdf");
    and from the Jsp or HTML from where you are trying to access this use. window.location.href.
    Thanks and Regards,
    Harsha

  • Email notification - pdf form responses

    Is there a way for the pdf form responses to be atttached to the email notifications

    Hi,
    We don't currently support having the response data be attached to notification emails in PDF format. You can vote for this feature here:
    http://forums.adobe.com/ideas/1984
    Regards,
    Brian

  • PDF form response display

    I'm pretty new to all of this, but here is what I'm trying to do:
    I work at a research facility, and we are wanting to be able to send PDF surveys and forms to people, and then let them click on an http submit button that will send the data to a JEE5 servlet that will persist the data into our database, so we can reduce manual entry.
    We made a simple PDF form in LiveCycle Designer 8, and I have the servlet working fine, in that it takes all of the information and and persists it to the database. the only thing left is we want to give the user some sort of results to let them know that the data was entered, and if possible show them some generated content, such as a score or results or something. The "preview pdf" window in the LiveCycle Designer can read html fine, so it shows everything as we want. However, plain adobe reader cant, it pops up an error saying "Cannot handle content type: text/html". Now the data is entered into the database fine, but the user thinks there was an error.
    I found an opensource java api (iText) that can generate pdfs and send them out in the response stream. Normal browsers recognize it fine, saving a pdf that can then be opened in adobe reader, but adobe reader still thinks its a text/html stream, and the LiveCycle Designer thinks the new pdf has not pages.
    if I could get the reader to display some sort of results page, that would be great, but really I would be satisfied with as little as the pop up window saying "Data submitted successfully".

    Derrick,
    I don't think this is quite the right LiveCycle forum. This is for the Data
    Services part of LC, formerly known as the Flex Data Services. This is the
    back-end server that works with Flex client applications.
    I would try the Forms forums.
    Tom

  • PDF via Response.redirect or direct send does not work

    We have a web site which has a mobile section. We store some PDF's in a Database, retrieve them as needed and send the file to the client.
    IT works fine on a desktop/notebook, iPhone. but on Windows Phone it just opens the reader, "downloads the file and says "Tap to open", but won't. Saving the file and doing a Response.Redirect doesn't work either.Only saving the file and setting
    up a JavaScript href to do a location =
    Will this be fixed, or do I need the workaround.
    - Bill Surface Pro 128gb, Win 8 Pro 64 bit, MS Expression 4, Office 365 Home Premium, Visual Studio Professional 2013, SQL Server 2012 Express

    Thanks,
    Never a problem in when NOT using phone. Always a problem when using phone (PDF Reader or Adobe Reader. The code that send it look like this:
    Dim PDFContent() As Byte = objCmd.ExecuteScalar
    objCmd.Dispose()
    objConn.Dispose()
    Response.Clear()
    Response.ClearContent()
    Response.ClearHeaders()
    Response.ContentType = "application/pdf"
    Response.Charset = String.Empty
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache)
    Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName)
    Response.OutputStream.Write(PDFContent, 0, PDFContent.Length)
    Response.OutputStream.Flush()
    Response.OutputStream.Close()
    Response.End()
    - Bill using: Surface Pro 128gb, Win 8.1 Pro 64 bit, Office 365 Home Premium, Visual Studio Web Developer 2013, MS Expression 4, SQL Server 2012 Express

  • Help with PDF form responses

    Hey there!
    I have two issues with online form data collection and am completely stumped. It's a real struggle to find useful documentation for Acrobat forms!
    #1 - I have created a form uploaded it to Acrobat.com, and have been able to collect test form data. In the local responses portfolio, I'm able to use the 'Update' button to bring the latest form data into the portfolio. But I would like to have a colleague be responsible for monitoring the form data and we're running into problems. He's able to open the portfolio and has full access, however the 'Update' button is greyed out so he is unable to bring in new form data. We've already updated his 'Acrobat.com' username/password in Acrobat preferences to match mine, but still no luck. Any help?
    #2 - Some computers are having issues with electronic submission. My best guess is that this is to do with Acrobat versions, as the issues all seem to come from computers where the form is completed using Acrobat Reader 8. The form was created with Pro 9, and form submission works for both Pro 9 and also Reader 9. Is there something I can do here? (And yes I know that it's a free upgrade to 9, but 8 is still in the official build for our organisation and I don't really have time to wait for them to complete an upgrade!)
    Thanks in advance for any help you can give.
    Jarrod

    Hello Paul,
    Thank you for your reply.
    I use Ipower for my hosting.  I see they use sendmail and the path on the server is - /usr/sbin/sendmail.  Would this work?
    The way I would like this to work would be:
    1) I e-mail the PDF form to the client
    2) Client opens and fills in the form
    3) They hit submit and the form information eventually gets e-mailed to my business e-mail
    I chose to use the HTTP method instead of e-mail because the PDF form says it can not be saved and if the client uses an internet beased e-mail like Yahoo it gets kind of messy.
    But, does the HTTP delivery method make it more difficult since this is not embedded in a website?
    Sorry, I did not realise this would be as involved as it is.  Your help would be greatly appreciated.

  • PDF form responses coming back uneditable

    I have created a lengthy form in InDesign (v.9.2) for a client, which I have exported to PDF then extended in Acrobat Pro (11.0.06) under File > Save as Other > Reader Extended PDF > Enable More Tools.
    This makes the form savable (if that's a real word.) The form is sent to their clients, which they fill in, save and send back by email.
    When the form returns, my client wants to be able to edit some of the responses further (mainly checkboxes) then re-save but the Save option in file menu is greyed out. The purple bar says 'Click "Sign" to fill out and send this form etc...'.  If you try to 'Save as > PDF', it will only save a blank copy of the form.
    I assume the client's clients use Reader for the input, and the client definitely uses just Reader.
    I have suggested using an original copy and checking all the checkboxes that the client specified, but they are getting a lot of these forms back and that would be too time-consuming.
    Is there a way round this without them having to upgrade to Acrobat Pro? That would make them distinctly unhappy. Though if the community decreed that was the only option, it could be considered.
    Any help greatly appreciated!

    The form that you sent is not Reader-enabled, so that would be the reason it's not savable with Reader versions prior to 11. Reader 11 is able to save non-enabled forms, so I would your clients could use it, but this doesn't help unless all of the people they distribute it to use Reader 11 as well.
    You should not provide clients with Reader-enabled forms, except for testing purposes. If they will be distributing a form for the purpose of collecting data and need Reader-enabled forms, they need to enable them with their own version of Acrobat. This is an Acrobat licensing issue.
    The Acrobat license also limits the licensee from using data from no more than 500 instances (including hardcopies) of an enabled form if the form has been made available to more than 500 recipients. A way to avoid this limitation is to use Adobe's FormsCentral service, which allows PDF forms to securely submit the form data, which is collected by a server. A team or people can have access to the data and export any response as a filled-in PDF, which can be  further edited as they want. They could instead set up their own web server to collect submissions, but this requires some expertise and more expense, particularly if security is needed. A form can also be set up to submit just the form data by email, which also avoids the licensing limitations, but since email is not secure and notoriously unreliable, it should not be considered for anything of much importance.
    Note that Acrobat Standard is sufficient for enabling the form for use with Reader.
    You should also make them aware of the Preview problem that I mentioned earlier. If they encounter a form that has been corrupted by Preview, they should export the form data and import it into the original blank form. They will need Acrobat for this.

  • Streaming Large Files to Response OutputStream consumes plenty of memory

    When we write large file's (> 100 MB) binary content to the Servlet Response OutputStream using the write method, it consumes plenty of Heap Memory on the server (Weblogic 7). The Heap does'nt come down after
    writing to the outputstream, it stays high for quite a long time, infact it comes down only we access the same page again. Is there a way to get this optimized?
    TIA.

    The servlet container will buffer your output, so that it knows how much of it there is, so that it can set the Content-Length header, so that the recipient knows where the payload ends.
    I don't know about Weblogic, but in Tomcat there are AFAIK two ways to get genuine streaming instead of buffering: set the Content-Length header before writing any output (and if you know the content length in advance). Or use chunked encoding (set the "Transfer-Encoding: chunked" header, google for it.)
    I don't know if it works, but if those two don't do it for you, you could also try forcing the reply to be HTTP/1.0 instead of HTTP/1.1, or disable keep-alive ("Connection: close"). HTTP/1.0 (which doesn't have keep-alive) and no-keep-alive might not need the Content-Length header because closing the socket will give an EOF to the recipient, so it knows where the payload ends.

  • Viewing and retrieving PDF form responses problem

    Yesterday there were 2 submissions of our driver application form. One was my test and the other was from an actual applicant. Both were clearly displayed under the View Responses tab and I could click on either one and save as a PDF. Today I have 7 new responses. When I click on the number under Total I get a series of horizontal cells: Time Submitted  First Name Middle Name, etc. I am not seeing the individual submissions as I did yesterday. What's the fix.

    Hi,
    This FAQ may be useful for the missing responses, http://forums.adobe.com/docs/DOC-4071.  If still not solve the issue, you can share your forms with me, I'll try to help you find out what is the problem.  You can share the form to my email, [email protected]
    Regards,
    Perry

  • Streaming a PDF Presentation form One iPad to 5 other iPads

    Can I stream a presentation I'm giving from my iPad to the other attendees (5 or 6) in a meeting? All attendees will be be in the same room.  Will they need to be on the same network, or can I achieve this using Bloetooth?
    The presentation is in PDF format, and I would usually use Good Reader to present on a single iPad on a 1 to 1 basis.
    Many thanks

    What not possible is to replicate directly and simply what is on your ipad screen to multiple devices.
    Work-arounds
    -- You could get an ipad app that share whatever it wished to other ipads.
    You could look at teamviewer.
    http://www.teamviewer.com/en/index.aspx
    -- You can replicate what on your screen to a tv or another computer.  The other computer can share it's screen how ever it wishes. 
    -- You could put the pdf file on the web or an internal web site.  Could put the file on some wifi web server you bring along with you.

  • Printing actual PDF with responses?

    I created a registration form for a youth sports program, I can see the responses under "view responses" and "summary report" but I also need to have access to the actual pdf completed so it can be printed.  What do i need to do to ensure i get the completed packet sent to me?  Is this an allowable feature?
    Thanks

    Hi;
    In a paid level subscription you have access to "Download Response as PDF Form" from the View Respones tab which will download a PDF that looks like the original form filled out.
    I am guessing that you are distributing a PDF as opposed to a web/HTML form, is that correct?  If you are distributing a PDF and you want the actual filled out PDF to be returned via Email as opposed to having to download from the Response table you could add an additional Submit method to the Submit button by editing the PDF in Adobe Acrobat and adding the Email Submit method so the form, when Submit is clicked would both submit the data to FormsCentral to be available on the View Responses tab and would also open an email in the users default email client attaching the PDF and assuming the user sends the email you would receive it back.  If this is what you are looking for let me know and I can point you to some instructions.
    Thanks,
    Josh

  • PDF Submission Responses

    How can I print the form submission date on the PDF Response Form?

    Hi,
    Sorry, when you export a response as PDF form, the date-submitted-column is not exported. 
    Thanks,
    Lucia

  • Auto-create PDFs from responses?

    Does there exist a way to automate the process of turning separate responses into a PDF? As a pay-per-month customer you have the possibility to right-click each and every row in the response-section and have to ability to export them into a formated PDF-file. Having several hundred responses, is there a way to automate this process and potentially delete all the responses that has been converted into a PDF?
    Would this be possible to automate using a third-party program?

    That's too bad, but thank you for the answer. Is this something that might be implemented in the future or do I have to look around for other ways to this exact thing?

Maybe you are looking for

  • Payment block

    Hi All We have 2 vendors say Vendor X & Y. I have a PO raised say for 10 qty and GR & IV done for 5 qty, now i am getting Payment Block for Vendor X and it is not getting blocked for Vendor Y, i checked the Vendor master for both X and Y is not havin

  • ITunes will not open on Mac

    When I open iTunes the following message appears, "iTunes quit unexpectedly", then it asks to reopen and when I do the same error code appears.

  • About FM CM_F_INITIALIZE

    What is this fm used for? any document about it?

  • MSCS Migration after upgrade

    Hi We are in the process of upgrading from 4.6C to 7.0 EHP1. As part of this process we will be moving to new hardware. It it possible to migrate onto the new hardware, upgrade the system and then create an MSCM cluster? We do not want to do another

  • Connectiing Java Web Service to Power Builder application

    Hello I have to develop an application where i must connect a Power Builder application to java web service.Can any one help me in this matter...My client wants from Power Builder application i should call a .exe..means the parameter from the power b