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 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图