GWT:How to generate pdf save/open window?

1,070 views
Skip to first unread message

Sanjay Jain

unread,
Dec 7, 2011, 5:25:17 AM12/7/11
to google-we...@googlegroups.com

I am using GWT2.4 version in my application.In this I application I have created Form using GWT control (like textbox,textaera).

I have also created preview of form.In that preview I have button of pdf generation. Now I want to create behavior to deal with pdf link same as browsers(Mozilla/chrome). For example in Mozilla on click of pdf link it asks for either save or open in a pop up window.

While debugging I found a jar name iText which can be used to create pdf, I want to implement browsers behavior in this also. Please help me out. Thanks in advance.

Kanagaraj M

unread,
Dec 7, 2011, 5:48:38 AM12/7/11
to google-we...@googlegroups.com
generate PDF in server side and save it.
Write an RPC to get the file location.
In the client use HyperLink to download the file.

Ed

unread,
Dec 7, 2011, 10:26:58 AM12/7/11
to Google Web Toolkit
Use the FormPanel.submit() for this.
I do exactly what you want: I use iText in the background and use a
servlet that generates the pdf.
The FormPanel.submit() is used to submit the required info to the
servlet.
The submit() works like a Form submit.
I build a FormBuilder class that makes things a bit easier.

I included it below:
----

public final class FormBuilder {

private FormPanel formPanel;

public FormBuilder() {
}

public FormBuilder(final Method method, final String action, final
String target) {
setMethod(method);
setAction(action);
setTarget(target);
}

public void submit() {
try {
RootPanel.get().add(getEnsureFormPanel());
getEnsureFormPanel().submit();
}
finally {
RootPanel.get().remove(getEnsureFormPanel());
}
}

public void setAcceptedCharset(final String charsets) {
getEnsureFormPanel().getElement().setAttribute("accept-charset",
charsets);
}

public void setAction(final String action) {
getEnsureFormPanel().setAction(action);
}

public void setMethod(final Method method) {
getEnsureFormPanel().setMethod(method.getValue());
}

public void setTarget(final String target) {
getEnsureFormPanel().getElement().setAttribute("target", target);
}

public void addValue(final String name, final String value) {
final InputElement el = Document.get().createTextInputElement();
getEnsureFormPanel().getElement().appendChild(el);
el.setName(name);
el.setValue(value);
}

public void removeAllValues() {
final int size = getEnsureFormPanel().getElement().getChildCount();
if (size > 0) {
for (int i = size - 1; i >= 0; i--) {
getEnsureFormPanel().getElement().getChild(i).removeFromParent();
}
}
}

//
//
private FormPanel getEnsureFormPanel() {
if (this.formPanel == null) {
this.formPanel = new FormPanel();
this.formPanel.getElement().getStyle().setDisplay(Display.NONE);
}
return this.formPanel;
}

/**
*/
public enum Method {
POST("POST"), GET("GET");

private final String value;

private Method(final String methodName) {
this.value = methodName;
}

public String getValue() {
return this.value;
}
}

shipra dhooper

unread,
Dec 7, 2011, 8:34:49 AM12/7/11
to google-we...@googlegroups.com


if u want to create pdf document then u can directly create pdf without using iText jar ...u should use apache pdf jar file on serverside code.u can also create by using amazon web services.


thanks 

 

Reply all
Reply to author
Forward
0 new messages