List of usage examples for com.itextpdf.text PageSize A4
Rectangle A4
To view the source code for com.itextpdf.text PageSize A4.
Click Source Link
From source file:Login.ventas.fproyectos.java
public void fondos(Document documento, PdfContentByte canvas) { try {//from www . java2s . c om Image imghead = Image.getInstance(usuario.getDireccion() + "/plantilla.jpg"); imghead.setAbsolutePosition(0, 0); imghead.setAlignment(Image.ALIGN_CENTER); float scaler = ((documento.getPageSize().getWidth() - documento.leftMargin() - documento.rightMargin()) / imghead.getWidth()) * 100; imghead.scalePercent(scaler); PdfTemplate tp = canvas.createTemplate(PageSize.A4.getWidth(), PageSize.A4.getHeight()); //el rea destinada para el encabezado tp.addImage(imghead); x = (int) imghead.getWidth(); y = (int) imghead.getHeight(); canvas.addTemplate(tp, 0, 0);//posicin del tmplate derecha y abajo } catch (IOException | DocumentException io) { } }
From source file:memoire.Exercises.java
public void CreatePdf44(ArrayList<String> list, String nameFile) { try {/* w w w .j a v a 2 s.c om*/ com.itextpdf.text.Document document = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4); String fileNameWithPath = "Examen00" + nameFile + ".pdf"; FileOutputStream fos = new FileOutputStream(fileNameWithPath); com.itextpdf.text.pdf.PdfWriter pdfWriter = com.itextpdf.text.pdf.PdfWriter.getInstance(document, fos); Rectangle rectangle = new Rectangle(30, 30, 550, 800); pdfWriter.setBoxSize("rectangle", rectangle); HeaderAndFooterPdfPageEventHelper headerAndFooter = new HeaderAndFooterPdfPageEventHelper(); //pdfWriter.setPageEvent(headerAndFooter); document.open(); com.itextpdf.text.html.simpleparser.HTMLWorker htmlWorker = new com.itextpdf.text.html.simpleparser.HTMLWorker( document); try { document.newPage(); //Rectangle page = document.getPageSize(); //PdfPTable head = new PdfPTable(1); //head.setHorizontalAlignment(10); // document.add(new Paragraph(Jsoup.parse(list.get(0)).text())); // headerAndFooter.onStartPage(pdfWriter, document,Jsoup.parse(list.get(0)).text()); //System.out.println(list.get(0)); for (int j = 0; j < NbrPartie + 1; j++) { // System.out.println(Jsoup.parse(list.get(j)).text()); // htmlWorker.parse(new StringReader(list.get(j))); XMLWorkerHelper.getInstance().parseXHtml(pdfWriter, document, new FileInputStream(list.get(j))); } //head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin()); //float number=page.getHeight() - document.topMargin()+ head.getTotalHeight(); //head.writeSelectedRows(0,(int)page.getWidth(), document.leftMargin(),page.getHeight() - document.topMargin()+ head.getTotalHeight(),pdfWriter.getDirectContent()); //pdfWriter.getPageNumber(); pdfWriter.flush(); document.close(); fos.close(); } catch (Exception e) { System.out.println("nnn"); JOptionPane.showMessageDialog(null, e.getMessage()); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e.toString()); } }
From source file:Metodos.PDF.java
public PDF(String route) { Document document = new Document(PageSize.A4); try {/* w ww.j a va 2 s . co m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(route + ".pdf")); document.open(); PdfContentByte contentByte = writer.getDirectContent(); //PdfTemplate template = contentByte.createTemplate(jPanel9.getWidth(), jPanel9.getHeight()); // Graphics2D g2 = template.createGraphics(jPanel9.getWidth(), jPanel9.getHeight()); // g2.scale(0.8, 0.8); //jPanel9.printAll(g2); // also tried with jp.paint(g2), same result // g2.dispose(); //document.close(); //contentByte.addTemplate(template, 25, -140); } catch (Exception e) { e.printStackTrace(); } finally { if (document.isOpen()) { document.close(); } } }
From source file:mhp_ph.PHprint.java
License:Open Source License
/** * Print articles as pdf//from ww w. j av a2 s . c o m * @param ll Articles * @param f Format * @param n Filename */ public static void printPdf(LinkedList<phArt> ll, format f, String n) { Document doc = new Document(PageSize.A4, 50, 50, 50, 50); try { PdfWriter pdf = PdfWriter.getInstance(doc, new FileOutputStream(n)); doc.addSubject("Przegld Historyczny"); doc.open(); BaseFont rr = BaseFont.createFont("FreeSerif.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); BaseFont ii = BaseFont.createFont("FreeSerifItalic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Font r = new Font(rr); Font i = new Font(ii); for (phArt a : ll) { Phrase p = new Phrase(); for (articleEntry e : formatArticle(a, f)) { switch (e.getStyle()) { case normal: { p.add(new Chunk(e.getString(), r)); break; } case italic: { p.add(new Chunk(e.getString(), i)); break; } } } doc.add(new Paragraph(p)); doc.add(new Paragraph("\n")); } doc.add(new Paragraph(" \n")); } catch (Exception e) { } doc.close(); }
From source file:Model.GerarRelatorio.java
public void init() { /*JFileChooser chooser = new JFileChooser(); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); } else {/*from w w w .j a v a 2 s. co m*/ System.out.println("No Selection "); } String saida = "\\RelatorioDiarioExecucao.pdf"; System.out.println(chooser.getSelectedFile() + saida); file = new File(chooser.getSelectedFile() + saida);*/ file = new File("C:\\Windows\\Temp\\" + relatorio.getNmRelatorio() + ".pdf"); file.delete(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { if (file.exists()) { file = new File("C:\\Windows\\Temp\\" + relatorio.getNmRelatorio() + "2.pdf"); } if (relatorio.getOrientacao().equalsIgnoreCase("Retrato")) { d = new Document(PageSize.A4); } else { d = new Document(PageSize.A4.rotate()); } paragrafos = new ArrayList<>(); tableHeader = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK); tableContent = new Font(FontFamily.TIMES_ROMAN, 10, Font.NORMAL, BaseColor.BLACK); dateHeader(); preencheVariaveis(); preencheNomeColuna(); preenche(); printPdf(); } catch (Exception e) { } } }); }
From source file:modelo.GeneratorPDF.java
public static void main(String[] args) { // criao do documento Document document = new Document(PageSize.A4, 72, 72, 72, 72); try {/*from w w w .j a v a 2 s. c o m*/ PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\Amanda\\Desktop\\teste.pdf")); document.open(); Font f = new Font(FontFamily.COURIER, 20, Font.BOLD); // adicionando um pargrafo no documento Paragraph p1 = new Paragraph("Gerando PDF - Java", f); p1.setAlignment(Element.ALIGN_CENTER); document.add(p1); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }
From source file:Modelo.RelatoriosBEAN.java
public static void relatorioCompras() throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();//from ww w. j a v a 2 s .com document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de Jogos Comprados </h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo</strong></th> " + "<th align=center><strong>Custo Unitrio</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor da Entrada</strong></th> " + "<th align=center><strong>Nmero de parcelas</strong></th> " + "<th align=center><strong>Preo Total</strong></th> " + "<th align=center><strong>Quantidade Compradra</strong></th> " + "<th align=center><strong>Caixa</strong></th> " + "<th align=center><strong>Jogo</strong></th> " + "</tr> "; for (NotaDecompraBEAN n : cNdc.listarALL()) { frase += "<tr align=center><td>" + n.getNdcCodigo() + "</td><td>" + n.getNdcCustoUnitario() + "</td><td>" + n.getNdcData() + "</td><td>" + n.getNdcEntrada() + "</td><td>" + n.getNdcParcelas() + "</td><td>" + n.getNdcPrecoTotal() + "</td><td>" + n.getNdcQtdComprada() + "</td><td>" + n.getCaixa().getCaixaCodigo() + "</td><td>" + n.getJogo().getJoNome() + "</td></tr>"; } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Modelo.RelatoriosBEAN.java
public static void relatorioContas() throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();//from ww w .j a v a 2 s . co m document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de Contas </h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo</strong></th> " + "<th align=center><strong>Data</strong></th> " + "<th align=center><strong>Valor da Entrada</strong></th> " + "<th align=center><strong>Nmero de parcelas</strong></th> " + "<th align=center><strong>Preo Total</strong></th> " + "<th align=center><strong>Descrio</strong></th> " + "<th align=center><strong>Fornecedor</strong></th> " + "<th align=center><strong>Caixa</strong></th> " + "</tr> "; for (ContaBEAN n : cContas.listarALL()) { frase += "<tr align=center><td>" + n.getConCodigo() + "</td><td>" + n.getConData() + "</td><td>" + n.getConEntrada() + "</td><td>" + n.getConNparcelas() + "</td><td>" + n.getConValorTotal() + "</td><td>" + n.getConDescricao() + "</td><td>" + n.getFornecedor().getForNomeEmpresa() + "</td><td>" + n.getCaixa().getCaixaCodigo() + "</td></tr>"; } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Modelo.RelatoriosBEAN.java
public static void relatorioMontanteVendedor() throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();// w w w .j ava2 s.com document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de montante por vendedor</h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo do funcionario</strong></th> " + "<th align=center><strong>Nome do funcionario</strong></th> " + "<th align=center><strong>Nmero de vendas</strong></th> " + "<th align=center><strong>Valor total das vendas</strong></th> " + "<th align=center><strong>Quantidade de alugueis</strong></th> " + "<th align=center><strong>Valor total de alugueis</strong></th> " + "<th align=center><strong>Montante Total</strong></th> " + "</tr> "; for (MontanteBEAN j : jDAO.montanteVendedor()) { frase += "<tr align=center><td>" + j.getFunCodigo() + "</td><td>" + j.getFunNome() + "</td><td>" + j.getnVendas() + "</td><td>" + j.getValorVendas() + "</td><td>" + j.getnAluguel() + "</td><td>" + j.getValorAluguel() + "</td><td>" + j.getValorTotal() + "</td></tr>"; } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Modelo.RelatoriosBEAN.java
public static void relatorioMontanteCliente() throws FileNotFoundException, DocumentException { String path = System.getProperty("user.home") + FRMEmitirRelatorios.local + ".pdf"; Document document = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(document, new FileOutputStream(path)); document.open();/*www.j a va2s . c o m*/ document.addAuthor("TechSales"); document.addCreator("TechSales"); document.addSubject("TechSales - Sistema de gerenciamento de locadoras"); document.addCreationDate(); document.addTitle("TechSales"); HTMLWorker htmlWorker = new HTMLWorker(document); String frase; try { frase = "<html>" + "<head> <meta charset=\"utf-8\"> </head>" + "<body>" + "<br/>" + "<h1 align=center>Relatrio de montante por cliente </h1>" + "<br/><br/>" + "<table BORDER RULES=rows border=0 style=\" width:100%; \">\n" + "<tr> " + "<th align=center><strong>Cdigo do cliente</strong></th> " + "<th align=center><strong>Nome do cliente</strong></th> " + "<th align=center><strong>Nmero de compras</strong></th> " + "<th align=center><strong>Valor total das compras</strong></th> " + "<th align=center><strong>Quantidade de alugueis</strong></th> " + "<th align=center><strong>Valor total de alugueis</strong></th> " + "<th align=center><strong>Montante Total</strong></th> " + "</tr> "; for (MontanteBEAN j : jDAO.montanteCliente()) { frase += "<tr align=center><td>" + j.getFunCodigo() + "</td><td>" + j.getFunNome() + "</td><td>" + j.getnVendas() + "</td><td>" + j.getValorVendas() + "</td><td>" + j.getnAluguel() + "</td><td>" + j.getValorAluguel() + "</td><td>" + j.getValorTotal() + "</td></tr>"; } frase += "</table>"; frase += "</body></html>"; htmlWorker.parse(new StringReader(frase)); document.close(); if (Desktop.isDesktopSupported()) { try { Desktop.getDesktop().open(new File(path)); } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } } } catch (Exception e) { e.printStackTrace(); } }