Forum How do I...?

OpenLayers and prince

mrh
We are using OpenLayers 3.18.2, while including it in Prince we get TypeError: Value is not an object. Any help how to debug or work around such an bug?

Best Regards Martin
hallvord
Hi Martin, I'll investigate OpenLayers a bit and let you know if I find any workarounds.
I guess trying to convert some of the demos on http://openlayers.org/en/latest/examples/ to PDF will help me reproduce the problem - if not I'll have to ask you for a demo :)
-Hallvord

Announcement: repos for tests/utils

hallvord
So far, I've found a number of issues - some of them can be worked around with more or less effort, some are low-hanging fruits that the Prince developers probably want to fix.

In no particular order..

1. Uses document.write() to add scripts to the document. Prince does not support the legacy document.write() method, but I have a script which can sort of fake support for it.

2. It uses document.implementation.createDocument() - Prince throws an error for reasons I'm not sure of

3. It uses function.bind() and element.classList - neither are supported, both would be nice to have. Polyfills are available.

4. It runs some code that will throw if getAttribute('unset_attribute') returns null. Older DOM specifications mandated returning null - browsers however implemented returning the empty string, and specs eventually changed to match. (Yes, there's a bit of tail-wagging-dog going on here).

5. It uses requestAnimationFrame() - a cousin of setTimeout() which Prince does not support, and which makes much less sense for Prince given its static output. Prince should perhaps alias it to setTimeout() for now.

6. It appears to call setTimeout() recursively (well, requestAnimationFrame() which I've aliased..). This is not allowed by Prince, since it needs the script to actually finish so that the PDF can be rendered.

I might still find workarounds that would let OpenLayers actually render something.. We'll see.

Announcement: repos for tests/utils

Edited by hallvord