1

My OpenLayers/MapFish print tool fails approximately half the time when attempting to print WMS with some vectors, and always fails when trying to print WFS layers.

After the OL map first loads I can successfully print the map page to a pdf with base layers and WMS layers. I also have some vector layers in the map for users to dynamically create points, lines, and polygons in. Sometimes I can add features to one or two of the drawing layers and successfully print other times I can draw in one of the layers and it will fail. If I attempt to print the same map more than three times the pdf generation fails. Also, if I try to print any maps with WFS layers the print fails.

When using Google Chrome I get an ERR_EMPTY_RESPONSE page after the print fails, but the console does not show any errors other than the empty response.

In FireFox I get a "The Connection Was Reset" page when the print fails and FireBug doesn't show any anything. Literally nothing. No errors or messages at all.

I am using the following GeoExt code to generate the print;

// The PrintProvider that connects us to the print service
var printProvider = new GeoExt.data.PrintProvider({
    method: "GET", // "POST" recommended for production use
    capabilities: printCapabilities,
    customParams: {
        mapTitle: "This is a map!",
        comment: "This is a comment!",
        defScale: newScale
    }
});

printPage = new GeoExt.data.PrintPage ({
    printProvider: printProvider
});

printPage.fit(mapPanel, true);
printProvider.print(mapPanel, printPage)

I am using GeoServer v2.8.1 with the GeoServer Printing-Plugin v2.8.1, Openlayers v2.12, Ext v3.4, and GeoExt v1.1.

Any suggestions on why the print fails?

1

I found that the issue was that my "GET" requests exceeded the maximum string length. I had to switch to using a "POST" request which then threw an error due to violating the cross origin rule.

The solution to geoserver/mapfish printing using the POST option can be found here;

WMS server with CORS enabled?

Simply paste this code at the beginning of your Javascript:

(function() {
    var cors_api_host = 'cors-anywhere.herokuapp.com';
    var cors_api_url = 'https://' + cors_api_host + '/';
    var slice = [].slice;
    var origin = window.location.protocol + '//' + window.location.host;
    var open = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function() {
        var args = slice.call(arguments);
        var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
        if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
            targetOrigin[1] !== cors_api_host) {
            args[1] = cors_api_url + args[1];
        }
        return open.apply(this, args);
    };
})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.