代码之家  ›  专栏  ›  技术社区  ›  jbassking10

打印整个Cytoscape.js HTML5画布。不仅仅是可见部分

  •  0
  • jbassking10  · 技术社区  · 7 年前

    我所能得到的最好的只是看得见的部分。

    <script>
        function printCanvas() {
    
            var padding = 10; // padding around found objects
            var canvases = $('canvas');
            var context = canvases[2].getContext('2d');
            // find borders of a rectange covering all objects
    
            var newWidth = canvases[2].width;
            var newHeight = canvases[2].height;
    
            // create a new canvas
            var newcanvas = document.createElement('canvas');
            newcanvas.width = newWidth + 2 * padding;
            newcanvas.height = newHeight + 2 * padding;
            var newcontext = newcanvas.getContext('2d');
    
            // copy data to the new canvas
            newcontext.putImageData(context.getImageData(0, 0, newWidth, newHeight), padding, padding);
    
            popup = window.open();
            popup.document.body.innerHTML = "<img src='" + newcanvas.toDataURL('png') + "' />";
    
            popup.print();
        }
    </script>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   user3140972    7 年前

    cy.png({full: true})
    

    有关更多详细信息,请参阅 documentation