给定目标整个div是否不使用jspdf导出为pdf?

时间:2019-01-08 07:24:35

标签: javascript html jspdf

我正在将bootstrap modal导出为pdf。这是我的html代码

 <div class="modal fade" id="myModalLarge" tabindex="-1" role="dialog" aria-labelledby="myModalLabelLarge" aria-hidden="true">
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <h4 class="modal-title" id="myModalLabelLarge">Load Sensor Report</h4>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="modal-body" id="content">
                    <div class="row" id="widgets">
                        <div class="col-xl-4 col-lg-6 col-md-12">
                            <!-- START date widget-->
                            <div class="card bg-info-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h2 mt-0">500</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px">Live Force</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="2,3,5,1,5,9" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                            <!-- END date widget-->
                        </div>
                        <div class="col-xl-4 col-lg-6 col-md-12">
                            <!-- START date widget-->
                            <div class="card bg-info-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h2 mt-0">500</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px">Live Repititions</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                            <!-- END date widget-->
                        </div>
                        <div class="col-xl-4 col-lg-6 col-md-12">
                            <!-- START card-->
                            <div class="card bg-info-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h2 mt-0">500</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px">Live Sets</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                        </div>
                    </div>
                    <!-- chart card start-->
                    <div class="row">
                        <div class="col-xl-12">
                            <!-- START card-->
                            <div class="card card-default card-demo" id="cardChart9">
                                <div class="card-header">
                                    <a class="float-right" href="#" data-tool="card-refresh" data-toggle="tooltip" title="Refresh card">
                                        <em class="fas fa-sync"></em>
                                    </a>
                                    <a class="float-right" href="#" data-tool="card-collapse" data-toggle="tooltip" title="Collapse card">
                                        <em class="fa fa-minus"></em>
                                    </a>
                                    <div class="card-title">Live Activity Data</div>
                                </div>
                                <div class="card-wrapper collapse show">
                                    <div class="card-body">
                                        <canvas id="myChart1"></canvas>
                                    </div>
                                </div>
                            </div>
                            <!-- END card-->
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START date widget-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0" id="m_tf">--</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Target Force</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="2,3,5,1,5,9" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                            <!-- END date widget-->
                        </div>
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START date widget-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0">500</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Average Force</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                            <!-- END date widget-->
                        </div>
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START card-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0" id="m_tr">--</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Target Repetions</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                        </div>
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START card-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0">12</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Average Repetions</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START card-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0" id="m_ts">--</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Target Sets</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                        </div>
                        <div class="col-xl-3 col-lg-6 col-md-12">
                            <!-- START card-->
                            <div class="card bg-purple-light pt-2 b0">
                                <div class="px-2">
                                    <em class="icon-bubbles fa-lg float-right"></em>
                                    <div class="h4 mt-0">02</div>
                                    <div class="text-uppercase" style="padding-bottom: 10px;font-weight:bold;font-size: 12px">Actual Sets</div>
                                </div>
                                <div data-sparkline="" data-type="line" data-width="100%" data-height="75px" data-line-color="#23b7e5" data-chart-range-min="0"
                                    data-fill-color="#23b7e5" data-spot-color="#23b7e5" data-min-spot-color="#23b7e5"
                                    data-max-spot-color="#23b7e5" data-highlight-spot-color="#23b7e5" data-highlight-line-color="#23b7e5"
                                    data-values="4,5,3,10,7,15" style="margin-bottom: -2px" data-resize="true"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- </div> -->
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <div class="modal-footer" id="ignore1">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal" style="margin-left:40px">Close</button>
                    <button class="btn btn-primary" type="button" id="toPdf">Export To Pdf</button>
                </div>
            </div>
        </div>
    </div>
</div>

这是js代码

var doc = new jsPDF('p', 'pt', 'a4');
    var elementHandler = {
        '#ignore1': function (element, renderer) {
            return true;
        }
    };
    $('#toPdf').click(function () {
        doc.addHTML($('#content'), {
            'elementHandlers': elementHandler
        }, function () {
            doc.save('sample-file.pdf');
        });
    });

除了页脚和页眉,我正在导出整个模式。我的情态就是这样 enter image description here

但是当我将其导出为pdf时,它会像这样导出 enter image description here

我正在使用jspdf。我给整个模态内容指定一个id,该id传入jspdf对象以创建pdf,但是当我导出时,它切掉了上面的3个蓝色小部件。

1 个答案:

答案 0 :(得分:0)

尝试使用.Suffix()代替.html()。要忽略div,请使用.addHtml()

data-html2canvas-ignore="true"