Created
September 2, 2014 17:12
-
-
Save marti1125/1b0c76aaa484c6bce4e1 to your computer and use it in GitHub Desktop.
Play Framework IText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | |
| PdfReader reader = new PdfReader(pdfYExcelStream); | |
| Rectangle psize = reader.getPageSize(1); | |
| Document document = new Document(PageSize.A4); | |
| reader.getPageContent(1); | |
| PdfWriter writer = PdfWriter.getInstance(document, outputStream); | |
| writer.addPageDictEntry(PdfName.ROTATE, PdfPage.LANDSCAPE); | |
| document.open(); | |
| PdfContentByte cb = writer.getDirectContent(); | |
| PdfImportedPage page = writer.getImportedPage(reader, 1); | |
| int cantidadPaginas = Math.round( psize.getWidth() / 800 ); | |
| System.out.println("hancho!! "+page.getWidth()); | |
| System.out.println("cantidad paginas " + cantidadPaginas); | |
| System.out.println("ancho original!! "+psize.getWidth()); | |
| //// Página final | |
| //document.setPageSize(PageSize.A4.rotate()); //-document.getPageSize().getWidth() | |
| //document.newPage(); | |
| //AffineTransform afinit = new AffineTransform(0, -1, 1, 0, -32800, 600); // equivale a 11 paginas mas! | |
| //cb.addTemplate(page,afinit); | |
| ///////////////////////////////////////// | |
| int totalAnchoDePaginas = 800*cantidadPaginas; | |
| System.out.println("total del ancho de las paginas!!" + totalAnchoDePaginas); | |
| //int tt = -32800 - 800; | |
| int tt = -totalAnchoDePaginas - 800; | |
| for(int p = 1; p <=totalAnchoDePaginas; p++){ | |
| tt = tt + 800; | |
| document.setPageSize(PageSize.A4.rotate()); | |
| document.newPage(); | |
| AffineTransform af = new AffineTransform(0, -1, 1, 0, tt, 600); | |
| cb.addTemplate(page, af); | |
| if(tt == 0){ | |
| break; | |
| } | |
| } | |
| document.close(); | |
| writer.flush(); | |
| writer.close(); | |
| outputStream.close(); | |
| ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
| out.flush(); | |
| out.write(outputStream.toByteArray()); | |
| out.close(); | |
| // de output a input!! | |
| InputStream resultadoPDF = new ByteArrayInputStream(out.toByteArray()); | |
| renderBinary(resultadoPDF, "ReporteDeDistribucionClasesPorHoras.pdf", | |
| "application/pdf", true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment