打印内嵌样式的页面

时间:2017-07-27 13:40:53

标签: css angular printing angular2-template

我有一个页面,我用各种设置动态设置它的样式

例如,这里是我要打印的表的元素:

  <td *ngFor="let attribute of attributes"
      [class.table-vertical]="styles.template['displayVerticalLines']"
      [style.border-left-width]="styles.template['displayVerticalLines']?styles.template['verticalLineSize'] + 'px':null"
      [style.border-right-width]="styles.template['displayVerticalLines']?styles.template['verticalLineSize'] + 'px':null"
      [style.border-left-color]="styles.template['displayVerticalLines']?styles.template['verticalLineColor']:null"
      [style.border-right-color]="styles.template['displayVerticalLines']?styles.template['verticalLineColor']:null">

这是我打印的功能:

   public print(): void {
            window.print();
    }

我看到样式对元素的影响很好但是当我尝试打印时,所有内联样式都被忽略,只有css文件中的样式才可见。

我意识到这是因为内联css的媒体类型不是打印的,但是我没有看到设置它的方法。

我还尝试添加动态<style>元素,但编译器只是忽略它并略过它。

这是一个简单的现象:

https://plnkr.co/edit/vm1AgWP33LL2Gslylvkp?p=preview

我该如何克服这个问题?

0 个答案:

没有答案