html - 打印 asp.net、javascript 后更改表格的字体大小和列宽

标签 html css

我在代码中有一个表要打印,它看起来像这样:

Web page view

当我尝试打印表格时,它的打印格式如下所示:

Print view

我需要更改打印 View 中文本的字体大小,还需要更改打印 View 中的列大小。另外,如果我可以删除 Web 表的打印 View 中的边框。

我使用 javascript 来打印表格。我已经使用了表 ID。

<script type="text/javascript"> 
function PrintPage() 
{ 

    var TableToPrint = document.getElementById('thisIDisforprinting2'); 
    newWin = window.open(""); 
    newWin.document.write(TableToPrint.outerHTML); 
    newWin.print(); 
    newWin.close();

} 
</script>

最佳答案

您可以使用 document.write 添加 css 标签,并使用“打印”媒体查询根据需要设置表格样式。

函数 PrintPage() {

    var TableToPrint = document.getElementById('thisIDisforprinting2');
    newWin = window.open("");
    newWin.document.write(TableToPrint.outerHTML);
    newWin.document.write('<style type="text/css"> @media print { #thisIDisforprinting2 { font-size: 24px; } }</style>');
    newWin.print();
    newWin.close();
}

低于设置列高并删除边框的版本

    newWin.document.write('<style type="text/css"> @media print { #thisIDisforprinting2 { font-size: 24px; border: none; } #thisIDisforprinting2 td { height: 150px; border: none; } } </style>');

关于html - 打印 asp.net、javascript 后更改表格的字体大小和列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52488834/

相关文章:

html - 使用 :not to remove formatting

php - 动态创建多个上传文件

php - 如何在具有基本主题的 Moodle 2.6 中通过 https 获取背景图像?

css - 菜单调整到下一行而不是全宽

javascript - 如何按对象的值对对象数组进行排序

css - Inline-block mistery : same code, 相同的客户端,不同的服务器但空间消失

css - body 和 child 身上带有 flexbox 的粘性页脚

javascript - 使用选择选项标签动态添加输入字段

html - 保持动画的连续性

html - photoshop 中的像素大小与 HTML/CSS 中的像素大小不同?