title: Printing in Openlayers 3 (pdf)
body: <p>I have made a printing tools for openlayers 3 which prints in PDF format. Here is my code to print in pdf.</p>
  
  <pre><code>var dims = {
    a0: [1189, 841],
    a1: [841, 594],
    a2: [594, 420],
    a3: [420, 297],
    a4: [297, 210],
    a5: [210, 148]
    };
  
    var exportElement = document.getElementById('export-pdf');
  
    exportElement.addEventListener('click', function(e) {
  
    if (exportElement.className.indexOf('disabled') &gt; -1) {
      return;
    }
    exportElement.className += ' disabled';
  
    var format = document.getElementById('format').value;
    var resolution = document.getElementById('resolution').value;
    var buttonLabelElement = document.getElementById('button-label');
    var label = buttonLabelElement.innerText;
    var dim = dims[format];
    var width = Math.round(dim[0] * resolution / 25.4);
    var height = Math.round(dim[1] * resolution / 25.4);
    var size = /** @type {ol.Size} */ (map.getSize());
    var extent = map.getView().calculateExtent(size);
  
    map.once('postcompose', function(event) {
      //var tileQueue = map.getTileQueue();
  
      // To prevent potential unexpected division-by-zero
      // behaviour, tileTotalCount must be larger than 0.
  
      //var tileTotalCount = tileQueue.getCount() || 1;
      var interval;
      interval = setInterval(function() {
        //var tileCount = tileQueue.getCount();
        //var ratio = 1 - tileCount / tileTotalCount;
        //buttonLabelElement.innerText = ' ' + (100 * ratio).toFixed(1) + '%';
        //if (ratio == 1 &amp;&amp; !tileQueue.getTilesLoading()) {
          clearInterval(interval);
          buttonLabelElement.innerText = label;
          var canvas = event.context.canvas;
          var data = canvas.toDataURL('image/jpeg');
          var pdf = new jsPDF('landscape', undefined, format);
          pdf.addImage(data, 'JPEG', 0, 0, dim[0], dim[1]);
          pdf.save('map.pdf');
          map.setSize(size);
          map.getView().fitExtent(extent, size);
          map.renderSync();
          exportElement.className =
              exportElement.className.replace(' disabled', '');
       // }
      }, 100);
    });
  
    map.setSize([width, height]);
    map.getView().fitExtent(extent, /** @type {ol.Size} */ (map.getSize()));
    map.renderSync();
  
  }, false);
  </code></pre>
  
  <p>I can print in PDF when I have only OSM Layer but when I add local layers from my geoserver I can't print anything and the whole application is freezed.</p>
  
  <p>Can anyone tell me what am I doing wrong here?</p>
  
  <p>I am using jspdf to print pdf.</p>
  
  <p>AJ</p>