Pra*_*eep 1 google-chrome printing-web-page media-queries angular
我想打印HTML,但我不能够改变的布局和保证金的的Chrome浏览器(参见所附的图像)。
PRINT() {
window.print();
}Run Code Online (Sandbox Code Playgroud)
@media print {
.doNotPrint {
display: none;
}
* {
-webkit-print-color-adjust: exact;
}
@page {
margin: 0 !important;
size: A4 Landscape !important;
-webkit-print-color-adjust: exact;
}
html,
body {
margin: 0 !important;
size: A4 Landscape !important;
-webkit-print-color-adjust: exact;
}
}Run Code Online (Sandbox Code Playgroud)
<form [ngClass]="themeSRVC.currentThemeNAME" fxLayout="column" fxFlex>
<!-- navBAR -->
<mat-toolbar id="idPrimaryTOOLBAR" color="primary" class="doNotPrint">
<mat-toolbar-row>
<button mat-icon-button type="button" (click)="routeSRVC.goBACK()">
<mat-icon matTooltip="Go Back">arrow_back</mat-icon>
</button>
<span class="fillSPACE"></span>
<button mat-icon-button (click)="PRINT()">
<mat-icon matTooltip="print">print</mat-icon>
</button>
</mat-toolbar-row>
</mat-toolbar>
<!-- *****printableCONTENT***** -->
<div id="idToPRINT" fxFlex>
<div fxLayout="row">
<div fxFlex="33" style="height:200px;background-color:red">Left</div>
<div fxFlex style="height:200px;background-color:yellow">Center</div>
<div fxFlex="33" style="height:200px;background-color:green"> Right</div>
</div>
</div>
</form>Run Code Online (Sandbox Code Playgroud)
我错过了什么..?请帮我删除边距并更改布局。
经过数小时的研究......我终于弄明白了。!
在您的应用程序的全局style.scss中设置 @media 样式。
不要在component.scss
如果您想将布局动态更改为纵向/横向,您可以执行以下操作
1)从全局 scss 中删除@media print{...}
2)在你的component.ts 中通过传递真/假来调用打印函数
PRINT(landscape: boolean) {
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
style.media = 'print';
style.appendChild(document.createTextNode(landscape ?
'@page { size: A4 landscape; margin: 0in;}' :
'@page { size: A4; margin: 0in; }'));
head.appendChild(style);
window.print();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3653 次 |
| 最近记录: |