Hi koko,
Ian is right, I encountered this exact same problem on the project I'm
currently working on. In your case it sounds like you want to send
some data from a textarea over to the server and put some dynamic
content in the PDF, is that right?
The best solution I've found is to separate what you're doing into two
stages. The first stage I call the preparation stage. The preparation
stage involves preparing the data create the PDF from and storing it
somewhere temporarily, in my case I used the user's session. Once the
data is prepared and stored away you can safely complete the RPC
call.
The second stage is what I call the generation or retrieval stage.
This involves actually generating and retrieving the PDF using the
data that was previously stored in the session. This stage is
triggered in the onSuccess callback method of the previous RPC call.
Really all that needs to be done inside the onSuccess method is to
open a new window and point the window.location property to the URL of
the servlet you're going to create. Using Ian's technique you can
write a simple servlet like he said, generate the PDF using the stored
data, and set the content type to application/pdf before writing the
byte stream to the servlet's output stream (you can find this inside
the HttpResponse object). This will tell the browser that a PDF is
coming it's way and it will automatically handle it appropriately.
Dave