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 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿