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:Export.SeguroViagem.java
public String criarDoc(ViagemBean vb, String numCriente, String user, String arquivo, Contrato c) { try {/* w w w. j a va 2s . c o m*/ PdfPTable pTablePrincaipal; // PdfPTable pTableSegu1; PdfPTable pTableSegu2; SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); SimpleDateFormat sdfPot = new SimpleDateFormat("dd/MM/yyyy"); Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.9f); Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.9f); // PdfPTable pTableLinha = new PdfPTable(1); // pTableLinha.setWidthPercentage(95); // PdfPCell linha= new PdfPCell(new Phrase(" ")); // // linha.setBorderWidthTop(0.5f); // linha.setBorderWidthBottom(0); // linha.setBorderWidthLeft(0); // linha.setBorderWidthRight(0); // pTableLinha.addCell(linha); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 138f, 5f); File ff = new File(arquivo + "/" + user + "/Seguro Viagem/"); ff.mkdirs(); String Ddata = sdf.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Doc Seguro Viagem " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro Viagem/" + "Doc Seguro Viagem " + Ddata + ".pdf"; outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); if (MarcaDAgua.isSimulation) { MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical(); writer.setPageEvent(v); } if (MarcaDAgua.isCanceled) { MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical(); writer.setPageEvent(v); } documento.open(); int total = vb.getInfoPessoaSegurada().size(); for (int i = 0; i < total; i++) { pTablePrincaipal = new PdfPTable(1); pTablePrincaipal.setWidthPercentage(98f); // pTableSegu1 = new PdfPTable(1); // pTableSegu1.setWidthPercentage(95); pTableSegu2 = new PdfPTable(new float[] { 55f, 45f }); pTableSegu2.setWidthPercentage(100f); // PdfPCell cellTitulo= new PdfPCell(new Phrase("Lista Pessoas Seguradas",fontCabecalhoN)); // cellTitulo.setBorder(0); PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo)); cellNull.setBorder(0); // if(((i)%6)==0) // { // pTableSegu1.addCell(cellTitulo); // pTableSegu1.addCell(cellNull); // } // Paragraph pCl = new Paragraph(); pCl.add(new Phrase("Nome do Segurado: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNomePessoaSegurada().toUpperCase(), fontCorpoN)); PdfPCell cellNome = new PdfPCell(pCl); cellNome.setColspan(2); cellNome.setBorder(0); pTableSegu2.addCell(cellNome); // PdfPCell cellNum= new PdfPCell(new Phrase(""+(i+1),fontCorpo)); // cellNum.setBorder(0); // cellNum.setHorizontalAlignment(Element.ALIGN_RIGHT); // pTableSegu2.addCell(cellNum); pCl = new Paragraph(); pCl.add(new Phrase("Endereo: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getEndereco().toUpperCase(), fontCorpoN)); PdfPCell cellEndereco = new PdfPCell(pCl); cellEndereco.setBorder(0); pTableSegu2.addCell(cellEndereco); pTableSegu2.addCell(cellNull); pCl = new Paragraph(); pCl.add(new Phrase("Data e Local Nascimento: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getDataNascFormatada(), fontCorpoN)); pCl.add(new Phrase(" em ", fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getLocalNascimento(), fontCorpoN)); PdfPCell cellNascDaNascloc = new PdfPCell(pCl); cellNascDaNascloc.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase("Sexo: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getSexo(), fontCorpoN)); pCl.add(new Phrase(" Tel.N ", fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getTelefone(), fontCorpoN)); PdfPCell cellSexo = new PdfPCell(pCl); cellSexo.setBorder(0); pTableSegu2.addCell(cellNascDaNascloc); pTableSegu2.addCell(cellSexo); pCl = new Paragraph(); pCl.add(new Phrase("Apolice: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumApolice(), fontCorpoN)); PdfPCell cellApolice = new PdfPCell(pCl); cellApolice.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase("Cliente: ".toUpperCase(), fontCorpo)); String[] codCliente = vb.getInfoPessoaSegurada().get(i).getNumApolice().split("/"); pCl.add(new Phrase(((codCliente.length == 2) ? "TIN " + codCliente[1] : "TIN "), fontCorpoN)); PdfPCell cellCliente = new PdfPCell(pCl); cellCliente.setBorder(0); pTableSegu2.addCell(cellApolice); pTableSegu2.addCell(cellCliente); pCl = new Paragraph(); pCl.add(new Phrase("Durao: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumDias() + " DIAS", fontCorpoN)); PdfPCell cellDuracao = new PdfPCell(pCl); cellDuracao.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase("Perodo: de ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(sdfPot.format(vb.getInfoPessoaSegurada().get(i).getDataInicio()), fontCorpoN)); pCl.add(new Phrase(" ", fontCorpo)); pCl.add(new Phrase(((vb.getInfoPessoaSegurada().get(i).getDataFim() != null) ? sdfPot.format(vb.getInfoPessoaSegurada().get(i).getDataFim()) : " "), fontCorpoN)); PdfPCell cellPeriodo = new PdfPCell(pCl); cellPeriodo.setBorder(0); pTableSegu2.addCell(cellDuracao); pTableSegu2.addCell(cellPeriodo); pCl = new Paragraph(); pCl.add(new Phrase("Data de Emisso: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(sdfPot.format(c.getDataContrato()), fontCorpoN)); PdfPCell cellDataEmissao = new PdfPCell(pCl); cellDataEmissao.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase("Destino: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase( ClienteDao.paisesSelected(vb.getInfoPessoaSegurada().get(i).getPaisDestino().toUpperCase()) + " ", fontCorpoN)); pCl.add(new Phrase("N de Pessoas: ", fontCorpo)); pCl.add(new Phrase((i + 1) + "", fontCorpoN)); PdfPCell cellDestino = new PdfPCell(pCl); cellDestino.setBorder(0); pTableSegu2.addCell(cellDataEmissao); pTableSegu2.addCell(cellDestino); pCl = new Paragraph(); pCl.add(new Phrase("Meio de Identificao: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase( ((vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase().equals("PASSAPORTE")) ? "PASS" : (vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase() .equals("BILHETE IDENTIDADE") ? "BI" : vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase())), fontCorpoN)); pCl.add(new Phrase(" N ", fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumDoc(), fontCorpoN)); PdfPCell cellEmiDocNum = new PdfPCell(pCl); cellEmiDocNum.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase("Emitido em: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getLocalEmissao().toUpperCase() + " ", fontCorpoN)); pCl.add(new Phrase("em ", fontCorpo)); pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getDataEmissaoFormatada(), fontCorpoN)); PdfPCell cellEmiDoc = new PdfPCell(pCl); cellEmiDoc.setBorder(0); pTableSegu2.addCell(cellEmiDocNum); pTableSegu2.addCell(cellEmiDoc); pCl = new Paragraph(); pCl.add(new Phrase("Outras Informaes: ".toUpperCase(), fontCorpo)); pCl.add(new Phrase( ((vb.getInfoPessoaSegurada().get(i).getOutrasInformacoes() == null) ? " " : vb.getInfoPessoaSegurada().get(i).getOutrasInformacoes().toUpperCase()), fontCorpoN)); PdfPCell cellOutraInf = new PdfPCell(pCl); cellOutraInf.setColspan(2); cellOutraInf.setBorder(0); pTableSegu2.addCell(cellOutraInf); // PdfPCell cellSegui1 = new PdfPCell(); // cellSegui1.addElement(pTableSegu1); // cellSegui1.setBorder(0); PdfPCell cellSegui2 = new PdfPCell(); cellSegui2.addElement(pTableSegu2); cellSegui2.setBorder(0); // PdfPCell cellSeguiT = new PdfPCell(); // cellSeguiT.addElement(pTableLinha); // cellSeguiT.setBorder(0); // pTablePrincaipal.addCell(cellSegui1); pTablePrincaipal.addCell(cellSegui2); // if((i+1)<total&&((i+1)%6)!=0) // pTablePrincaipal.addCell(cellSeguiT); // documento.add(pTablePrincaipal); // // System.err.println((((i+1)%6)==0)+" "+(i+1)); if ((i + 1) != total) { documento.newPage(); } } documento.close(); return reString; } catch (DocumentException | IOException ex) { Logger.getLogger(SeguroViagem.class.getName()).log(Level.SEVERE, null, ex); return reString; } }
From source file:Export.SeguroViatura.java
public String criarDoc(String numApolice, String numCliente, Contrato c, VeiculoBean vb, String user, String arquivo) {//w ww. j av a 2 s .c o m try { SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss"); Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10.5f); Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoTabT = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6.5f); Font fontCorpoTab = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6.5f); Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f); Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f); Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f); Font fontCorpoNGT = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f); Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f, Font.UNDERLINE); Font fontUK = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f, Font.ITALIC); Font fontUKb = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f, Font.ITALIC); PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f }); pTableEmpresaPricipal.setWidthPercentage(88f); PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1); // PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1); PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1); PdfPTable pTableNull = new PdfPTable(1); PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo)); cellNull.setBorder(0); pTableNull.addCell(cellNull); PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(Empresa.NOME, fontCabecalhoNG)); pCellNomeEmpresa.setBorder(0); PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(Empresa.ENDERECO, fontCabecalhoN)); pCellNomeEndereco.setBorder(0); PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(Empresa.CAIXAPOSTAL, fontCabecalhoN)); pCellCaixaPostal.setBorder(0); PdfPCell pCellTeleFax = new PdfPCell( new Phrase(Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN)); pCellTeleFax.setBorder(0); PdfPCell pCellSociedade = new PdfPCell(new Phrase(Empresa.SOCIEDADE, fontCabecalhoN)); pCellSociedade.setBorder(0); PdfPCell pCellPolice = new PdfPCell(new Phrase(Empresa.APOLICE + numApolice, fontCabecalhoN)); pCellPolice.setBorder(0); Image imageEmpresa = Image.getInstance("logo.png"); imageEmpresa.scaleToFit(190f, 100f); pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa); pTableEmpresaInforImpres1.addCell(pCellNomeEndereco); pTableEmpresaInforImpres1.addCell(pCellCaixaPostal); pTableEmpresaInforImpres1.addCell(pCellTeleFax); pTableEmpresaInforImpres1.addCell(pCellSociedade); pTableEmpresaInforImpres1.addCell(pCellPolice); PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1); cellTabela3.setBorder(0); pTableEmpresaInforImpres5.addCell(cellTabela3); PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5); cellTabela5.setBorder(0); PdfPCell cellTabela6 = new PdfPCell(imageEmpresa); cellTabela6.setBorder(0); pTableEmpresaPricipal.addCell(cellTabela6); pTableEmpresaPricipal.addCell(cellTabela5); PdfPTable pTableSeguro = new PdfPTable(1); pTableSeguro.setWidthPercentage(88f); PdfPTable pTableCliente = new PdfPTable(1); pTableCliente.setWidthPercentage(88f); PdfPTable pTableTitulo = new PdfPTable(1); pTableTitulo.setWidthPercentage(88f); Paragraph paTitulo = new Paragraph(); Paragraph pTitulo = new Paragraph("resumo de aplice para Automvel".toUpperCase(), fontCorpoNGT); Paragraph pTituloUk = new Paragraph("\nthe motor policy sumay".toUpperCase(), fontUKb); paTitulo.add(pTitulo); paTitulo.add(pTituloUk); PdfPCell cellTitulo = new PdfPCell(paTitulo); cellTitulo.setBorder(0); cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER); pTableTitulo.addCell(cellTitulo); ClienteI ci = new ClienteI(numCliente); Paragraph para = new Paragraph(); Paragraph phrase = new Paragraph("1 - Informaes Do Cliente".toUpperCase(), fontCorpoNG); Paragraph paraUK = new Paragraph("\n1 - Customer information".toUpperCase(), fontUKb); para.add(phrase); para.add(paraUK); PdfPCell cellTituloTsbleSegurado = new PdfPCell(para); cellTituloTsbleSegurado.setBorder(0); Paragraph pCl = new Paragraph(); pCl.add(new Phrase(ci.getNOMEL_(), fontCorpo)); pCl.add(new Phrase(ci.getNOME_(), fontCorpoN)); pCl.add(new Phrase("\nNAME:", fontUK)); PdfPCell cellNome = new PdfPCell(new Phrase(pCl)); cellNome.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase(ci.getENDERECOL_(), fontCorpo)); pCl.add(new Phrase(ci.getENDERECO_(), fontCorpoN)); pCl.add(new Phrase("\nADDRESS:", fontUK)); PdfPCell cellEndereco = new PdfPCell(pCl); cellEndereco.setBorder(0); /** pCl = new Paragraph(); pCl.add(new Phrase(" " +ci.getNUNCLIENTEL_(),fontCorpo)); pCl.add(new Phrase(ci.getNUNCLIENTE_(),fontCorpoN)); PdfPCell cellNCliente = new PdfPCell( pCl ); cellNCliente.setBorder(0); * */ pCl = new Paragraph(); pCl.add(new Phrase(ci.getPROFISSAOL_(), fontCorpo)); pCl.add(new Phrase(ci.getPROFISSAO_(), fontCorpoN)); pCl.add(new Phrase("\nPROFISSION/OCCUPATION/ACTIVITY AREA:", fontUK)); PdfPCell cellProfissao = new PdfPCell(pCl); cellProfissao.setBorder(0); pCl = new Paragraph(); pCl.add(new Phrase(ci.getLOCALTRABALHOL_(), fontCorpo)); pCl.add(new Phrase(ci.getLOCALTRABALHO_(), fontCorpoN)); pCl.add(new Phrase("\nPLACE OF WORK", fontUK)); PdfPCell cellLocalTrabalho = new PdfPCell(pCl); cellLocalTrabalho.setBorder(0); cellNome.setPaddingTop(7f); cellNome.setPaddingBottom(7f); cellNome.setBorder(0); cellEndereco.setPaddingTop(7f); cellEndereco.setPaddingBottom(7f); cellEndereco.setBorder(0); // PdfPCell cellNCliente= new PdfPCell( new Phrase(" "+ci.getNUNCLIENTE(),fontCorpo));cellNome.setPaddingTop(5f); // cellNCliente.setPaddingTop(7f); // cellNCliente.setPaddingBottom(7f); // cellNCliente.setBorder(0); cellProfissao.setPaddingTop(7f); cellProfissao.setPaddingBottom(7f); cellProfissao.setBorder(0); cellLocalTrabalho.setPaddingTop(7f); cellLocalTrabalho.setPaddingBottom(7f); cellLocalTrabalho.setBorder(0); pTableCliente.addCell(cellTituloTsbleSegurado); pTableCliente.addCell(cellNome); pTableCliente.addCell(cellEndereco); // pTableCliente.addCell(cellNCliente); pTableCliente.addCell(cellProfissao); pTableCliente.addCell(cellLocalTrabalho); para = new Paragraph(); Paragraph p = new Paragraph("3 - Premio E Cobertura".toUpperCase(), fontCorpoNG); Paragraph p1 = new Paragraph("\n3 - PREMIUM AND COVER".toUpperCase(), fontUKb); para.add(p); para.add(p1); PdfPCell cellTiltuloSegro = new PdfPCell(para); cellTiltuloSegro.setPaddingTop(7f); cellTiltuloSegro.setPaddingBottom(7f); cellTiltuloSegro.setBorder(0); // PdfPCell cellApolice= new PdfPCell( new Phrase(" N Aplice: ".toUpperCase()+numApolice,fontCorpo)); // cellApolice.setPaddingTop(7f); // cellApolice.setPaddingBottom(7f); // cellApolice.setBorder(0); Paragraph pTotalSegurado = new Paragraph(); pTotalSegurado.add(new Phrase("Prmio: ".toUpperCase().toUpperCase(), fontCorpo)); /** * * * ildo - premio liquido -> */ pTotalSegurado.add(new Phrase( ((c.getPremioLiquidoMoeda() == null /*&& vb.getVeiculo().getTipoCobertura().equals("41") */ ) ? " " : c.getPremioLiquidoMoeda() + " " + c.getSigla()), fontCorpoN)); pTotalSegurado.add(new Phrase("\nPREMIUM", fontUK)); PdfPCell cellTotalSegurado = new PdfPCell(pTotalSegurado); cellTotalSegurado.setPaddingTop(7f); cellTotalSegurado.setPaddingBottom(7f); cellTotalSegurado.setBorder(0); Paragraph pExcesso = new Paragraph(); pExcesso.add(new Phrase("Excesso: ".toUpperCase(), fontCorpo)); pExcesso.add(new Phrase((c.getFranquia() == null) ? "No aplicvel".toUpperCase() : c.getFranquia(), fontCorpoN)); pExcesso.add(new Phrase("\nEXCESS: ", fontUK)); PdfPCell cellExcesso = new PdfPCell(pExcesso); cellExcesso.setPaddingTop(7f); cellExcesso.setPaddingBottom(7f); cellExcesso.setBorder(0); // PdfPCell cellValor1Preminio= new PdfPCell( new Phrase(" Valor Primeiro Premio: ".toUpperCase()+((c.getPrimeiroPremio()==null)?" ":c.getPrimeiroPremio()),fontCorpo)); // cellValor1Preminio.setPaddingTop(7f); // cellValor1Preminio.setPaddingBottom(7f); // cellValor1Preminio.setBorder(0); // // PdfPCell cellTotalPremioAnual= new PdfPCell( new Phrase(" Valor Premio Anual: ".toUpperCase()+((c.getPremioAnual()==null)?" ":c.getPremioAnual()),fontCorpo)); // cellTotalPremioAnual.setPaddingTop(7f); // cellTotalPremioAnual.setPaddingBottom(7f); // cellTotalPremioAnual.setBorder(0); // PdfPCell cellPeriodo= new PdfPCell( new Phrase(" Periodo Do Seguro: ".toUpperCase()+((c.getDataInicio()!= null) ? sdf.format(c.getDataInicio()): " " )+" "+((c.getDataFim()!= null) ? sdf.format(c.getDataFim()): " " ),fontCorpo)); // cellPeriodo.setPaddingTop(7f); // cellPeriodo.setPaddingBottom(7f); // cellPeriodo.setBorder(0) Paragraph pDataRenovacao = new Paragraph(); pDataRenovacao.add(new Phrase("Data Renovao de Seguro: ".toUpperCase(), fontCorpo)); pDataRenovacao.add(new Phrase(((c.getDataRenovacao() != null) ? sdf.format(c.getDataRenovacao()) : " "), fontCorpoN)); pDataRenovacao.add(new Phrase("\nRENEWAL DATE OF COVER", fontUK)); PdfPCell cellDataRenovacao = new PdfPCell(pDataRenovacao); cellDataRenovacao.setPaddingTop(7f); cellDataRenovacao.setPaddingBottom(7f); cellDataRenovacao.setBorder(0); Paragraph pTipoCobert = new Paragraph(); pTipoCobert.add(new Phrase("Tipo De Cobertura: ".toUpperCase(), fontCorpo)); pTipoCobert .add(new Phrase( ((vb.getVeiculo().getTipoCobertura() != null) ? (vb.getVeiculo().getTipoCobertura().equals("41") ? "Contra Terceiros".toUpperCase() : (vb.getVeiculo().getTipoCobertura().equals("42") ? "CONTRA Todos os riscos".toUpperCase() : (vb.getVeiculo().getTipoCobertura().equals("43") ? "Compreensivo limitado".toUpperCase() : vb.getVeiculo().getTipoCobertura()))) : " "), fontCorpoN)); pTipoCobert.add(new Phrase("\nTYPE OF CAVER", fontUK)); PdfPCell cellTipoCobert = new PdfPCell(pTipoCobert); cellTipoCobert.setPaddingTop(7f); cellTipoCobert.setPaddingBottom(7f); cellTipoCobert.setBorder(0); Paragraph pLimiteArea = new Paragraph(); pLimiteArea.add(new Phrase("Limite de rea geogrfica: ".toUpperCase(), fontCorpo)); pLimiteArea.add(new Phrase("so Tom e principe".toUpperCase(), fontCorpoN)); pLimiteArea.add(new Phrase("\nLIMIT OF GEOGRAPHICAL AREA".toUpperCase(), fontUK)); PdfPCell cellLimiteArea = new PdfPCell(pLimiteArea); cellLimiteArea.setPaddingTop(7f); cellLimiteArea.setPaddingBottom(7f); cellLimiteArea.setBorder(0); Paragraph pLeis = new Paragraph(); pLeis.add(new Phrase("legislao: ".toUpperCase(), fontCorpo)); pLeis.add(new Phrase("artigos 1 36, lei n 30/2000 da repblica democrtica de stp".toUpperCase(), fontCorpoN)); pLeis.add(new Phrase("\nLEGISLATION: ", fontUK)); pLeis.add(new Phrase("ARTICLES 1 TO 36, LAW NO 30/2000 OF THE DEMOCRATIC REPUBLIC OF STP", fontUKb)); PdfPCell cellLeis = new PdfPCell(pLeis); cellLeis.setPaddingTop(7f); cellLeis.setPaddingBottom(7f); cellLeis.setBorder(0); pTableSeguro.addCell(cellTiltuloSegro); // pTableSeguro.addCell(cellApolice); pTableSeguro.addCell(cellTotalSegurado); // pTableSeguro.addCell(cellValor1Preminio); // pTableSeguro.addCell(cellTotalPremioAnual); pTableSeguro.addCell(cellExcesso); pTableSeguro.addCell(cellDataRenovacao); pTableSeguro.addCell(cellTipoCobert); pTableSeguro.addCell(cellLimiteArea); pTableSeguro.addCell(cellLeis); PdfPTable pTableDadosTitulo = new PdfPTable(1); pTableDadosTitulo.setWidthPercentage(88f); para = new Paragraph(); Phrase PDadosTitulo = new Phrase("2 - Informaes do(s) Veculo(s)".toUpperCase(), fontCorpoN); Phrase PDadosTitulos = new Phrase("\n2 - VEHICLE (S) INFORMATIONS".toUpperCase(), fontUKb); para.add(PDadosTitulo); para.add(PDadosTitulos); PdfPCell cellDadosTitulo = new PdfPCell(para); cellDadosTitulo.setBorder(0); pTableDadosTitulo.addCell(cellDadosTitulo); pTableDadosTitulo.addCell(cellNull); PdfPTable pTableDados = new PdfPTable(new float[] { 13.5f, 13.5f, 14, 17, 16, 12, 14 }); pTableDados.setWidthPercentage(88f); para = new Paragraph(); Phrase PMarca = new Phrase("Marca".toUpperCase(), fontCorpoTabT); Phrase PMarcaUK = new Phrase("\nMARK".toUpperCase(), fontUK); para.add(PMarca); para.add(PMarcaUK); PdfPCell cellMarca = new PdfPCell(para); cellMarca.setPaddingTop(5f); cellMarca.setPaddingBottom(5f); cellMarca.setHorizontalAlignment(Element.ALIGN_CENTER); para = new Paragraph(); Paragraph PModelo = new Paragraph("Modelo".toUpperCase(), fontCorpoTabT); Paragraph PModeloUK = new Paragraph("\nMODEL".toUpperCase(), fontUK); para.add(PModelo); para.add(PModeloUK); PdfPCell cellModelo = new PdfPCell(para); cellModelo.setHorizontalAlignment(Element.ALIGN_CENTER); cellModelo.setPaddingTop(5f); cellModelo.setPaddingBottom(5f); para = new Paragraph(); Phrase PMatricula = new Phrase("NO DE MATR?CULA".toUpperCase(), fontCorpoTabT); Phrase PMatriculaUK = new Phrase("\nREG. NUMBER".toUpperCase(), fontUK); para.add(PMatricula); para.add(PMatriculaUK); PdfPCell cellMatricula = new PdfPCell(para); cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER); cellMatricula.setPaddingTop(5f); cellMatricula.setPaddingBottom(5f); para = new Paragraph(); Phrase PChasii = new Phrase("No. de chissi/Motor".toUpperCase(), fontCorpoTabT); Phrase PChasiiUK = new Phrase("\nchissiS/ENGINE NO.".toUpperCase(), fontUK); para.add(PChasii); para.add(PChasiiUK); PdfPCell cellChasii = new PdfPCell(para); cellChasii.setHorizontalAlignment(Element.ALIGN_CENTER); cellChasii.setPaddingTop(5f); cellChasii.setPaddingBottom(5f); para = new Paragraph(); Phrase PAnoFabricoCompra = new Phrase("ano de Fabrico/Compra".toUpperCase(), fontCorpoTabT); Phrase PAnoFabricoCompraUK = new Phrase("\nYear of Manufacture/PURCHASE".toUpperCase(), fontUK); para.add(PAnoFabricoCompra); para.add(PAnoFabricoCompraUK); PdfPCell cellAnoFabricoCompra = new PdfPCell(para); cellAnoFabricoCompra.setHorizontalAlignment(Element.ALIGN_CENTER); cellAnoFabricoCompra.setPaddingTop(5f); cellAnoFabricoCompra.setPaddingBottom(5f); para = new Paragraph(); Phrase PTotalLuagares = new Phrase("lotao".toUpperCase(), fontCorpoTabT); Phrase PTotalLuagaresUK = new Phrase("\nSTOCKING", fontUK); para.add(PTotalLuagares); para.add(PTotalLuagaresUK); PdfPCell cellTotalLuagares = new PdfPCell(para); cellTotalLuagares.setHorizontalAlignment(Element.ALIGN_CENTER); cellTotalLuagares.setPaddingTop(5f); cellTotalLuagares.setPaddingBottom(5f); para = new Paragraph(); Phrase PDadosValorSeguro = new Phrase("Estimativa / Valor Segurado".toUpperCase(), fontCorpoTabT); Phrase PDadosValorSeguroUK = new Phrase("\nEstimation / Amount Insured".toUpperCase(), fontUK); para.add(PDadosValorSeguro); para.add(PDadosValorSeguroUK); PdfPCell cellDadosValorSeguro = new PdfPCell(para); cellDadosValorSeguro.setHorizontalAlignment(Element.ALIGN_CENTER); cellDadosValorSeguro.setPaddingTop(5f); cellDadosValorSeguro.setPaddingBottom(5f); pTableDados.addCell(cellMarca); pTableDados.addCell(cellModelo); pTableDados.addCell(cellMatricula); pTableDados.addCell(cellChasii); pTableDados.addCell(cellAnoFabricoCompra); pTableDados.addCell(cellTotalLuagares); pTableDados.addCell(cellDadosValorSeguro); int total = vb.getInfo().size(); for (int i = 0; i < total; i++) { cellMarca = new PdfPCell( new Phrase((vb.getInfo().get(i).getMarca() == null) ? " " : vb.getInfo().get(i).getMarca(), fontCorpoTab)); cellMarca.setHorizontalAlignment(Element.ALIGN_CENTER); cellModelo = new PdfPCell(new Phrase( (vb.getInfo().get(i).getModelo() == null) ? " " : vb.getInfo().get(i).getModelo(), fontCorpoTab)); cellModelo.setHorizontalAlignment(Element.ALIGN_CENTER); cellMatricula = new PdfPCell( new Phrase(((vb.getInfo().get(i).getNumeroMatricula() == null) ? ".........." : vb.getInfo().get(i).getNumeroMatricula()), fontCorpoTab)); cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER); cellDadosValorSeguro = new PdfPCell(new Phrase( ((vb.getInfo().get(i).getValorAtual() == null || vb.getInfo().get(i).getValorAtual().isEmpty() || vb.getVeiculo().getTipoCobertura().equals("41")) ? " NA " : Moeda.format(Double.valueOf(vb.getInfo().get(i).getValorAtual()))), fontCorpoTab)); cellDadosValorSeguro.setHorizontalAlignment(Element.ALIGN_CENTER); cellAnoFabricoCompra = new PdfPCell(new Phrase(((vb.getInfo().get(i).getAnoFabrico() == null || (vb.getInfo().get(i).getAnoFabrico().isEmpty())) ? "......." : vb.getInfo().get(i).getAnoFabrico()) + "/" + ((vb.getInfo().get(i).getAnoCompra() == null || (vb.getInfo().get(i).getAnoCompra().isEmpty())) ? "......." : vb.getInfo().get(i).getAnoCompra()), fontCorpoTab)); cellAnoFabricoCompra.setHorizontalAlignment(Element.ALIGN_CENTER); cellTotalLuagares = new PdfPCell( new Phrase(vb.getInfo().get(i).getCapacidade() + " LUGARES", fontCorpoTab)); cellTotalLuagares.setHorizontalAlignment(Element.ALIGN_CENTER); cellChasii = new PdfPCell(new Phrase(vb.getInfo().get(i).getChassi() + " ", fontCorpoTab)); cellChasii.setHorizontalAlignment(Element.ALIGN_CENTER); float pad = getPadding(total); cellMarca.setPaddingTop(pad); cellMarca.setPaddingBottom(pad); pTableDados.addCell(cellMarca); cellModelo.setPaddingTop(pad); cellModelo.setPaddingBottom(pad); pTableDados.addCell(cellModelo); cellMatricula.setPaddingTop(pad); cellMatricula.setPaddingBottom(pad); pTableDados.addCell(cellMatricula); cellChasii.setPaddingTop(pad); cellChasii.setPaddingBottom(pad); pTableDados.addCell(cellChasii); cellAnoFabricoCompra.setPaddingTop(pad); cellAnoFabricoCompra.setPaddingBottom(pad); pTableDados.addCell(cellAnoFabricoCompra); cellTotalLuagares.setPaddingTop(pad); cellTotalLuagares.setPaddingBottom(pad); pTableDados.addCell(cellTotalLuagares); cellDadosValorSeguro.setPaddingTop(pad); cellDadosValorSeguro.setPaddingBottom(pad); pTableDados.addCell(cellDadosValorSeguro); } // PdfPTable pTableAssinaturaTitulo= new PdfPTable(1); // pTableAssinaturaTitulo.setWidthPercentage(88f); // PdfPTable pTableAssinatura= new PdfPTable( new float[]{50f,50f}); // pTableAssinatura.setWidthPercentage(88f); // PdfPCell cellAssinatora= new PdfPCell(new Phrase("Assinaturas".toUpperCase(),fontCorpoN)); // cellAssinatora.setBorder(0); // cellAssinatora.setHorizontalAlignment(Element.ALIGN_CENTER); // PdfPCell celllinha1= new PdfPCell(new Phrase("____________________________________________".toUpperCase(),fontCorpo)); // celllinha1.setBorder(0); // celllinha1.setHorizontalAlignment(Element.ALIGN_CENTER); // PdfPCell celllinha2= new PdfPCell(new Phrase("____________________________________________".toUpperCase(),fontCorpo)); // celllinha2.setBorder(0); // celllinha2.setHorizontalAlignment(Element.ALIGN_CENTER); // PdfPCell celllinha11= new PdfPCell(new Phrase("para nicon Seguro sa stp".toUpperCase(),fontCorpoP)); // celllinha11.setBorder(0); // celllinha11.setHorizontalAlignment(Element.ALIGN_CENTER); // PdfPCell celllinha21= new PdfPCell(new Phrase("o segurado ".toUpperCase(),fontCorpoP)); // celllinha21.setBorder(0); // celllinha21.setHorizontalAlignment(Element.ALIGN_CENTER); // pTableAssinaturaTitulo.addCell(cellAssinatora); // pTableAssinatura.addCell(celllinha1); // pTableAssinatura.addCell(celllinha2); // pTableAssinatura.addCell(celllinha11); // pTableAssinatura.addCell(celllinha21); Document documento = new Document(); documento.setPageSize(PageSize.A4); documento.setMargins(20f, 20f, 35f, 5f); // File ff= new File("Documentos\\"+user+"\\Seguro Automovel\\"); // ff.mkdirs(); // ff =new File(ff.getAbsoluteFile()+"\\"+"Formulario Seguro Automovel "+sdf1.format(new Date())+".pdf"); File ff = new File(arquivo + "/" + user + "/Seguro Automovel/"); ff.mkdirs(); String Ddata = sdf1.format(new Date()); ff = new File(ff.getAbsoluteFile() + "/" + "Formulario Seguro Automovel " + Ddata + ".pdf"); reString = "../Documentos/" + user + "/Seguro Automovel/" + "Formulario Seguro Automovel " + Ddata + ".pdf"; OutputStream outputStraem = new FileOutputStream(ff); PdfWriter writer = PdfWriter.getInstance(documento, outputStraem); if (MarcaDAgua.isSimulation) { MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical(); writer.setPageEvent(v); } if (MarcaDAgua.isCanceled) { MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical(); writer.setPageEvent(v); } PdfPTable pTableLinha = new PdfPTable(1); pTableLinha.setWidthPercentage(88f); PdfPCell cellLinha = new PdfPCell(new Phrase( "----------------------------------------------------------------------------------------------------------------------", fontCorpo)); cellLinha.setBorder(0); pTableLinha.addCell(cellLinha); cellLinha.setPaddingTop(-9f); pTableLinha.addCell(cellLinha); PdfPTable pTableApoliceAndPeriodo = new PdfPTable(new float[] { 40, 60 }); pTableApoliceAndPeriodo.setWidthPercentage(88f); Paragraph pApolice = new Paragraph(); pApolice.add(new Phrase("N Aplice: ".toUpperCase(), fontCorpo)); pApolice.add(new Phrase(numApolice, fontCorpoN)); pApolice.add(new Phrase("\nPOLICY NO:", fontUK)); PdfPCell cellApolice = new PdfPCell(pApolice); // cellApolice.setPaddingTop(-2); // cellApolice.setPaddingBottom(4.5f); cellApolice.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableApoliceAndPeriodo.addCell(cellApolice); Paragraph pPeriodo = new Paragraph(); pPeriodo.add(new Phrase("Periodo Do Seguro: ".toUpperCase(), fontCorpo)); pPeriodo.add(new Phrase(((c.getDataInicio() != null) ? sdf.format(c.getDataInicio()) : " ") + " " + ((c.getDataFim() != null) ? sdf.format(c.getDataFim()) : " "), fontCorpoN)); pPeriodo.add(new Phrase("\nPERIOD OF INSURANCE:", fontUK)); PdfPCell cellPeriodo = new PdfPCell(pPeriodo); // cellPeriodo.setPaddingTop(-2); // cellPeriodo.setPaddingBottom(4.5f); cellPeriodo.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); pTableApoliceAndPeriodo.addCell(cellPeriodo); documento.open(); documento.add(pTableEmpresaPricipal); documento.add(pTableNull); documento.add(pTableTitulo); documento.add(pTableNull); documento.add(pTableApoliceAndPeriodo); documento.add(pTableNull); documento.add(pTableCliente); documento.add(pTableNull); documento.add(pTableLinha); documento.add(pTableNull); documento.add(pTableDadosTitulo); documento.add(pTableDados); documento.add(pTableNull); documento.add(pTableLinha); documento.add(pTableNull); documento.add(pTableSeguro); // documento.add(pTableNull); // documento.add(pTableAssinaturaTitulo); // documento.add(pTableNull); // documento.add(pTableNull); // documento.add(pTableAssinatura); documento.close(); // PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",1); // //PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Hewlett-Packard HP LaserJet P2035",1); // // printPdf.print(); } catch (BadElementException | IOException ex) { Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex); } return reString; }
From source file:eyeofthetiger.utils.PDFDossardGenerator.java
public void createPdf(List<Participant> participants, OutputStream out) throws IOException, DocumentException { sortParticipants(participants);//from w w w . java 2s . c om Document document = new Document(PageSize.A4.rotate()); float margin = CentimeterToUserSpace(marginCm); document.setMargins(margin, margin, margin, margin); PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfReader pdfBackgroundReader = null; PdfImportedPage backgroundPage = null; if (pdfBackground != null && (new File(pdfBackground)).exists() && (new File(pdfBackground)).isFile()) { pdfBackgroundReader = new PdfReader(pdfBackground); backgroundPage = writer.getImportedPage(pdfBackgroundReader, 1); } float documentTop = document.top(); float documentBottom = document.bottom(); float documentHeight = documentTop - documentBottom; float left = document.left(); float right = document.right(); float width = right - left; float height = documentTop - documentBottom; //cb.rectangle(left, documentBottom, width, documentHeight); //cb.stroke(); boolean logoLeftExist = (new File(logoLeft)).exists() && (new File(logoLeft)).isFile(); boolean logoRightExist = (new File(logoRight)).exists() && (new File(logoRight)).isFile(); float imgLeftRight = left; float imgLeftBottom = documentTop; float imgRightLeft = right; float imgRighBottom = documentTop; Image imgLeft = null; Image imgRight = null; if (exportLogos) { if (logoLeftExist) { imgLeft = Image.getInstance(logoLeft); float h = imgLeft.getHeight(); float w = imgLeft.getWidth(); float nw = width * logoLeftWidth; float nh = (h / w) * nw; imgLeft.scaleAbsolute(nw, nh); //img.scaleAbsoluteHeight(img.getScaledWidth() / xyRatio); imgLeft.setAbsolutePosition(left, documentTop - imgLeft.getScaledHeight()); //cb.addImage(img); imgLeftRight = imgLeft.getAbsoluteX() + imgLeft.getScaledWidth(); imgLeftBottom = imgLeft.getAbsoluteY(); } if (logoRightExist) { imgRight = Image.getInstance(logoRight); float h = imgRight.getHeight(); float w = imgRight.getWidth(); float nw = width * logoRightWidth; float nh = (h / w) * nw; imgRight.scaleAbsolute(nw, nh); imgRight.setAbsolutePosition(right - imgRight.getScaledWidth(), documentTop - imgRight.getScaledHeight()); //cb.addImage(imgRight); imgRightLeft = imgRight.getAbsoluteX(); imgRighBottom = imgRight.getAbsoluteY(); } } float nameHeightPercent = 0.35f; float groupHeightPercent = 0.25f; float nameTop = documentTop; float nameBottom = nameTop; if (exportName) { nameBottom = nameTop - (documentHeight * nameHeightPercent); } float groupeTop = nameBottom; float groupeBottom = nameBottom; if (exportGroup) { groupeBottom = groupeTop - (documentHeight * groupHeightPercent); } float barcodeTop = groupeBottom; float barcodeBottom = documentBottom; ColumnText columnText; for (Participant participant : participants) { if (backgroundPage != null) { //cb.addTemplate(backgroundPage, 1f, 0, 0, 1, 0, 0); //TODO cb.addTemplate(backgroundPage, 0, 0); } float nameFontSize = 65f; float groupFontSize = 45f; float renseignementFontSize = 35f; if (imgLeft != null) { cb.addImage(imgLeft); } if (imgRight != null) { cb.addImage(imgRight); } if (exportName) { columnText = new ColumnText(cb); columnText.setAlignment(Rectangle.ALIGN_CENTER); if (imgLeftRight != -1 && imgLeftBottom != -1) { float[] leftBorder = null; if (imgLeftBottom < nameBottom) { leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, nameBottom, left, nameBottom }; } else { leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, imgLeftBottom, left, imgLeftBottom, left, nameBottom }; } float[] rightBorder = null; if (imgRighBottom < nameBottom) { rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, nameBottom, right, nameBottom }; } else { rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, imgRighBottom, right, imgRighBottom, right, nameBottom }; } columnText.setColumns(leftBorder, rightBorder); } else { columnText.setSimpleColumn(left, nameTop, right, nameBottom); } //cb.rectangle(left, nameBottom, width, (nameTop - nameBottom)); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); String txt = participant.getNom().toUpperCase() + " " + participant.getPrenom(); float previousPos = columnText.getYLine(); columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); while (nameFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) { nameFontSize = nameFontSize - 0.5f; columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); columnText.setYLine(previousPos); } columnText.setLeading(nameFontSize); columnText.setText(createCleanPhrase(txt, nameFontSize, true)); columnText.setYLine(previousPos); columnText.go(false); } if (exportGroup) { columnText = new ColumnText(cb); columnText.setAlignment(Rectangle.ALIGN_CENTER); columnText.setSimpleColumn(document.left(), groupeTop, document.right(), groupeBottom); float groupeHeight = groupeTop - groupeBottom; //cb.rectangle(document.left(), groupeTop - groupeHeight, document.right() - document.left(), groupeHeight); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); columnText.setFollowingIndent(0); String txt1 = participant.getGroupe(); String txt2 = exportRenseignement ? "\n" + participant.getRenseignements() : null; float previousPos = columnText.getYLine(); columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); while (groupFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) { groupFontSize = groupFontSize - 0.5f; renseignementFontSize = renseignementFontSize - 0.5f; columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); columnText.setYLine(previousPos); } columnText.setText(null); columnText.setLeading(groupFontSize); columnText.addText(createCleanPhrase(txt1, groupFontSize, true)); columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false)); columnText.setYLine(previousPos); columnText.go(false); } { columnText = new ColumnText(cb); float topMargin = 12f; columnText.setSimpleColumn(left, barcodeTop - topMargin, right, barcodeBottom); float barcodeHeight = (barcodeTop - topMargin) - barcodeBottom; //cb.rectangle(left, barcodeTop - barcodeHeight, width, barcodeHeight); //cb.stroke(); columnText.setExtraParagraphSpace(0f); columnText.setAdjustFirstLine(false); columnText.setIndent(0); float previousPos = columnText.getYLine(); columnText.setText(null); columnText.addElement(createCleanBarcode(cb, participant.getNumero(), width, barcodeHeight)); columnText.go(false); } document.newPage(); } document.close(); if (pdfBackgroundReader != null) { pdfBackgroundReader.close(); } }
From source file:Facturacion.Factura.java
public void Generar(String numero, int cantidad, int total, Cliente c) throws FileNotFoundException, DocumentException { com.itextpdf.text.Document document = new com.itextpdf.text.Document(PageSize.A4, 80, 80, 50, 50); FileOutputStream salida = new FileOutputStream("FACTURA" + numero + ".pdf"); PdfWriter writer = PdfWriter.getInstance(document, salida); writer.setInitialLeading(0);//from www . j a v a 2s . c o m PdfPTable table = new PdfPTable(6); table.addCell("CANTIDAD"); table.addCell("CODIGO"); table.addCell("NOMBRE"); table.addCell("DESCRIPCION"); table.addCell("PRECIO"); table.addCell("TOTAL"); for (int i = 0; i < producto.size(); i++) { table.addCell(String.valueOf(cantidad)); table.addCell(String.valueOf(producto.get(i).getCodigo())); table.addCell(producto.get(i).getNombreP()); table.addCell(producto.get(i).getDescripcion()); table.addCell(String.valueOf(producto.get(i).getPrecio())); table.addCell(String.valueOf(total)); } SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");//dd/MM/yyyy Date now = new Date(); String strDate = sdfDate.format(now); document.open(); Paragraph paragraph = new Paragraph(); Paragraph paragraph1 = new Paragraph(); paragraph.add("DIMASPORT CIA. LTDA.\n\nFACTURA N" + numero); paragraph.setAlignment(Paragraph.ALIGN_CENTER); paragraph1.add("\n\nNOMBRE: " + c.getNombre() + " " + c.getApellido() + "\nCEDULA: " + c.getCedula() + "\nDIRECCION: " + c.getDireccion() + "\nCORREO: " + c.getCorreo() + "\nTELEFONO: " + c.getTelefono() + "\nFECHA: " + strDate + "\n\n"); paragraph.setAlignment(Paragraph.ALIGN_LEFT); document.add(paragraph); document.add(paragraph1); document.add(table); document.close(); }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Take the patient encounter and build a pdf * * @param encounterId The id of the encounter to * @return The the PDF stream to output to the browser *///from ww w. j ava 2 s .c om private byte[] buildPDF(int encounterId) { // Get Patient Encounter ServiceResponse<PatientEncounterItem> patientEncounterItemServiceResponse = searchService .retrievePatientEncounterItemByEncounterId(encounterId); if (patientEncounterItemServiceResponse.hasErrors()) { throw new RuntimeException(); } PatientEncounterItem patientEncounter = patientEncounterItemServiceResponse.getResponseObject(); // Get Patient ServiceResponse<PatientItem> patientItemServiceResponse = searchService .retrievePatientItemByEncounterId(encounterId); if (patientItemServiceResponse.hasErrors()) { throw new RuntimeException(); } PatientItem patientItem = patientItemServiceResponse.getResponseObject(); // Get Vitals for Encounter ServiceResponse<VitalMultiMap> vitalMultiMapServiceResponse = vitalService .retrieveVitalMultiMap(encounterId); if (vitalMultiMapServiceResponse.hasErrors()) { throw new RuntimeException(); } VitalMultiMap patientVitals = vitalMultiMapServiceResponse.getResponseObject(); // Get TabFields for Encounter ServiceResponse<TabFieldMultiMap> patientEncounterTabFieldResponse = tabService .retrieveTabFieldMultiMap(encounterId); if (patientEncounterTabFieldResponse.hasErrors()) { throw new RuntimeException(); } TabFieldMultiMap tabFieldMultiMap = patientEncounterTabFieldResponse.getResponseObject(); // Get Prescriptions ServiceResponse<List<PrescriptionItem>> prescriptionItemServiceResponse = searchService .retrieveDispensedPrescriptionItems(encounterId); if (prescriptionItemServiceResponse.hasErrors()) { throw new RuntimeException(); } List<PrescriptionItem> prescriptions = prescriptionItemServiceResponse.getResponseObject(); // Get Problems ServiceResponse<List<ProblemItem>> problemItemServiceResponse = encounterService .retrieveProblemItems(encounterId); if (problemItemServiceResponse.hasErrors()) { throw new RuntimeException(); } List<ProblemItem> problems = problemItemServiceResponse.getResponseObject(); // Will eventually output the PDF -- all 3 lines below are needed ByteArrayOutputStream pdfStream = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4, 10, 10, 10, 10); try { PdfWriter docWriter = PdfWriter.getInstance(document, pdfStream); document.open(); // PDF Author Info document.addAuthor("fEMR"); document.addCreationDate(); document.addCreator("fEMR"); document.addTitle("Patient Report"); // Add the header to the page document.add(createHeaderTable()); // Add basic patient info document.add(createPatientInfoTable(patientItem)); // Add Encounter Info Table document.add(createEncounterInfoTable(patientEncounter)); // Add Vitals Table document.add(createVitalsTable(patientEncounter, patientVitals)); // Add Assessments Table document.add(getAssessments(tabFieldMultiMap, prescriptions, problems)); // Add Chief Complaints Table document.add(getChiefComplaintsTable(tabFieldMultiMap)); document.close(); docWriter.close(); } catch (Exception e) { e.printStackTrace(); } return pdfStream.toByteArray(); }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
public void generate(OutputStream output) { final Rectangle pageSize = PageSize.A4; final ByteArrayOutputStream outputBuffer = new ByteArrayOutputStream(); document = new Document(pageSize, LEFT_MARGIN, RIGHT_MARGIN, TOP_MARGIN, BOTTOM_MARGIN); try {// w ww.j a v a2s. c om final PdfWriter writer = PdfWriter.getInstance(document, outputBuffer); writer.setBoxSize("art", new Rectangle(ART_BOX_LEFT_MARGIN, ART_BOX_BOTTOM_MARGIN, pageSize.getRight() - ART_BOX_RIGHT_MARGIN, pageSize.getTop() - ART_BOX_TOP_MARGIN)); writer.setPageEvent(new HeaderFooter()); document.open(); createAndAddForeword(); createAndAddEventTable(); createAndAddAfterword(); createAndAddOrganizerTable(); document.close(); writer.close(); // Loop through the document again to add the missing page numbers document = new Document(); final PdfCopy copy = new PdfCopy(document, output); document.open(); final PdfReader reader = new PdfReader(outputBuffer.toByteArray()); addPageNumbers(reader, copy); document.close(); reader.close(); } catch (DocumentException | IOException ex) { throw new PDFGenerationException("Error generating PDF", ex); } }
From source file:forms_all.BonafideController.java
@FXML private void doPrinting(ActionEvent event) { print_btn.setVisible(false);/*from w w w .j a v a 2 s . co m*/ Scene scene = print_btn.getScene(); WritableImage snapshot = scene.snapshot(null); BufferedImage image = SwingFXUtils.fromFXImage(snapshot, null); File f = new File("test2.png"); try { ImageIO.write(image, "png", f); } catch (IOException ex) { } Document document = new Document(PageSize.A4, 0, 0, 0, 0); try { PdfWriter.getInstance(document, new FileOutputStream("Image.pdf")); document.open(); // BufferedImage img = ImageIO.read(new File("test1.png")); //File f = new File("test1.png"); Image image1 = Image.getInstance("test2.png"); document.add(image1); document.close(); } catch (Exception e) { e.printStackTrace(); } try { InputStream is = new BufferedInputStream(new FileInputStream("Image.pdf")); DocFlavor flavor = DocFlavor.INPUT_STREAM.PDF; PrintService service = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob printJob = service.createPrintJob(); printJob.addPrintJobListener(new BonafideController.JobCompleteMonitor()); Doc doc = new SimpleDoc(is, flavor, null); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); //attributes.add(new Destination(new java.net.URI("file:/home/jayesh/NetBeansProjects/myFile.ps"))); printJob.print(doc, attributes); //while(jobRunning) //{ // Thread.sleep(1000); //} is.close(); } catch (Exception ex) { } finally { System.out.println("exiting"); } System.out.println("Done"); try { con1(); Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost/pro", username, password); String query = "insert into log values(?,?)"; PreparedStatement ps = con.prepareStatement(query); ps.setString(1, getCurUser()); Date date = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/YYYY HH:mm:ss"); ps.setString(2, "Printed Bonafide Form at " + df.format(date)); ps.executeUpdate(); } catch (Exception ex) { ex.printStackTrace(); } print_btn.setVisible(true); }
From source file:fr.pigouchet.gestion.util.GeneratePdf.java
public static void createPageByCategory(Categorie category) { loadAllData();/* w ww .j a va 2 s . c om*/ Document document = new Document(PageSize.A4, 36, 36, 54, 36); try { PdfWriter.getInstance(document, new FileOutputStream(FILE + "/Fiche " + category.getNom() + ".pdf")); document.open(); PdfPTable table = oneCategory(category); document.add(table); document.newPage(); document.close(); if (Desktop.isDesktopSupported()) { try { File myFile = new File(FILE + "/Fiche " + category.getNom() + ".pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fr.pigouchet.gestion.util.GeneratePdf.java
public static void createFullPage() throws IOException { loadAllData();//from ww w . java 2s .co m Document document = new Document(PageSize.A4, 36, 36, 54, 36); try { writer = PdfWriter.getInstance(document, new FileOutputStream(FILE + "/Tous les produits.pdf")); document.open(); for (Categorie categorie : dataCate) { PdfPTable table = allSubCategory(categorie, document); document.add(table); document.newPage(); passed = false; } //System.out.println(writer.getPageNumber()); document.close(); if (Desktop.isDesktopSupported()) { try { File myFile = new File(FILE + "/Tous les produits.pdf"); Desktop.getDesktop().open(myFile); } catch (IOException ex) { // no application registered for PDFs } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:fr.ybonnel.breizhcamppdf.PdfHandler.java
License:Apache License
protected static void generate(OutputStream output, boolean schedule) throws IOException { Document document = new Document(PageSize.A4.rotate()); try {// w w w . j a va2 s. com PdfWriter pdfWriter = PdfWriter.getInstance(document, output); document.open(); if (schedule) { new PdfRenderer(document, pdfWriter).render(); } else { new RoomPdfRenderer(document, pdfWriter).render(); } document.close(); } catch (DocumentException e) { throw new RuntimeException(e); } }