HTML 变得“漂亮”用于在纯文本打印机上打印的文本转换(点阵)

发布于 2024-09-01 10:00:36 字数 1238 浏览 4 评论 0原文

我有一个网站,可以生成一些简单的表格数据作为 html 表格,我的许多用户在激光/喷墨打印机上打印网页;然而,有些人喜欢在传统的点阵打印机上打印(仅限文本),这就是问题所在。

当从网络浏览器向点阵打印机进行打印时,打印机实际上将数据视为“图形”/图像,并继续逐点打印。

即,如果打印字符“C”,打印机将其水平切片并分 3-4 遍打印。

同一打印机将 ASCII 文件(例如记事本)中的文本作为完整字符一次性打印,因此比打印网页时速度快 5 倍,而且安静得多。

(甚至尝试过“通用纯文本驱动程序”,但 Mozilla Firefox 有一个已知的错误,即自 2.0+ 以来,它不会在该特定驱动程序上打印任何内容)

那么是否有一些干净的方法来格式化已经生成的 HTML(比如方法采用整个 html)表作为字符串)并生成具有正确对齐的列的相应文本文件?

我尝试过剥离 html 标签,但主要问题是对单元格数据进行良好的“包装”并保持其他单元格数据(来自同一行)的完整性。

例如:(“|”和“_”并不是必需的)

Col1    |  Col2      |  Colum_Name3  |  Col4   |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
1       |  this cell | this column   | smaller |
        | is in three| spans 2 rows  |         |
        | rows       |               |         |
- - - - - - - - - - - - - - - - - - - - - - - - 
2       | smaller now| this also     | but this|
        |            |               | cell's  |
        |            |               | data is |
        |            |               | now     |
        |            |               | bigger  |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

您能否建议首选方法?

我想过使用 xslt 并以某种方式输出文本(而不是更流行的 pdf),但 Apache FOP 的文本渲染器确实损坏了,并且可能在开发路径中被遗忘了。商用的太贵了。

I have a web-site that generates some simple tabular data as html tables, many of my users print the web-page on a laser/inkjet printer; however some like to print on legacy Dot Matrix printers (text only) and there-in lies the problem.

When giving Print from web-browser onto dot-matrix printer, the printer actually perceives data as 'graphic'/image and proceeds to print it dot-by-dot.

i.e If printing a character 'C', printer slices it horizontally and prints in 3-4 passes.

Same printer prints a text from an ASCII file (say from notepad) as complete characters in single pass, thereby being 5 times faster and much quieter than when printing a web-page.

(Even tried 'generic text-only driver' but Mozilla Firefox has a know bug that it does not print anything over this particular driver since 2.0+)

So is there some clean way of formatting an already generated HTML (say method takes the entire html table as string) and generates a corresponding text file with properly aligned columns?

I have tried stripping the html tags, but the major issue there is performing good 'wrapping' of a cell's data and maintaining integrity of other cells' data (from same row).

eg: ( '|' and '_' not really required)

Col1    |  Col2      |  Colum_Name3  |  Col4   |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
1       |  this cell | this column   | smaller |
        | is in three| spans 2 rows  |         |
        | rows       |               |         |
- - - - - - - - - - - - - - - - - - - - - - - - 
2       | smaller now| this also     | but this|
        |            |               | cell's  |
        |            |               | data is |
        |            |               | now     |
        |            |               | bigger  |
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Could you please suggest preferred approach?

I've thought of using xslt and somehow outputting text (instead of more prevalent pdf), but Apache FOP's text renderer is really broken and perhaps forgotten in development path. Commercial one's are way too costly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2024-09-08 10:00:36

有一些文本浏览器可以执行此操作:例如,Lynx:http://lynx.isc。 org/ 和 Elinks:http://elinks.or.cz/

编辑:哎呀,Lynx 不支持表,但 Elinks 支持。

There are text browsers out there that can do this: For example, Lynx: http://lynx.isc.org/ and Elinks: http://elinks.or.cz/

EDIT: Oops, Lynx doesn't support tables, but Elinks does.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文