dongwen9975 2019-02-14 19:16
浏览 242

使用多个“选择”选项生成PDF?

I have a page showing a list of "selected" members with "ranks" and "year" and I want it to a pdf without showing the buttons.

How can I generate such a PDF without losing the style?

I've tried using plain jsPDF but it returns only some values but not (select) tags

<?php
echo '<script>';
 echo 'function onClick() {';
 echo "var pdf = new jsPDF('p', 'pt', 'letter');";
 echo 'pdf.canvas.height = 72 * 11;';
 echo 'pdf.canvas.width = 72 * 8.5;';
 echo "pdf.fromHTML($('.matrikule').get(0), 10, 10, {'width': 180});";
 echo 'pdf.save("test.pdf");';
 echo '};';
    echo 'var element = document.getElementById("clickbind");';
    echo 'element.addEventListener("click", onClick);';
    echo '</script>';
?>

Refer to the screenshot beneath

enter image description here

I want the PDF to show exactly the way it's on web page. Is this only achievable with html2canvas?

  • 写回答

1条回答 默认 最新

  • dqtok88424 2019-02-15 00:20
    关注

    You want to use jsPDF's .html() and html2canvas 1.0.0-alpha.12, not .fromHtml(). You may modify the following code for your php and put data-html2canvas-ignore="true" to the buttons you want to hide.

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.debug.js" 
            integrity="sha384-NaWTHo/8YCBYJ59830LTz/P4aQZK1sS0SneOgAvhsIl3zBu8r9RevNg5lHCHAuQ/"
            crossorigin="anonymous"></script>
    <script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
    <!-- html2canvas 1.0.0-alpha.11 or higher version is needed -->
    
    <script>
        function onClick() {
            let pdf = new jsPDF('p', 'pt', 'letter');
            pdf.html(document.getElementById('clickbind'), {
                callback: function () {
                    pdf.save('test.pdf');
                    window.open(pdf.output('bloburl')); // this makes debug easier.
                }
            });
        }
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测