drbouzlxb92333332 2017-09-14 05:24
浏览 152

从chrome中打开的pdf中删除图像的边框

I wanna download the current page into pdf by button click , I used the html2canvas concept and here is the sample code

$("#btnPdf").click(function(){

    var dt    = new Date();
    var day   = dt.getDate();
    var month = dt.getMonth() + 1;
    var year  = dt.getFullYear();
    var hour  = dt.getHours();
    var mins  = dt.getMinutes();
    var postfix = month + "-" + day + "-" + year + "_" + hour + ":" + mins;
    var docs = 'dd'+ postfix;



    html2canvas(document.getElementById("main-div"), {
        onrendered: function(canvas) {

            var width = canvas.width;
            var height = canvas.height;
            var millimeters = {};
            millimeters.width = Math.floor(width * 0.264583);
            millimeters.height = Math.floor(height * 0.264583);


            var imgData = canvas.toDataURL('image/png',1.0);
            console.log('Report Image URL: '+imgData);

            var doc = new jsPDF('p', 'mm', "a4"); //210mm wide and 297mm high
             doc.deletePage(1);
             doc.addPage(millimeters.width, millimeters.height);
            doc.addImage(imgData, 'png',0,0);
            doc.save(docs+'.pdf');
        },

    });

});

and works fine.I am getting the borders for image of current page in pdf only when you open the pdf in chrome but I didnt get any border in pdf while opening in adobe,firefox etc.But the problem is in chrome. Please any suggestions , how to remove the border for the images in pdf opened in chrome. Thanks in advance

  • 写回答

1条回答

  • duanjiao2978 2017-09-14 07:10
    关注

    i think your real question is:

    How to control html style when save it as pdf by chrome "print page"?

    Maybe, you can first set img style through chrome "Element" pannel or by javascript, remove img border, then calling save api.

    PS:

    As far as i know, what chrome doing when print page as pdf is complex.

    For example, it need transform page content(pixels) to pdf size(a4/a3/a2), that decides pdf typograph.

    Some web designers do adjusting work of print things by add a <link> element with attribute media="print". So this style file will effects only when printing.

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作