如何在Chrome ios(iPAD)上获得jspdf点击按钮打印pdf?

时间:2017-11-15 17:30:35

标签: javascript ios google-chrome jspdf

我有一个带有按钮的aspx页面:

<input type="button" class="create_pdf" id="create_pdf" value="Generate PDF" /> 

使用jspdf从html生成pdf文件。一切都可以从台式机和笔记本电脑中完美运行,但出于某种原因,从ipad点击Chrome ios上的按钮什么都不做。有关决议的任何建议吗?以下是代码:

<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>  

<script>
    (function () {
        var
         form = $('.form'),
         cache_width = form.width(),
         legal = [612.00, 1008.00]; // for legal size paper width and height  

        $('#create_pdf').on('click', function () {
            $('body').scrollTop(0);
            createPDF();
        });
        //create pdf  
        function createPDF() {
            getCanvas().then(function (canvas) {
                var
                 img = canvas.toDataURL("image/png"),
                 doc = new jsPDF(
                    {
                        orientation: "p",
                        unit: 'px',
                        format: 'legal',
                    }
                 );

                var position = 0;
                var imgWidth = 790;
                var pageHeight = 1296;
                var imgHeight = canvas.height * imgWidth / canvas.width;
                var heightLeft = imgHeight;

                doc.addImage(img, 'PNG', 0, position, imgWidth, imgHeight);

                window.open(doc.output('bloburl'), '_self');
                form.width(cache_width);
            });
        }

        // create canvas object  
        function getCanvas() {

            return html2canvas(form, {
                imageTimeout: 2000,
                removeContainer: true
            });
        }

    }());
</script>  

0 个答案:

没有答案