【问题标题】:Adjusting Div Width with printJS使用 printJS 调整 Div 宽度
【发布时间】:2019-05-14 15:46:43
【问题描述】:

我正在尝试使用 PrintJS 库。它允许您定位特定的 id 并打印该 id 中包含的 html。我面临的问题是,当我更改屏幕尺寸时,它也会更改 div 的打印尺寸。它们为您提供了传入 css 的选项,但并非所有更改都被应用。

这是我的测试用法:

printJS({printable: 'oogles', type: 'html', style: '.modal-header { color: red; width: 100px; } .modal-body { width:100% }'})

一些css更改已成功应用于color: red等样式部分,但更改宽度似乎不起作用。我尝试过width: 100%; 或任意设置为特定宽度,如width: 100px;

html:

    <div id='oogles'>
      <div class='modal-header'>wooooooo we are printing some things!</div>
      <div class='modal-body'>well we are trying at least</div>
    </div>

有人有使用 PrintJS 调整打印元素宽度的经验吗?

谢谢

【问题讨论】:

    标签: javascript jquery printjs


    【解决方案1】:

    尝试将样式表传递给库。如果 HTML 没有任何内联样式标签,最好禁用 lib 的样式处理。

    例如:

    printJS({
      printable: 'oogles', 
      type: 'html', 
      style: '.modal-header { color: red; width: 100px; } .modal-body { width:100% }'
      css: [
             'my_stylesheet_1',
             'my_stylesheet_2.css'
      ],
      scanStyles: false
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      • 1970-01-01
      • 2021-06-22
      • 1970-01-01
      相关资源
      最近更新 更多