Reputation: 553
What is the best way to download a pdf file using GWT client ? Should I invoke a normal servlet to do that ? or is there a different preferred approach to handle this problem ?
I am new to GWT, so if some sample code would be of great help.
Thanks Deep
Upvotes: 8
Views: 13214
Reputation: 15709
You can implement a Servlet download the file OR you can do that using Data URIs:
Window.open
to open a file save dialog passing the formatted DataURI.Take a look at this reference, to understand the Data URI usage:
Upvotes: 1
Reputation: 3599
the best way is to navigate your browser to that file
on download button add click handler:
Button downloadButton = new Button("Download");
downloadButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.open("url_of_file", "download File", "");
}
});
Upvotes: 0
Reputation: 8551
Try it with GET...
Window.open(GWT.getHostPageBaseURL() + "FileRepository/doDownload?docId=" + dokument.getId(), "", "");
Upvotes: 4