i'm working with iText in Java Servlets. I'm fighting with the creation of PDFs from my JSP files. I've seen that is not possible, so i created new servlets which parse a String (my HTML page). Here part of the code:
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();
This code works. Now i have to create another PDF which needs to have an A4 page rotated by 90°. Using org.w3c.dom.Document i can't find how to do. There is the possibility to use another Document Class, the com.itextpdf.text.Document which has the rotate() method to rotate it, but using this Document i can't find how to do to parse my String (HTML code)...
Hints?
如果您需要的只是侧面的文档,则可以使用以下方法:
private Document document = new Document(PageSize.A4.rotate());
...i've just found out, that iTextRendere is not part of iText, but of Flying Source. In this link i've seen that the creation of a landscape page is simply done by adding some css to the source (X)HTML:
<style type="text/css">
@page{ size: 11.69in 8.27in;}
...
</style>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.