2012-03-27 194 views
0

我正在使用Java Servlet中的iText。我正在从我的JSP文件创建PDF文件。我已经看到这是不可能的,所以我创建了解析字符串(我的HTML页面)的新servlet。这里的部分代码:使用iText和org.w3c.dom.Document旋转PDF文件

StringBuffer buffer = getHTMLinBuffer(consulenti, anUser); 
DocumentBuilder builder = DocumentBuilderFactory 
    .newInstance().newDocumentBuilder(); 
Document doc = builder.parse(new ByteArrayInputStream(buffer.toString().getBytes("UTF-8"))); 
ITextRenderer renderer = new ITextRenderer(); 
renderer.setDocument(doc, null); 
String fileName = "listaConsulenti.pdf"; 
String absolutePath = getServletContext().getRealPath("/"); 
String tempPath = absolutePath + "temp/"; 
File file = new File(tempPath, fileName); 
file.createNewFile(); 
OutputStream os = new FileOutputStream(file); 
renderer.layout(); 
renderer.createPDF(os); 
os.close(); 

此代码有效。 现在我必须创建另一个需要A4页面旋转90°的PDF。使用org.w3c.dom.Document我找不到如何操作。 有可能使用其他文档类,com.itextpdf.text.Document其中rotate()方法旋转它,但使用此文档我找不到如何做解析我的字符串(HTML代码)...

提示?

回答

0

...我只是发现了,那iTextRendere不iText的一部分,但飞来源。 在this link我已经看到了一个横向页面的创建是简单地通过添加一些CSS来源(X)HTML做:

<style type="text/css"> 
@page{ size: 11.69in 8.27in;} 
... 
</style> 
0

如果你需要的是在它的一侧的文档,可以使用以下命令:

private Document document = new Document(PageSize.A4.rotate()); 
+0

不,我不能。使用org.w3c.dom.Document是不可能的。 – Emaborsa 2012-03-28 15:52:02