使用JSPDF进行多个画布的屏幕截图

发布于 2025-01-19 07:05:02 字数 1227 浏览 1 评论 0原文

希望我想做的事情的解决方案很简单。我使用以下代码成功将画布打印为 pdf:

<!-- Start PDF Script -->
  <script type="text/javascript">
        function getPDFFileButton () {
            return html2canvas($('canvas'), {
                background: "#ffffff",
                onrendered: function(canvas) {
                    var myImage = canvas.toDataURL("image/png,1.0");
                    // Adjust width and height
                    var imgWidth = (canvas.width * 20) / 240;
                    var imgHeight = (canvas.height * 20) / 240; 
                    // jspdf changes
                    var pdf = new jsPDF('p', 'mm', 'a4');
                    pdf.addImage(myImage, 'png', 15, 2, imgWidth, imgHeight); // 2: 19
                    pdf.save('H&H-Carport-Design.pdf');
                }
            });
        }       
        $("#btnPrint").on("click", function () {
            getPDFFileButton ()
        });
    </script>
<!-- End PDF Script -->
<button type="button" class="btn btn-lg btn-secondary" id="btnPrint">Print PDF <i class="fas align-middle fa-file-pdf"></i></button>

我需要帮助修改代码以从前、后、左和右拍摄画布的照片,并在单击“打印 PDF”按钮。这可能吗?

Hopefully the solution to what I would like to do is easy. I successfully have the canvas printing to a pdf using the following code:

<!-- Start PDF Script -->
  <script type="text/javascript">
        function getPDFFileButton () {
            return html2canvas($('canvas'), {
                background: "#ffffff",
                onrendered: function(canvas) {
                    var myImage = canvas.toDataURL("image/png,1.0");
                    // Adjust width and height
                    var imgWidth = (canvas.width * 20) / 240;
                    var imgHeight = (canvas.height * 20) / 240; 
                    // jspdf changes
                    var pdf = new jsPDF('p', 'mm', 'a4');
                    pdf.addImage(myImage, 'png', 15, 2, imgWidth, imgHeight); // 2: 19
                    pdf.save('H&H-Carport-Design.pdf');
                }
            });
        }       
        $("#btnPrint").on("click", function () {
            getPDFFileButton ()
        });
    </script>
<!-- End PDF Script -->
<button type="button" class="btn btn-lg btn-secondary" id="btnPrint">Print PDF <i class="fas align-middle fa-file-pdf"></i></button>

I need help modifying the code to take a picture of the canvas from the Front, Back, Left and Right and put all of the images on the same PDF when you click the "Print PDF" button. Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文