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:utils.PrintUtils.java
public static void printTrimestrialReportNote(Annee annee, Trimesteannee trimesteannee, Classe classe, ClasseElementevaluation classeElementevaluation, List<Eleveanneeclasse> eleveanneeclasses, List<Sequenceannee> sequenceannees, ClasseElementevaluationFacadeLocal classeElementevaluationFacadeLocal, PlanningEvaluationFacadeLocal planningEvaluationFacadeLocal, EvaluationFacadeLocal evaluationFacadeLocal) throws Exception { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); String fichier = "proces_verbal_note" + "_" + trimesteannee.getIdtrimestre().getNom() + "_" + classe.getNom() + ".pdf"; Document rapport = new Document(PageSize.A4.rotate()); PdfWriter.getInstance(rapport, new FileOutputStream( Utilitaires.path + "/" + Utilitaires.repertoireParDefaultNotesTrim + "/" + fichier)); rapport.open();//from w w w .j a va2 s . c om rapport.add(new Paragraph("Anne Scolaire : " + annee.getCode() + " / " + annee.getCodefin())); rapport.add(new Paragraph("Classe : " + classe.getNom())); rapport.add( new Paragraph("Unit Evaluation : " + classeElementevaluation.getElementevaluation().getNom())); rapport.add(new Paragraph("Priode : " + trimesteannee.getIdtrimestre().getNom())); rapport.add(new Paragraph(" ")); PdfPTable table = new PdfPTable(2 + sequenceannees.size()); table.setWidthPercentage(100); table.addCell(PrintUtils.createPdfPCell("PROCES VERBAL TRIMESTRIEL DES NOTES ", 2 + sequenceannees.size(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("ELEVES", 2, true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("NOTES", sequenceannees.size(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("MATRICULE", true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("NOM(S) ET PRENOM(S)", true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); for (Sequenceannee s : sequenceannees) { table.addCell(PrintUtils.createPdfPCell("" + s.getIdsequence().getNom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); } for (Eleveanneeclasse e : eleveanneeclasses) { table.addCell(PrintUtils.createPdfPCell("" + e.getEleve().getMatricule(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); table.addCell(PrintUtils.createPdfPCell("" + e.getEleve().getNom() + " " + e.getEleve().getPrenom(), true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); for (Sequenceannee s1 : sequenceannees) { String r = findNote1(e, s1, classeElementevaluation, classeElementevaluationFacadeLocal, planningEvaluationFacadeLocal, evaluationFacadeLocal); table.addCell(PrintUtils.createPdfPCell("" + r, true, new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL))); } } rapport.add(table); rapport.close(); }
From source file:view.GerarNotaFiscal.java
public GerarNotaFiscal() { Document document = new Document(); atributosMenuPrincipal novo = new atributosMenuPrincipal(); DAO dao = new DAO(); novo = dao.atualiza(null);// w w w . jav a2s .co m try { PdfWriter.getInstance(document, new FileOutputStream("notafiscal_id_" + novo.getId_venda() + ".pdf")); document.open(); document.setPageSize(PageSize.A4); Paragraph titulo = new Paragraph("Nota fiscal eletrnica - Serralheria Sousa"); titulo.setAlignment(400); Image logo = null; try { logo = Image.getInstance( "/media/diego/HD1/Documentos/Sistemas de Informao/5 Perodo/Programao Orientada a Objetos II/Dados/Serralheria Sousa/img1.png"); //logo.setAbsolutePosition(10, 10); } catch (BadElementException | IOException ex) { Logger.getLogger(GerarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex); } Paragraph dados = new Paragraph("" + "\nID da venda: " + novo.getId_venda() + "" + "\nProduto: " + novo.getProduto() + "" + "\nQuantidade do produto: " + novo.getQtd() + "" + "\nValor da venda: R$ " + novo.getValor_venda() + "" + "\nCliente: " + novo.getNome_cliente() + "\n\nData da venda: " + novo.getData() + "" + "\nVendedor: " + novo.getNome_usuario()); document.add(logo); document.add(titulo); document.add(new Paragraph("___________________________________________________________________")); document.add(dados); document.add( new Paragraph("\n\n\n___________________________________________________________________")); document.add(new Paragraph( "Serralheria Sousa LTDA - Todos os direitos reservados\n" + "\n" + "Rua Sinh Soido, 228\n" + "Bairro: Oeiras Nova Cidade: Oeiras\n" + "UF: PI\n" + "CEP: 64500-000\n" + "(89) 3462-2994" + "\n\nhttp://www.serralheriasousa.pe.hu senha: abacate")); //document.add(new ); } catch (FileNotFoundException | DocumentException ex) { System.out.println("Erro" + ex); } finally { document.close(); } try { Desktop.getDesktop().open(new File("notafiscal_id_" + novo.getId_venda() + ".pdf")); } catch (IOException ex) { Logger.getLogger(GerarNotaFiscal.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:view.PdfSalesReport.java
@Override public void printSalesCheckout() { Document document = new Document(PageSize.A4); try {//from ww w.j a va 2s.c o m PdfWriter.getInstance(document, new FileOutputStream("C:\\SalesReport.pdf")); document.open(); for (Order order : generics) { document.add( new Paragraph("================================= Order =================================")); document.add(new Paragraph("N Order: " + (order.getNumber() + 1) + " Name Customer: " + order.getCustomer().getName() + " Address: " + order.getCustomer().getAddress() + " Total Payment:" + order.getTotalOrderPayment())); document.add(new Paragraph( "--------------------------------- OrderItems --------------------------------- ")); for (OrderItem item : order.getItems()) { document.add(new Paragraph( "Products: " + item.getProduct().getName() + " Qt: " + item.getQuantity())); } document.add(new Paragraph("Sum Price Products: " + order.getSumPriceItems())); document.add( new Paragraph("-------------------------------------------------------------------------")); document.add( new Paragraph("=========================================================================")); } document.close(); } catch (FileNotFoundException ex) { Logger.getLogger(PdfSalesReport.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(PdfSalesReport.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:view.PrincipalView.java
public void gerarDocumento() throws IOException, DocumentException { doc = new Document(PageSize.A4.rotate()); String caminho = "C:/RelatoriosAgenda/Ficha.pdf"; PdfWriter.getInstance(doc, new FileOutputStream(caminho)); doc.open();/* www. ja va 2 s . c om*/ PdfPTable tabela = new PdfPTable(1); tabela.setHorizontalAlignment(Element.ALIGN_RIGHT); tabela.setWidthPercentage(100f); tabela.setTotalWidth(472); tabela.setLockedWidth(true); Paragraph pNome = new Paragraph("" + tfdNome.getText() + "\n" + tfdSobrenome.getText() + "\n \n"); pNome.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell colNome = new PdfPCell(pNome); tabela.addCell(colNome); doc.add(tabela); JOptionPane.showMessageDialog(null, "Relatrio de Funcionrios salvo com sucesso em C:/RelatoriosAgenda/"); Desktop.getDesktop().open(new File(caminho)); doc.close(); }
From source file:View.QuanLiMuonTra.java
private void xuatFile() { if (MuonTraTable.getSelectedRow() < 0) { JOptionPane.showMessageDialog(null, "Bn cha ch?n phiu mn!"); } else {//from w w w . ja va 2s . c o m String[] thongTinPhieuMuon = getNoiDungtuMuonTraGiaTable(); String TongTienPhat = getXtuTablemaY("sum(TienPhatTrenNgay*(NgayTra - NgayMuon))", "MuonTra m,ChiTietMuonTra c ", "(m.MaMuonTra = '" + thongTinPhieuMuon[0] + "' AND c.MaMuonTra = m.MaMuonTra AND c.NgayTra IS NOT NULL)")[0]; String tenDocGia = getXtuTablemaY("TenDocGia", "DocGia", "MaDocGia ='" + thongTinPhieuMuon[1] + "'")[0]; String[] tenCot = { "Tn Quyn", "M Quyn", "Ti?n Pht/Ngy", "Ngy Tr D Kin", "Ngy Tr" }; ; String title = "Phiu Mn Tr"; String fileName = "PhieuMuonTra"; String bf = "H? v tn : L Ng?c Long\n" + "MSSV : 20142659\n" + "?? ti : Xy dng chng trnh qun l th vin"; bf += "\n\nTr?ng ?i H?c Bch Khoa H Ni Cng Ha - X Hi - Ch Ngha - Vit Nam\n" + " Th vin T Quang Bu ?c Lp - T Do - Hnh Phc"; bf += "\n\n " + title.toUpperCase(); String kt = "\nM Mn Tr : " + thongTinPhieuMuon[0] + "\nTn ?c Gi : " + tenDocGia + "\nM ?c Gi : " + thongTinPhieuMuon[1] + "\nNgy Mn :" + thongTinPhieuMuon[2] + "\n?t C?c :" + thongTinPhieuMuon[3] + " (VN?)\nTng Ti?n Pht :" + TongTienPhat + " (VN?)\nGhi Ch :" + thongTinPhieuMuon[4] + "\n"; String af = "H Ni, Vit Nam Ngy " + Model.ThuVien.getTodayNgayThangNam() + "\n" + "Ng?i to bng : L Ng?c Long"; System.out.println(bf + kt); Model.ThuVien.xuatFilePDF2(fileName, bf + kt, tenCot, af, ChiTietMuonTraTable, title, PageSize.A4); } }
From source file:view.RelatorioDescricaoView.java
public void gerarDocumento() throws FileNotFoundException { try {//w w w . java 2 s .c om String descricao = tbeDescricao.getValueAt(tbeDescricao.getSelectedRow(), 0).toString(); listaPatrimonio = patrimonioDAO.listaTodosPorDescricao(descricao); doc = new Document(PageSize.A4, 41.5f, 41.5f, 55.2f, 55.2f); String caminho = "C:/Relatorios Descricao/Relatorio " + tbeDescricao.getValueAt(tbeDescricao.getSelectedRow(), 0).toString() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(caminho)); doc.open(); Font f1 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); Font f2 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font f3 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font f4 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font f5 = new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL); Paragraph titulo1 = new Paragraph("Universidade do Estado de Minas Gerais", f2); titulo1.setAlignment(Element.ALIGN_CENTER); titulo1.setSpacingAfter(10); Paragraph titulo2 = new Paragraph( "" + tbeDescricao.getValueAt(tbeDescricao.getSelectedRow(), 0).toString(), f2); titulo2.setAlignment(Element.ALIGN_CENTER); titulo2.setSpacingAfter(10); doc.add(titulo1); doc.add(titulo2); PdfPTable tabela = new PdfPTable(new float[] { 0.20f, 0.80f, 0.18f, 0.42f }); tabela.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.setWidthPercentage(100f); PdfPCell cabecalho1 = new PdfPCell(new Paragraph("Codigo", f3)); cabecalho1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho1.setBorder(0); PdfPCell cabecalho2 = new PdfPCell(new Paragraph("Sala", f3)); cabecalho2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho2.setBorder(0); PdfPCell cabecalho3 = new PdfPCell(new Paragraph("Estado", f3)); cabecalho3.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho3.setBorder(0); PdfPCell cabecalho4 = new PdfPCell(new Paragraph("Orgo", f3)); cabecalho4.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho4.setBorder(0); tabela.addCell(cabecalho1); tabela.addCell(cabecalho2); tabela.addCell(cabecalho3); tabela.addCell(cabecalho4); for (PatrimonioM patrimonio : listaPatrimonio) { Paragraph p1 = new Paragraph(patrimonio.getCodigo(), f5); p1.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col1 = new PdfPCell(p1); col1.setBorder(0); Paragraph p2 = new Paragraph(patrimonio.getSala().getDescricao(), f5); p2.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col2 = new PdfPCell(p2); col2.setBorder(0); Paragraph p3 = new Paragraph(patrimonio.getGrau_conservacao().getDescricao(), f5); p3.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col3 = new PdfPCell(p3); col3.setBorder(0); Paragraph p4 = new Paragraph(patrimonio.getEntidade().getNome(), f5); p4.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col4 = new PdfPCell(p4); col4.setBorder(0); tabela.addCell(col1); tabela.addCell(col2); tabela.addCell(col3); tabela.addCell(col4); } doc.add(tabela); doc.close(); JOptionPane.showMessageDialog(null, "Relatrio salvo com sucesso em C:/Relatorios Decricao/"); Desktop.getDesktop().open(new File(caminho)); } catch (DocumentException e) { e.printStackTrace(); } catch (SQLException ex) { ex.printStackTrace(); } catch (IOException exx) { exx.printStackTrace(); JOptionPane.showMessageDialog(null, "Documento de Relatorios aberto. Feche para gerar um novo."); } }
From source file:view.RelatorioSalaView.java
public void gerarDocumento() throws FileNotFoundException { try {/*from www . jav a2 s .co m*/ int numeroSala = Integer.parseInt(tbeSala.getValueAt(tbeSala.getSelectedRow(), 0).toString()); listaPatrimonio = patrimonioDAO.listaTodosSala(numeroSala); doc = new Document(PageSize.A4, 41.5f, 41.5f, 55.2f, 55.2f); String caminho = "C:/Relatorios Sala/Relatorio " + tbeSala.getValueAt(tbeSala.getSelectedRow(), 1).toString() + ".pdf"; PdfWriter.getInstance(doc, new FileOutputStream(caminho)); doc.open(); Font f1 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); Font f2 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font f3 = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); Font f4 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD); Font f5 = new Font(Font.FontFamily.HELVETICA, 10, Font.NORMAL); Paragraph titulo1 = new Paragraph("Universidade do Estado de Minas Gerais", f2); titulo1.setAlignment(Element.ALIGN_CENTER); titulo1.setSpacingAfter(10); Paragraph titulo2 = new Paragraph("" + tbeSala.getValueAt(tbeSala.getSelectedRow(), 1).toString(), f2); titulo2.setAlignment(Element.ALIGN_CENTER); titulo2.setSpacingAfter(10); doc.add(titulo1); doc.add(titulo2); PdfPTable tabela = new PdfPTable(new float[] { 0.20f, 0.80f, 0.18f, 0.42f }); tabela.setHorizontalAlignment(Element.ALIGN_CENTER); tabela.setWidthPercentage(100f); PdfPCell cabecalho1 = new PdfPCell(new Paragraph("Codigo", f3)); cabecalho1.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho1.setBorder(0); PdfPCell cabecalho2 = new PdfPCell(new Paragraph("Descrio", f3)); cabecalho2.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho2.setBorder(0); PdfPCell cabecalho3 = new PdfPCell(new Paragraph("Estado", f3)); cabecalho3.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho3.setBorder(0); PdfPCell cabecalho4 = new PdfPCell(new Paragraph("Orgo", f3)); cabecalho4.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); cabecalho4.setBorder(0); tabela.addCell(cabecalho1); tabela.addCell(cabecalho2); tabela.addCell(cabecalho3); tabela.addCell(cabecalho4); for (PatrimonioM patrimonio : listaPatrimonio) { if (patrimonio.getKit()) { listaComposto = patri.listaTodosExistentes(patrimonio); for (PatrimonioCompostoM composto : listaComposto) { Paragraph p1 = new Paragraph(patrimonio.getCodigo(), f5); p1.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col1 = new PdfPCell(p1); col1.setBorder(0); Paragraph p2 = new Paragraph(composto.getDescricao(), f5); p2.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col2 = new PdfPCell(p2); col2.setBorder(0); Paragraph p3 = new Paragraph(composto.getGrau().getDescricao(), f5); p3.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col3 = new PdfPCell(p3); col3.setBorder(0); Paragraph p4 = new Paragraph(patrimonio.getEntidade().getNome(), f5); p4.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col4 = new PdfPCell(p4); col4.setBorder(0); tabela.addCell(col1); tabela.addCell(col2); tabela.addCell(col3); tabela.addCell(col4); } } else { Paragraph p1 = new Paragraph(patrimonio.getCodigo(), f5); p1.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col1 = new PdfPCell(p1); col1.setBorder(0); Paragraph p2 = new Paragraph(patrimonio.getDescricao(), f5); p2.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col2 = new PdfPCell(p2); col2.setBorder(0); Paragraph p3 = new Paragraph(patrimonio.getGrau_conservacao().getDescricao(), f5); p3.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col3 = new PdfPCell(p3); col3.setBorder(0); Paragraph p4 = new Paragraph(patrimonio.getEntidade().getNome(), f5); p4.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell col4 = new PdfPCell(p4); col4.setBorder(0); tabela.addCell(col1); tabela.addCell(col2); tabela.addCell(col3); tabela.addCell(col4); } } doc.add(tabela); doc.close(); JOptionPane.showMessageDialog(null, "Relatrio salvo com sucesso em C:/Relatorios Sala/"); Desktop.getDesktop().open(new File(caminho)); } catch (DocumentException e) { e.printStackTrace(); } catch (SQLException ex) { ex.printStackTrace(); } catch (IOException exx) { exx.printStackTrace(); JOptionPane.showMessageDialog(null, "Documento de Relatorios aberto. Feche para gerar um novo."); } }
From source file:View.TelaRelatorio.java
public void GerarPDF() { Document documentoPDF = new Document(); try {/*from www .ja v a 2 s .com*/ PdfWriter.getInstance(documentoPDF, new FileOutputStream("C:\\Users\\Marilia Nayara\\Desktop\\PDFRelatorio.pdf")); documentoPDF.open(); documentoPDF.setPageSize(PageSize.A4); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD); Paragraph cabecalho = new Paragraph("Teste De SI", fonte); cabecalho.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(cabecalho); Image imagem = Image.getInstance( "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\src\\View\\imagem2.jpg"); imagem.scaleToFit(400, 300); documentoPDF.add(imagem); } catch (DocumentException de) { de.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { documentoPDF.close(); } }
From source file:View.TelaRelatorio.java
public void GerarEntrega(int codigo) throws IOException { NegociosCompra nc = new NegociosCompra(); Compra compra = nc.ConsultarCompra(codigo); Document documentoPDF = new Document(); String output = "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\Relatorios\\VendasEntrega\\Compra" + codigo + ".pdf"; try {/*from w ww. ja v a 2s .c o m*/ PdfWriter.getInstance(documentoPDF, new FileOutputStream(output)); documentoPDF.open(); documentoPDF.setPageSize(PageSize.A4); Image imagem = Image.getInstance( "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\src\\View\\image.png"); imagem.scaleToFit(100, 75); imagem.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(imagem); Font fonte1 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); Paragraph agr = new Paragraph("Aplicao para Gesto de Restaurantes", fonte1); agr.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(agr); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD); Paragraph cabecalho = new Paragraph("COMPRA ENTREGA", fonte); cabecalho.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(cabecalho); documentoPDF.add(new Paragraph("\n")); Cliente c = new NegociosCliente().ProcurarCliente(compra.getCpf_c()); Timestamp t = compra.getData(); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); String a = formato.format(t); PdfPTable dadosC = new PdfPTable(new float[] { 0.10f, 0.70f, 0.20f }); List<String> dados = new ArrayList<String>(); dados.add("CODIGO DA COMPRA"); dados.add("CLIENTE"); dados.add("DATA DA COMPRA"); dados.add("" + compra.getCodigo()); dados.add(c.getNome()); dados.add(a); for (String s : dados) { dadosC.addCell(s); } dadosC.setWidthPercentage(110f); documentoPDF.add(dadosC); documentoPDF.add(new Paragraph("\n")); /*documentoPDF.add(new Paragraph(" LISTA DE PRODUTOS COMPRADOS")); documentoPDF.add(new Paragraph("\n")); documentoPDF.add(new Paragraph("Codigo Produto Valor Unitrio Quantidade Valor ")); String tam = "Codigo Produto Valor Unitrio Quantidade Valor "; JOptionPane.showMessageDialog(null, tam.length()); for(int x=0;x<compra.getLista_prod().size();x++){ Produto p = new NegociosProduto().ProcurarProduto(compra.getLista_prod().get(x).intValue()); String cod = ""+p.getCodigo(); String nome = p.getNome(); float pv = p.getPvenda(); String pvs = ""+pv; int quant = compra.getQuantidades().get(x).intValue(); String squant = ""+quant; float pf = pv*quant; String spf = ""+pf; int espaco = 13 - cod.length(); String esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } cod = cod+esp; espaco = 49 - nome.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } nome = nome + esp; espaco = 24 - pvs.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } pvs = pvs + esp; espaco = 23 - squant.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } squant = squant + esp; espaco = 8 - spf.length(); esp = ""; for(int y = 0;y <espaco;y++){ esp=esp+" "; } spf = spf + esp; String fina = cod+nome+pvs+squant+spf; //JOptionPane.showMessageDialog(null, fina.length()); documentoPDF.add(new Paragraph(fina)); }*/ Font fonte3 = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL); // Criando uma tabela com 3 colunas PdfPTable table = new PdfPTable(new float[] { 0.1f, 0.45f, 0.15f, 0.15f, 0.15f }); table.setWidthPercentage(110.f); // Ttulo para a tabela Paragraph tableHeader = new Paragraph("LISTA DE PRODUTOS COMPRADOS", fonte3); PdfPCell header = new PdfPCell(tableHeader); // Definindo que o header vai ocupar as 3 colunas header.setColspan(5); // Definindo alinhamento do header header.setHorizontalAlignment(Paragraph.ALIGN_CENTER); // Adicionando o header tabela table.addCell(header); List<String> list = new ArrayList<String>(); list.add("CODIGO"); list.add("PRODUTO"); list.add("VALOR UNIT?RIO"); list.add("QUANTIDADE"); list.add("VALOR"); for (int x = 0; x < compra.getLista_prod().size(); x++) { Produto p = new NegociosProduto().ProcurarProduto(compra.getLista_prod().get(x).intValue()); String cod = "" + p.getCodigo(); String nome = p.getNome(); float pv = p.getPvenda(); String pvs = "" + pv; int quant = compra.getQuantidades().get(x).intValue(); String squant = "" + quant; float pf = pv * quant; String spf = "" + pf; list.add(cod); list.add(nome); list.add(pvs); list.add(squant); list.add(spf); } for (String s : list) { table.addCell(s); } documentoPDF.add(table); documentoPDF.add(new Paragraph("\n")); Paragraph total = new Paragraph("Total: " + compra.getPreco_final(), fonte3); total.setAlignment(Element.ALIGN_RIGHT); documentoPDF.add(total); documentoPDF.add(new Paragraph("\n")); PdfPTable endereco = new PdfPTable(new float[] { 0.30f, 0.80f }); endereco.setWidthPercentage(60f); endereco.setHorizontalAlignment(Element.ALIGN_CENTER); Paragraph tableH = new Paragraph("ENDEREO DE ENTREGA", fonte3); PdfPCell hea = new PdfPCell(tableH); hea.setColspan(2); hea.setHorizontalAlignment(Paragraph.ALIGN_CENTER); endereco.addCell(hea); List<String> dadosE = new ArrayList<String>(); dadosE.add("LOGRADOURO"); dadosE.add(c.getEndereco().getRua()); dadosE.add("NUMERO"); dadosE.add("" + c.getEndereco().getNumero()); dadosE.add("BAIRRO"); dadosE.add(c.getEndereco().getBairro()); dadosE.add("CIDADE"); dadosE.add(c.getEndereco().getCidade()); dadosE.add("ESTADO"); dadosE.add(c.getEndereco().getEstado()); for (String s : dadosE) { endereco.addCell(s); } documentoPDF.add(endereco); documentoPDF.add(new Paragraph("\n")); documentoPDF .add(new Paragraph("Assinatura: __________________________________________________________")); Paragraph ass = new Paragraph("(" + c.getNome() + ")", fonte1); ass.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(ass); documentoPDF.add(new Paragraph( "----------------------------------------------------------------------------------------------------------------------------------")); Paragraph comp = new Paragraph("COMPROVANTE DE ENTREGA"); comp.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(comp); documentoPDF.add(new Paragraph("\n")); documentoPDF.add(dadosC); documentoPDF.add(total); documentoPDF .add(new Paragraph("Assinatura: __________________________________________________________")); documentoPDF.add(ass); } catch (DocumentException de) { de.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { documentoPDF.close(); java.awt.Desktop.getDesktop().open(new File(output)); } }
From source file:View.TelaRelatorio.java
public void GerarVendidosSemana(String inicio, String Final) throws FileNotFoundException, BadElementException, IOException { NegocioRelatorio nr = new NegocioRelatorio(); Document documentoPDF = new Document(); String nome = inicio.toString(); String comp = Final.toString(); String output = "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\Relatorios\\MaisVendidos\\MVdia.pdf"; try {/*from ww w . j a va 2 s . co m*/ PdfWriter.getInstance(documentoPDF, new FileOutputStream(output)); documentoPDF.open(); documentoPDF.setPageSize(PageSize.A4); Image imagem = Image.getInstance( "C:\\Users\\Marilia Nayara\\Documents\\NetBeansProjects\\SistemaInformao\\src\\View\\image.png"); imagem.scaleToFit(100, 75); imagem.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(imagem); Font fonte1 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD); Paragraph agr = new Paragraph("Aplicao para Gesto de Restaurantes", fonte1); agr.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(agr); Font fonte = new Font(Font.FontFamily.TIMES_ROMAN, 24, Font.BOLD); Paragraph cabecalho = new Paragraph("MAIS VENDIDAS DA SEMANA", fonte); cabecalho.setAlignment(Element.ALIGN_CENTER); documentoPDF.add(cabecalho); documentoPDF.add(new Paragraph("\n")); List<MaisVendidos> mv = nr.MaisVendidos(inicio, Final); System.out.println("voltou"); SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy"); List<Timestamp> gamb = new ArrayList<Timestamp>(); String aux; String aux1; for (int j = 0; j < mv.size(); j++) { int gam = 0; Date d = new Date(mv.get(j).getData().getTime()); aux = formato.format(d); for (int i = 0; i < gamb.size(); i++) { aux1 = formato.format(gamb.get(i).getTime()); if (aux.equals(aux1)) { gam = 1; System.out.println("entroy aki"); } } if (gam == 0) { gamb.add(mv.get(j).getData()); System.out.println(j); String a = formato.format(mv.get(j).getData()); Calendar cal = Calendar.getInstance(); cal.setTime(mv.get(j).getData());// ========> Objeto Date int day = cal.get(Calendar.DAY_OF_WEEK); Paragraph dia = new Paragraph(); if (day == 1) { dia = new Paragraph("DOMINGO " + a); } else if (day == 2) { dia = new Paragraph("SEGUNDA-FEIRA " + a); } else if (day == 3) { dia = new Paragraph("TERA-FEIRA " + a); } else if (day == 4) { dia = new Paragraph("QUARTA-FEIRA " + a); } else if (day == 5) { dia = new Paragraph("QUINTA-FEIRA " + a); } else if (day == 6) { dia = new Paragraph("SEXTA-FEIRA " + a); } else if (day == 7) { dia = new Paragraph("SABADO " + a); } documentoPDF.add(dia); documentoPDF.add(new Paragraph("\n")); PdfPTable dadosC = new PdfPTable(new float[] { 0.30f, 0.50f, 0.15f, 0.15f }); List<String> dados = new ArrayList<String>(); dados.add("CATEGORIA"); dados.add("PRODUTO"); dados.add("QUANTIDADE"); dados.add("VALOR"); List<String> categorias = new ArrayList<String>(); for (int x = 0; x < mv.size(); x++) { String aux2 = formato.format(mv.get(x).getData().getTime()); int contc = 0; System.out.println(aux); System.out.println(aux2); if (aux.equals(aux2)) { Categoria c = new NegociosCategoria().ProcurarCategoria(mv.get(x).getIdent()); for (int k = 0; k < categorias.size(); k++) { if (c.getNome().equals(categorias.get(k).toString())) { contc = 1; } } if (contc == 0) { categorias.add(c.getNome()); dados.add(c.getNome()); Produto p = new NegociosProduto().ProcurarProduto(mv.get(x).getCodigo()); dados.add(p.getNome()); dados.add("" + mv.get(x).getQuantidade()); double valor = mv.get(x).getQuantidade() * mv.get(x).getPtotal(); dados.add("" + valor); } } } for (String s : dados) { dadosC.addCell(s); } dadosC.setWidthPercentage(110f); documentoPDF.add(dadosC); } } } catch (DocumentException de) { de.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { documentoPDF.close(); java.awt.Desktop.getDesktop().open(new File(output)); } }