简体   繁体   English

是否有打印html表背景的技巧?

[英]Is there a trick to print html table background?

Suppose, I create a calendar as HTML table where different cells have different background color and different text. 假设,我创建一个日历作为HTML表格,其中不同的单元格具有不同的背景颜色和不同的文本。 It looks nice on screen. 它在屏幕上看起来不错。

I realized that it is not possible to print this table preserving the cell's background color. 我意识到打印此表不可能保留单元格的背景颜色。 Instructing my viewers to tweak their browsers to print the calendar is just ridiculous. 指示我的观众调整他们的浏览器来打印日历是非常荒谬的。

Is there any trick to print HTML table as you see it on screen? 你在屏幕上看到HTML表是否有任何技巧? Maybe it is possible to somehow transform it to image, or something? 也许有可能以某种方式将其转换为图像或其他东西?


Here is a solution that I came up with. 这是我提出的解决方案。
Below is an illustration of creating printable 3x2 board, with 100pt x 100pt cells. 下面是创建可打印的3x2板,100pt x 100pt单元的示意图。 I simplified the fragment as much as possible. 我尽可能地简化了片段。 Main idea: every cell has an image that is overlayed by text. 主要思想:每个单元格都有一个由文本覆盖的图像。 This is much more slower than having simple background color, but allow having single codebase for screen and printing. 这比具有简单的背景颜色要慢得多,但允许使用单个代码库进行屏幕和打印。
You can get rid of inner spacing with additional styling. 你可以通过额外的造型摆脱内部空间。

<table style="table-layout:fixed; width:300pt; height:200pt; border-collapse:collapse; line-height: 0;">
    <tr>
        <td>
        <img src="Content/images/backTab.png" style="width:100pt; height:100pt; position:relative; z-index:0" />
        <div style="position:relative; top:-50pt; z-index:1; color:Red; text-align:center; ">Text</div>
        </td>

I'm new in Web development and I found the whole situation being ridiculous. 我是Web开发的新手,我发现整个情况都很荒谬。 Thousands developers crying about printing of background color/image but nobody cares. 成千上万的开发人员一直在为打印背景颜色/图像而烦恼,但没有人关心。 I have looked at W3C HTML/CSS/Printing standards. 我看过W3C HTML / CSS / Printing标准。 There is nothing there about suppressing backgrounds on printing. 没有什么可以抑制打印背景。 If browsers make decision to save user's ink, there must be CSS style to explicitly enforce the background printing. 如果浏览器决定保存用户的墨迹,则必须有CSS样式才能明确强制执行后台打印。 In this case there will be no stupid difficulties to show and print chess board, or crossword puzzle, or calendar. 在这种情况下,展示和印刷国际象棋棋盘,填字游戏或日历将不会有愚蠢的困难。

If anyone has connections in W3C, please, let them know. 如果有人在W3C有联系,请告诉他们。

You can create a css file and specify it in the html that it should be used for printing: 您可以创建一个css文件,并在html中指定它应该用于打印:

http://www.alistapart.com/articles/goingtoprint/ http://www.alistapart.com/articles/goingtoprint/

However, settings such as printing it as you see it on the screen require settings to be changed in the web browsers print settings. 但是,如在屏幕上看到的那样进行打印等设置需要在Web浏览器打印设置中更改设置。

Unfortunately there is no way around this without a custom solution. 不幸的是,如果没有自定义解决方案,就无法解决这

You can play with Prototype Javascript and assign the HTML to canvas element which will create an image on the client side. 您可以使用Prototype Javascript并将HTML分配给canvas元素,该元素将在客户端创建图像。

http://prototype-graphic.xilinus.com/ http://prototype-graphic.xilinus.com/

Hope this helps, 希望这可以帮助,

Jeffrey Kevin Pry Jeffrey Kevin Pry

Couldn't you use 10x10 images with the background color you're thinking of and have them set to repeat across the background using CSS? 难道你不能使用你想到的背景颜色的10x10图像并将它们设置为使用CSS在背景中重复吗? (Fixed color images are very easily compressible and tend to be small, don't worry about the size as pointed out in the comments). (固定彩色图像非常容易压缩,往往很小,不用担心评论中指出的大小)。

Also, in addition to my comment you can try to use: http://iecapt.sourceforge.net/ update: Also, this article probably can be helpful. 此外,除了我的评论,你可以尝试使用: http//iecapt.sourceforge.net/ update:此外,这篇文章可能会有所帮助。 http://www.codeproject.com/KB/graphics/html2image.aspx http://www.codeproject.com/KB/graphics/html2image.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM