0

我正在尝试使用 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 调整打印元素宽度的经验?

谢谢

4

1 回答 1

0

尝试将样式表传递给库。如果 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
})
于 2019-05-15T21:26:52.813 回答