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

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

问题描述

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



因为我习惯于在Java中工作,可以很容易地在Java项目中使用的解决方案是可取的。虽然它只需要在Windows系统上工作。



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



快速浏览一下使用Gecko渲染引擎的Java-API Jrex。

是否有办法从Internet Explorer呈现引擎中抓取呈现的页面并自动将其发送到PDF打印机工具?我在Windows中没有OLE编程经验,所以我不知道什么是可能的,哪些不是。



你有想法吗?

编辑:FlyingSaucer / iText看起来非常有希望。我会尽力去解决这个问题。



感谢所有的答案

解决方案

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


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.

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.

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.

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

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.

Do you have an idea?

EDIT: The FlyingSaucer/iText thing looks very promising. I will try to go with that.

Thanks for all the answers

解决方案

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天全站免登陆