gpt4 book ai didi

javascript - Html2pf/html2canvas/jsPDF 使用 Bootstrap 模式不显示边框

转载 作者:行者123 更新时间:2023-11-28 01:16:34 25 4
gpt4 key购买 nike

我不确定是哪个必需的库引发了这个问题,或者它是否与 Bootstrap 有关,但我无法让输出 PDF 显示边框。

我试过增加边框的宽度,但它只是被忽略了,不知道该怎么做。

fiddle :https://jsfiddle.net/8q7ce58y/233/

我曾尝试在模态主体中使用 .clone(),但它只会渲染到窗口 View 上的内容。

代码:(最好检查 fiddle )

<div class="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg modal-a4" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Doc Preview</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="row m-0">
<div class="col">
<p align="center">Text<br></p>
</div>
</div>
<div class="row m-0">
<div class="col">
<p><b><span style="font-size: 18px;">Field :</span></b> </p>
<p>{Field_Name}
</p>
</div>
</div>
<h3 class="text-center p-2 m-0">Images</h3>
<div class="row attachment-row m-0">
<div class="col-6 text-center p-2">
Image1
</div>
<div class="col-6 text-center p-2">
Image2
</div>
</div>
</div>
<div class="modal-footer"><button class="ml-auto btn btn-primary ld-ext-right">Download PDF<div class="ld ld-ring ld-cycle running"></div></button></div>
</div>
</div>
</div>

CSS:

.modal-dialog.modal-a4{
width: 8.27in !important;
padding: 0;
}
.modal-a4 .modal-body>*:last-child {
border-bottom: 10px solid black;
}

.modal-a4 .modal-body>* {
border-left: 10px solid black;
border-right: 10px solid black;
}

.modal-a4 .modal-body>*:not(.attachment-row) {
border-top: 10px solid black;
}

最佳答案

我在 jsPDF 中使用了 html2canvas

function savePdf(){
// body tag of html
html2canvas(document.body).then(function(canvas) {
var jpegUrl = canvas.toDataURL("image/jpeg");
var doc = new jsPDF('l', 'mm', [318, 210]);
doc.addImage(jpegUrl, 'JPEG', 10, 10);
doc.save('sample-file.pdf');
});
}

图书馆

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.4/jspdf.min.js"></script>

下载 html2canvas: https://html2canvas.hertzen.com/

html2canvas.js
html2canvas.min.js

并通过按钮或输入调用函数:

<button id="cmd" onclick="savePDF()">generate PDF</button>

关于javascript - Html2pf/html2canvas/jsPDF 使用 Bootstrap 模式不显示边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51790970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com