Saving screen state

If you want to save screen state, for example of the current dizmoViewer or a dizmo, there are two API calls to help you with that. Firstly, takeScreenshot, which returns image data. Secondly, 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 any 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 the bitmap. The image data is jpeg/base-64.

Example:

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

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);

In addition you can define the resulting PDF resolution by providing rheight and rwidth, which should be a multiple of the height and width.

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