Vaadin Page Source

I want to export vaadin page as pdf. For this purpose,first I try to get vaadin page source code as HTML,then use some pdf Export API.
how can I get vaadin page source code as HTML?

// Panel to display HTML of dumped content
final Panel panel = new Panel("Dumped Content");
panel.setWidth("640px");
panel.setHeight("400px");
final Label dumpContent = new Label();
panel.setContent(dumpContent);
layout.addComponent(panel);

// Handle dump content from server-side
Page.getCurrent().getJavaScript().addFunction("dumpcontent",
    new JavaScriptFunction() {
        @Override
        public void call(JSONArray arguments)
             throws JSONException {
            // Display the dumped HTML as text
            dumpContent.setValue(arguments.getString(0));
    }
});

// Button for dumping the content
Button takeadump = new Button("Take a Dump");
takeadump.addClickListener(new ClickListener() {
    @Override
    public void buttonClick(ClickEvent event) {
        Page.getCurrent().getJavaScript().execute(
"dumpcontent(document.documentElement.innerHTML)");
    }
});
layout.addComponent(takeadump);

Thanks, Marko, for the post, which worked for me in Vaadin 7.7.6. using

import elemental.json.JsonArray;
import elemental.json.JsonException