diplay pdf files

96 views
Skip to first unread message

mauricio

unread,
Nov 16, 2007, 9:07:17 PM11/16/07
to Google Web Toolkit
hi guys,

i am new to gwt and hope to get better,
im bulding a web app and i need to display pdf files, i was wondering
if its possible to open a new browser tab and displaying a pdf file in
it,

what should i use?
thank you,

Reinier Zwitserloot

unread,
Nov 17, 2007, 5:58:23 AM11/17/07
to Google Web Toolkit
That only works if your user has a PDF plugin installed.

Assuming they do, just create a standard link

<a href="/somePdf.pdf" target="_blank">Click here to see a PDF of all
this</a>

As long as your webserver returns the right mimetype (application/pdf
or whatever it is), that'll work fine, and for those without a PDF
plugin, it'll pop up a download dialog.

Detecting the existence of a PDF plugin, or sending the user to an
appropriate download link, is entirely OS *AND* browser dependent and
will take you many days of pain. If you want to go there, that's fine,
but you may have more success by asking on other newsgroups; at that
point it's no longer GWT related.

mauricio

unread,
Nov 17, 2007, 11:31:38 AM11/17/07
to Google Web Toolkit
hi reinier, and thank you for the quick reply =).
doing some research, i found out that java has some libraries for
opening pdf files inside a java app.

i have a couple of questions:

is it possible to use these java libraries in an gwt application? i
mean, can i use these libraries from the client package to open and
display a pdf file ?.

what would you guys use with gwt in order to show a pdf file?

thanks again,
its great to have this group , im learning a lot just by reading other
people problems.

Martin Gorostegui

unread,
Nov 17, 2007, 12:39:16 PM11/17/07
to Google-We...@googlegroups.com
Mauricio,
 
I'm not sure which of the following two issues you need to solve (maybe both):
1) How to show a pdf file in a browser
2) How to generate a pdf file from java

If you just need to show in the browser an existing pdf file what Reinier told you should be enough. But if what you need is to create a pdf file on the fly and show that in the browser (for example: a user clicks a button in the browser and then a pdf file is created on the fly out of some info from a database) then here is when you need one of those java pdf libraries you mentioned like iText to generate a pdf file from java. If the latest is your case you will need to point the href to an standard java httpServlet and in that servlet generate the pdf and write it to your response setting the correct mime type.
 
Finally, when using GWT you can use any java framework you want on the server side (hibernate, spring, struts, seam or whatever). But if you are in the client side you can't. There you can only use GWT widgets out of the box or any other javascript framework you want (yui, mootools, scriptaculous, ext, etc) through JSNI
 
I Hope this helps.
 
Martin

mauricio

unread,
Nov 17, 2007, 2:18:16 PM11/17/07
to Google Web Toolkit
it gave me a better view of everything, thanks a lot martin. I will
try to explain myself better

my app has search area, where the user writes a query and through a
RPC service collects all the results that are alike. What i store in
the database are papers(articles,thesis) names. These papers are
associated with a pdf file which is the paper itself.

I put the results of the query in a ListBox. When the user clicks on
the result he/she wants, i need to display the pdf file associated to
the result. So the user can browse the paper/article/thesis

thank you for responding,
mauricio



Peter Blazejewicz

unread,
Nov 17, 2007, 3:35:09 PM11/17/07
to Google Web Toolkit
hi Mauricion,

on results (assuming you have already pdf file URI path on client
side) either:
#1
add <embed><object> tags into your dom, e.g via HTMLPanel or via DOM
object methods
or:
#2
add Frame (which is wrapper for html iFrame) to display your pdf, it
accepts URL/UIR paths and on most browsers PDF will be displayed in
frame without downloading it,

regards,
Peter

Reinier Zwitserloot

unread,
Nov 17, 2007, 8:27:40 PM11/17/07
to Google Web Toolkit
mauricio: GWT isn't java. It just looks like it a little. You most
extremely very definitely cannot use a java PDF viewer in GWT, I
guarantee you it won't work. Displaying a PDF file without a pdf
plugin on the browser is -impossible-. Get over it. If we're talking
about academians, they almost always have PDF plugins installed, so
it's a moot point.

Heed Martin's advice on how to use iframes to show the PDF while still
leaving room for your interface, if that's what you need.

mauricio

unread,
Nov 18, 2007, 12:02:37 PM11/18/07
to Google Web Toolkit


thank you guys for your answers,
it really apreciate it
mauricio

Serega....@gmail.com

unread,
Nov 19, 2007, 1:36:43 AM11/19/07
to Google Web Toolkit
you can generate PDF-file on the server-side, if you need.
Use JasperReports for this.
Ofcourse, without PDF-plugin or some PDF viewer / Adobe Acrobat user
won't see any PDF. Just download link with file.

mauricio

unread,
Nov 19, 2007, 9:12:20 AM11/19/07
to Google Web Toolkit
thanks Serega, what i needed was to show a pdf file that is on the
server. (although i think im gonna need JasperReports later on, so
thanks!)
Following the advises, what i did was to create a new frame in the
gui, and showing the pdf.

Maybe someone has the same question , so i post my(simple) solution
here:

i created a new frame like this
final Frame frame=new Frame("http://startpage.com");
i got the pdf filename using a rpc service and put the result in the
frame , the pdf showed with no problems

public void onSuccess(Object result) {

String r=(String)result;
frame.setUrl("http://server/directory/"+r);
}

thanks for all the posts,
regards,
mauricio

obesga

unread,
Nov 19, 2007, 11:04:44 AM11/19/07
to Google Web Toolkit
.. maybe there's another way, maybe more elegant maybe trickier.
( I suggest this because it's also interesting to me )

You can't show a PDF directly inside an HTML page. Nor for GWT nor for
other Javascript libraries.
You must use one of them
- a PDF plug-in on client browser
- a Flash movie as PDF viewer ( http://www.scribd.com/ ) but not open
soruce :(
- convert online PDF to HTML and deploy it onto a RichTextArea wigdet
or something like that.

How do you see it ? Sure, it'll require more research from you

Oskarloko

doopa

unread,
Nov 20, 2007, 5:03:05 AM11/20/07
to Google Web Toolkit
Have you considered using namazu for the search. It indexs all your
pdfs and then allows you to create a web interface to return search
results. It should just require installing and not having to write any
complicated code.

http://www.namazu.org/

Sounds like it does what you are looking for?

On Nov 17, 8:18 pm, mauricio <mauricio.vela...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages