将 HTML 文件转换为 PDF [英] Converting HTML files to PDF

查看:60
本文介绍了将 HTML 文件转换为 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从现有的 (X)HTML 文档自动生成 PDF 文件.输入文件(报告)使用相当简单的基于表格的布局,因此可能不需要对真正花哨的 JavaScript/CSS 内容的支持.

I need to automatically generate a PDF file from an exisiting (X)HTML-document. The input files (reports) use a rather simple, table-based layout, so support for really fancy JavaScript/CSS stuff is probably not needed.

由于我习惯于在 Java 中工作,因此更可取的是可以轻松地在 Java 项目中使用的解决方案.不过,它只需要在 Windows 系统上工作.

As I am used to working in Java, a solution that can easily be used in a java-project is preferable. It only needs to work on windows systems, though.

一种可行但不能产生高质量输出(至少开箱即用)的方法是使用 CSS2XSLFO 和 Apache FOP 来创建 PDF 文件.我遇到的问题是,虽然 CSS 属性转换得很好,但表格布局非常混乱,文本从表格单元格中流出.

One way to do it that is feasable, but does not produce good quality output (at least out of the box) is using CSS2XSLFO, and Apache FOP to create the PDF files. The problem I encountered was that while CSS-attributes are converted nicely, the table-layout is pretty messed up, with text flowing out of the table cell.

我还快速浏览了 Jrex,这是一种用于使用 Gecko 渲染引擎的 Java-API.

I also took a quick look at Jrex, a Java-API for using the Gecko rendering engine.

有没有办法从 Internet Explorer 渲染引擎中获取渲染页面并将其自动发送到 PDF 打印机工具?我没有在 Windows 中进行 OLE 编程的经验,所以我不知道什么是可能的,什么是不可能的.

Is there maybe a way to grab the rendered page from the internet explorer rendering engine and send it to a PDF-Printer tool automatically? I have no experience in OLE programming in windows, so I have no clue what's possible and what is not.

你有什么想法吗?

推荐答案

Flying Saucer XHTML 渲染器项目支持将 XHTML 输出为 PDF.看一个例子 这里.

The Flying Saucer XHTML renderer project has support for outputting XHTML to PDF. Have a look at an example here.

这篇关于将 HTML 文件转换为 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆