Saving Screen State

If you want to save screen state e.g of the current dizmoViewer or a dizmo, there are two new API calls to help you with that: takeScreenshot, which returns image data, and addPageToPDF, which creates (multiple page) PDFs

viewer.takeScreenshot

viewer.takeScreenshot({
    geometry: {
        x: <x coordinate of the center of the image>,
        y: <y coordinate of the center of the image>,
        height: <height of the rectangle to be provided as a bitmap>,
        width: <width of the rectangle to be provided as a bitmap>,
        angle: <the viewer rotation to be used when capturing the rectangle to be provided as a bitmap>,
        zoom: <the viewer zoom level to be used when capturing the rectangle to be provided as a bitmap>
    },
    bitmap: {
        height: <the height of the bitmap that is produced from the screenshot>,
        width: <the width of the bitmap that is produced from the screenshot>
    }
    },
    function(image) { // do something with the image data }
);

Several things can be omitted. The call can be called with just a callback e.g viewer.takeScreenshot({}, function(image) {}) or with the full configuration (each bitmap and geometry can be omitted if not needed)

viewer.takeScreenshot({
    bitmap: {
        height: 200,
        width: 200
    },
    function(image) {}
});
viewer.takeScreenshot({
    geometry: {
        x: 20,
        y: 20,
        height: 200,
        width: 200,
        angle: 230,
        zoom: 4
    },
    function(image) {}
});

The call assumes default values if geometry or bitmap is omitted. However, if geometry, for example, is supplied, all the values in the geometry object have to be set. The same goes for bitmap. The image data is jpeg/base-64

Example:

viewer.takeScreenshot({}, function(image){
    document.getElementById('myimg').src='data:image/jpeg;base64,'+image;
});

Note: Sticky dizmos are not supported, which means they are not visible in the saved image.

viewer.addPageToPDF

If you want to save the screen state of the dizmoViewer or a dizmo to a PDF, you can now create PDF-Files, and add (multiple) Pages to it.

Example:

var pdf = viewer.openPDF("test.pdf");
viewer.addPageToPDF(pdf, {
    x: viewer.getAttribute("geometry/x"),
    y: viewer.getAttribute("geometry/y"),
    height: viewer.getAttribute("geometry/windowheight"),
    width: viewer.getAttribute("geometry/windowwidth"),
    zoom: viewer.getAttribute("geometry/zoom"),
    angle: viewer.getAttribute("geometry/angle")});
viewer.closePDF(pdf);

The resulting PDF File is saved on your desktop (Mac & Windows) or in your home directory (Linux)