打印时捕获图像时html2canvas缩放问题

发布于 2025-01-12 23:32:41 字数 2033 浏览 4 评论 0原文

我正在尝试使用 html2canvas 打印一个元素。但它从左侧给出了空白空间,如下图所示。页面中没有任何滚动条。我尝试了很多解决方案但没有任何效果。

我的html代码:

 <div *ngIf="journeyAnalizeData" class="row rowmargin0">
            <div class="col-lg-12 col-xl-12 gridPadding">
                <div id='printArea'>
                    <table id="tableList" class="table-list">
                        <tr>
                            <td
                                style="text-align: center; color:Black;background-color:White;border-style:None;width:247px;vertical-align:Top;padding: 0px;">
                                <div id="container" class="container">
                                    <div style="width: 100%; text-align: center; font-size: 14pt; font-weight: bold; display:flex; flex-direction: column;">
                                        <div class="buttons" style="display:flex; justify-content: flex-start;">

                                            <button class="print-button" (click)="print()"
                                                 
                                                ><i
                                                    class="fa fa-print" aria-hidden="true"></i>
                                                {{'report.fms.journeyAnalize.yaziciyagonder' |
                                                translate}}
                                            </button>

我的代码ts代码:

print() {

        html2canvas(document.querySelector("#printArea"), <any>{
            useCors: true,
            allowTaint: false,
            
        }).then(canvas => {
            
            var nWindow = window.open("");

            nWindow.document.body.appendChild(canvas);

            nWindow.focus();
            nWindow.print();
        });

    }

在此处输入图像描述

I'm trying to print an element with html2canvas. But it gives empty space from left and it shows like below image. There isn't any scroll in the page. I tried lots of solution but nothing works.

my html code:

 <div *ngIf="journeyAnalizeData" class="row rowmargin0">
            <div class="col-lg-12 col-xl-12 gridPadding">
                <div id='printArea'>
                    <table id="tableList" class="table-list">
                        <tr>
                            <td
                                style="text-align: center; color:Black;background-color:White;border-style:None;width:247px;vertical-align:Top;padding: 0px;">
                                <div id="container" class="container">
                                    <div style="width: 100%; text-align: center; font-size: 14pt; font-weight: bold; display:flex; flex-direction: column;">
                                        <div class="buttons" style="display:flex; justify-content: flex-start;">

                                            <button class="print-button" (click)="print()"
                                                 
                                                ><i
                                                    class="fa fa-print" aria-hidden="true"></i>
                                                {{'report.fms.journeyAnalize.yaziciyagonder' |
                                                translate}}
                                            </button>

My code ts code:

print() {

        html2canvas(document.querySelector("#printArea"), <any>{
            useCors: true,
            allowTaint: false,
            
        }).then(canvas => {
            
            var nWindow = window.open("");

            nWindow.document.body.appendChild(canvas);

            nWindow.focus();
            nWindow.print();
        });

    }

enter image description here

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

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

发布评论

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