List of usage examples for com.itextpdf.text PageSize A3
Rectangle A3
To view the source code for com.itextpdf.text PageSize A3.
Click Source Link
From source file:org.saiku.web.export.PdfReport.java
License:Apache License
public byte[] pdf(QueryResult qr, String svg) throws Exception { int resultWidth = qr != null && qr.getCellset() != null && qr.getCellset().size() > 0 ? qr.getCellset().get(0).length : 0;//from w w w. ja v a2 s. c om if (resultWidth == 0) { throw new SaikuServiceException("Cannot convert empty result to PDF"); } Rectangle size = PageSize.A4.rotate(); if (resultWidth > 8) { size = PageSize.A3.rotate(); } if (resultWidth > 16) { size = PageSize.A2.rotate(); } if (resultWidth > 32) { size = PageSize.A1.rotate(); } if (resultWidth > 64) { size = PageSize.A0.rotate(); } Document document = new Document(size, 15, 15, 10, 10); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); document.open(); populatePdf(document, writer, qr); // do we want to add a svg image? if (StringUtils.isNotBlank(svg)) { document.newPage(); StringBuffer s1 = new StringBuffer(svg); if (!svg.startsWith("<svg xmlns=\"http://www.w3.org/2000/svg\" ")) { s1.insert(s1.indexOf("<svg") + 4, " xmlns='http://www.w3.org/2000/svg'"); } String t = "<?xml version='1.0' encoding='ISO-8859-1'" + " standalone='no'?>" + s1.toString(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.concatCTM(1.0f, 0, 0, 1.0f, 36, 0); float width = document.getPageSize().getWidth() - 20; float height = document.getPageSize().getHeight() - 20; Graphics2D g2 = cb.createGraphics(width, height); //g2.rotate(Math.toRadians(-90), 100, 100); PrintTranscoder prm = new PrintTranscoder(); TranscoderInput ti = new TranscoderInput(new StringReader(t)); prm.transcode(ti, null); PageFormat pg = new PageFormat(); Paper pp = new Paper(); pp.setSize(width, height); pp.setImageableArea(5, 5, width, height); pg.setPaper(pp); prm.print(g2, pg, 0); g2.dispose(); cb.restoreState(); } document.close(); return baos.toByteArray(); }