Try the Geoserver print module
http://docs.geoserver.org/latest/en/user/extensions/printing/index.html
First you have to download the print module (be sure to choose the correct version!)
then unzip the downloaded content and put the files to your /WEB-INF/lib/ folder of your Geoserver installation.
Restart Geoserver and check if the config file was generated in YOUR_GEOSERVER_DATA_DIR/printing/config.yaml
If the printing module was installed properly you should be able to retrieve informations from your Geoserver about your print module:
http://localhost:8080/geoserver/pdf/info.json
This response you can use to set a variable, lets call it "printCapabilities"
http://localhost:8080/geoserver/pdf/info.json?var=printCapabilities
and use this variable then in combination with GeoExt (http://geoext.org):
printProvider = new GeoExt.data.PrintProvider({
url: "localhost:8080/geoserver/pdf",
method: "POST", // "POST" recommended for production use
capabilities: printCapabilities, // from the info.json script in the html
customParams: {
mapTitle: "Einzugsgebiete Liechtenstein",
//comment: "nix"
dpi: 300
}
});
//Drucken/PDF (Button)
btnPrint = new Ext.Button({
iconCls: 'print',
layout: 'fit',
tooltip: 'Drucken',
handler: function() {
var printDialog = new Ext.Window({
title: 'Druckvorschau',
autoHeight: true,
width: 300,
items: [
new GeoExt.PrintMapPanel({
sourceMap: mappanel,
printProvider: printProvider
/* {
capabilities: printCapabilities
} */
})],
bbar: [{
text: "Create PDF",
handler: function() {
printDialog.items.get(0).print();
}
}]
});
printDialog.show();
}
});
Here you will find several GeoExt-examples with printing functionality:
http://geoext.org/examples.html
or have a look at the newer Version GeoExt2:
http://geoext.github.io/geoext2/examples/printpreview/print-preview.html