1
votes

I am trying to get a PDF in GWT from client side I am using jspdf for that

Here is my code in GWT client side onModuleLoad

    public void onModuleLoad() {

    Button btn = new Button("click");
    RootPanel.get().add(btn);
    btn.addClickHandler(new ClickHandler(){

        @Override
        public void onClick(ClickEvent event) {
            callJs();
        }});

}

public native void callJs() /*-{
    var doc = new jsPDF();
    doc.text(20, 20, 'Hello world.');
    doc.save('Test.pdf');

}-*/;

}

In my project.html file, I added these in my header

          <script type="text/javascript" src="examples/js/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="jspdf.js"></script>
<script type="text/javascript" src="jspdf.plugin.standard_fonts_metrics.js"></script>
<script type="text/javascript" src="jspdf.plugin.split_text_to_size.js"></script>
<script type="text/javascript" src="jspdf.plugin.from_html.js"></script>
<script type="text/javascript" src="FileSaver.js"></script>

I have downloaded the jspdf and put inside my war folder

Now when i Click on the button I get the error in console:

                 jsPDF is not defined

Please suggest what I am missing ..

NOTE: If i use the same above code within my project.html page It works fine but it doesnt work when i put the same code inside my JSNI method

1

1 Answers

0
votes

It seems that <script type="text/javascript" src="jspdf.js"></script> has not been loaded by your browser (404 ?).

Be sure that the jspdf.js file is at the root of you .war (with your project.html)