Help with Byte Array to PDF

374 views
Skip to first unread message

koko

unread,
Feb 16, 2009, 7:05:56 PM2/16/09
to Google Web Toolkit
Hi lads:

I have a problem with converting byte array to pdf file, this will be
processing in the client side.
in my project the PDF file was constructed by the content in the
textarea which user type in, after user press PDF button it will
trigger RPC call and get byte array response from server side,
actually it was a PDF file, I want to shown it to the user and let
them download.
Now after RPC byte array was stored in variable called result, what
should I do next? Can anyone help me please..

Ian Petersen

unread,
Feb 16, 2009, 7:34:18 PM2/16/09
to Google-We...@googlegroups.com

That approach won't work. To serve a PDF to the user, write a servlet
that spits out the PDF, annotated with the appropriate Content-Type
header. When the user presses the PDF button, either open a new
window or display an iframe and, in either case, set the URL for the
new window to be the address of your PDF-generating servlet. If you
want to prompt the user to save the PDF to disk rather than displaying
it the browser, set the Content-Disposition header appropriately. (I
forget what value you need there, but you should be able to find it
with a good search engine.)

Ian

koko

unread,
Feb 16, 2009, 7:54:15 PM2/16/09
to Google Web Toolkit
Thanks Ian, I had tried this way, but what how should I post my data
in textarea to the server side? I encounter like SOP errors, for my
tomcat runs on port 8080, while GWT on 8888, I also tried to set in
the same port 8888, won't work, can you teach me how to configure or
set in detail, I am doing this for my project, thanks for a lot!
Regards.


On 2月17日, 上午12时34分, Ian Petersen <ispet...@gmail.com> wrote:

ginger_ninja

unread,
Feb 17, 2009, 4:53:49 AM2/17/09
to Google Web Toolkit
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

koko

unread,
Feb 17, 2009, 11:37:20 AM2/17/09
to Google Web Toolkit
Hi Ginger:
Thanks a lot for your kind help :)
Yeah that's what I really want to do.
but there is still a problem, now I am just in development period, how
can I write a servlet that can share the session with GWT project ?
For now they are using different port and probably different tomcat?
Also my textara contains some of the pictures, can I get them in the
PDF as well?
when I get the content of textarea I just use textarea.gettext();

Thanks a lot for your help!

Regards.

koko

unread,
Feb 17, 2009, 8:30:56 PM2/17/09
to Google Web Toolkit
Can anyone help?
Message has been deleted

Carl Pritchett

unread,
Apr 7, 2009, 12:24:09 AM4/7/09
to Google Web Toolkit
Hi,

You need to not use the embedded tomcat server and point the hosted
mode to your real server (e.g. localhost:8080).

You do this using the -noserver option passed to the GWTShell.

See this reference:
http://code.google.com/docreader/#p=google-web-toolkit-doc-1-5&s=google-web-toolkit-doc-1-5&t=FAQ_HostedModeNoServer

Regards,
Carl.
Reply all
Reply to author
Forward
0 new messages