package siprp.ficha; import java.awt.Color; import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; public class ExamePDF { // private static final Font FONT_BOLD = new Font( Font.TIMES_ROMAN, 9, Font.BOLD, new Color( 0, 0, 0 ) ); // private static final Font FONT_NORMAL = new Font( Font.TIMES_ROMAN, 9, Font.NORMAL, new Color( 0, 0, 0 ) ); private static final Font FONT_BOLD = FontFactory.getFont( "Arial", 8, Font.BOLD ); private static final Font FONT_NORMAL = FontFactory.getFont( "Arial", 8, Font.NORMAL ); private static final Font FONT_ZAPFDINGBATS = new Font( Font.ZAPFDINGBATS , 12, Font.NORMAL, new Color( 0, 0, 0 ) ); public ExamePDF() { } public static void main( String[] args ) { try { Hashtable ht = new Hashtable(); // designacao_social // estabelecimentos.nome // estabelecimentos.localidade // servico_saude_tipo_interno // servico_saude_tipo_interempresas // servico_saude_tipo_externo // servico_saude_tipo_sns // servico_saude_designacao // servico_higiene_tipo_interno // servico_higiene_tipo_interempresas // servico_higiene_tipo_externo // servico_higiene_outro // servico_higiene_designacao // trabalhadores.nome // sexo // data_nascimento // nacionalidade // numero_mecanografico // data_admissao // categoria // local_trabalho // funcao_proposta // data_admissao_funcao // observacoes // exames.data // tipo_admissao // tipo_periodico // tipo_ocasional // tipo_apos_doenca // tipo_apos_acidente // tipo_pedido_trabalhador // tipo_pedido_empresa // tipo_mudanca_funcao // tipo_trabalho // tipo_outro // resultado_apto // resultado_apto_condicionalmente // resultado_inapto_temp // resultado_inapto_def // outra_funcao_1 // outra_funcao_2 // outra_funcao_3 // outra_funcao_4 // proximo_exame // outras_recomendacoes // medicos.nome // numero_cedula ht.put( "trabalhadores.nome", "Trabalhador do comércio" ); ht.put( "servico_saude_designacao", "Designacao servico saude" ); ht.put( "servico_saude_tipo_externo", Boolean.TRUE ); ht.put( "tipo_periodico", Boolean.TRUE ); ht.put( "resultado_inapto_temp", Boolean.TRUE ); FileOutputStream fos = new FileOutputStream( System.getProperty( "user.home" ) + "\\report.pdf" ); fos.write( new ExamePDF().createPDF( ht ) ); fos.close(); System.out.println( "File saved." ); Process proc = Runtime.getRuntime().exec( "cmd.exe /c \"" + System.getProperty( "user.home" ) + "\\report.pdf\"" ); proc.waitFor(); new File( System.getProperty( "user.home" ) + "\\report.pdf" ).delete(); System.out.println( "Done." ); } catch( Exception e ) { e.printStackTrace(); } } public void print( byte []pdf ) throws Exception { FileOutputStream fos = new FileOutputStream( System.getProperty( "user.home" ) + "\\report_ficha.pdf" ); fos.write( pdf ); fos.close(); System.out.println( "File saved." ); Process proc = Runtime.getRuntime().exec( "cmd.exe /c \"" + System.getProperty( "user.home" ) + "\\report_ficha.pdf\"" ); proc.waitFor(); new File( System.getProperty( "user.home" ) + "\\report_ficha.pdf" ).delete(); } public byte[] createPDF( Hashtable values ) { Document document = new Document(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); document.setPageSize( PageSize.A4 ); try { PdfWriter pdfw = PdfWriter.getInstance( document, bos ); document.addTitle( "Ficha de Aptid\u00e3o" ); document.addAuthor( "SIPRP" ); document.addCreator( "Evolute" ); document.open(); Paragraph conteudo = new Paragraph(); conteudo.add( new Chunk( "FICHA DE APTID\u00c3O\n", // new Font( Font.TIMES_ROMAN, 10, Font.BOLD, new Color( 0, 0, 0 ) ) ) ); FontFactory.getFont( "Arial", 10, Font.BOLD ) ) ); conteudo.add( new Chunk( "(Portaria n\u00ba1031/2002, de 10 de Agosto)", // new Font( Font.TIMES_ROMAN, 7, Font.NORMAL, new Color( 0, 0, 0 ) ) ) ); FontFactory.getFont( "Arial", 7, Font.BOLD ) ) ); conteudo.setAlignment( Element.ALIGN_CENTER ); document.add( conteudo ); Table table = new Table( 1 ); table.setBorderWidth( 1 ); table.setPadding( 5 ); table.setOffset( 0 ); table.setWidth( 100 ); table.addCell( new Phrase( "Empresa/Entidade", FONT_BOLD ) ); StringBuffer texto = new StringBuffer(); Cell cell = new Cell(); texto.append( "DESIGNA\u00c7\u00c3O SOCIAL: " + values.get( "designacao_social" ) + "\n" ); texto.append( "ESTABELECIMENTO: " + values.get( "estabelecimentos.nome" ) + " LOCALIDADE: " + values.get( "estabelecimentos.localidade" ) + "\n" ); texto.append( "SERVI\u00c7O DE SA\u00DaDE: Tipo Interno " + ( ( values.get( "servico_saude_tipo_interno" ) == null ) ? "\u2610" : "\u2612" ) + " Interempresas " + ( ( values.get( "servico_saude_tipo_interempresas" ) == null ) ? "\u2610" : "\u2612" ) + " Externo " + ( ( values.get( "servico_saude_tipo_externo" ) == null ) ? "\u2610" : "\u2612" ) + " Servi\u00e7o Nacional de Sa\u00fade " + ( ( values.get( "servico_saude_tipo_sns" ) == null ) ? "\u2610" : "\u2612" ) + "\n" ); texto.append( "DESIGNA\u00c7\u00c3O: " + values.get( "servico_saude_designacao" ) + "\n" ); texto.append( "SERVI\u00c7O DE HIGIENE E SEGURAN\u00c7A: Tipo Interno " + ( ( values.get( "servico_higiene_tipo_interno" ) == null ) ? "\u2610" : "\u2612" ) + " Interempresas " + ( ( values.get( "servico_higiene_tipo_interempresas" ) == null ) ? "\u2610" : "\u2612" ) + " Externo " + ( ( values.get( "servico_higiene_tipo_externo" ) == null ) ? "\u2610" : "\u2612" ) + " Outro " + ( ( values.get( "servico_higiene_outro" ) == null ) ? "\u2610" : "\u2612" ) + "\n" ); texto.append( "DESIGNA\u00c7\u00c3O: " + values.get( "servico_higiene_designacao" ) + "" ); cell.addElement( new Phrase( 12f, texto.toString(), FONT_NORMAL ) ); table.addCell( cell ); document.add( table ); table = new Table( 1 ); table.setBorderWidth( 1 ); table.setPadding( 5 ); table.setOffset( 0 ); table.setWidth( 100 ); table.addCell( new Phrase( "Trabalhador", FONT_BOLD ) ); texto = new StringBuffer(); texto.append( "NOME: " + values.get( "trabalhadores.nome" ) + "\n" ); texto.append( "SEXO: " + values.get( "sexo" ) + " DATA DE NASCIMENTO: " + values.get( "data_nascimento" ) + " NACIONALIDADE: " + values.get( "nacionalidade" ) + "\n" ); texto.append( "N\u00daMERO MECANOGR\u00c1FICO/OUTRO: " + values.get( "numero_mecanografico" ) + " DATA DE ADMISS\u00c3O: " + values.get( "data_admissao" ) + "\n" ); texto.append( "CATEGORIA PROFISSIONAL: " + values.get( "categoria" ) + " LOCAL DE TRABALHO: " + values.get( "local_trabalho" ) + "\n" ); texto.append( "FUN\u00c7\u00c3O PROPOSTA: " + values.get( "funcao_proposta" ) + " DATA DE ADMISS\u00c3O NA FUN\u00c7\u00c3O: " + values.get( "data_admissao_funcao" ) + "" ); table.addCell( new Phrase( 12f, texto.toString(), FONT_NORMAL ) ); document.add( table ); table = new Table( 1 ); table.setBorderWidth( 1 ); table.setOffset( 0 ); table.setPadding( 5 ); table.setWidth( 100 ); table.addCell( new Phrase( "Observa\u00e7\u00f5es", FONT_BOLD ) ); texto = new StringBuffer(); texto.append( values.get( "observacoes" ) ); table.addCell( new Phrase( 12f, texto.toString(), FONT_NORMAL ) ); document.add( table ); table = new Table( 2 ); table.setBorderWidth( 1 ); table.setOffset( 0 ); table.setPadding( 5 ); table.setWidth( 100 ); cell = new Cell( new Phrase( "Exame M\u00e9dico", FONT_BOLD ) ); cell.setColspan( 2 ); table.addCell( cell ); texto = new StringBuffer(); texto.append( "DATA DO EXAME: " + values.get( "exames.data" ) + "\n" ); texto.append( "TIPO\n" ); texto.append( "ADMISS\u00c3O ...................................................................................... " + ( ( values.get( "tipo_admissao" ) == null ) ? "" : "X" ) + "\n" ); texto.append( "PERI\u00d3DICO ..................................................................................... " + ( ( values.get( "tipo_periodico" ) == null ) ? "" : "X" ) + "\n" ); texto.append( "OCASIONAL .................................................................................... " + ( ( values.get( "tipo_ocasional" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " AP\u00d3S DOEN\u00c7A ...................................................................... " + ( ( values.get( "tipo_apos_doenca" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " AP\u00d3S ACIDENTE ................................................................... " + ( ( values.get( "tipo_apos_acidente" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " A PEDIDO DO TRABALHADOR ............................................. " + ( ( values.get( "tipo_pedido_trabalhador" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " A PEDIDO DO SERVI\u00c7O ........................................................ " + ( ( values.get( "tipo_pedido_empresa" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " POR MUDAN\u00c7A DE FUN\u00c7\u00c3O ................................................ " + ( ( values.get( "tipo_mudanca_funcao" ) == null ) ? "" : "X" ) + "\n" ); texto.append( " POR ALTERA\u00c7\u00c3O DAS CONDI\u00c7\u00d5ES DE TRABALHO ......... " + ( ( values.get( "tipo_trabalho" ) == null ) ? "" : "X" ) + "\n" ); texto.append( "OUTRO ............................................................................................ " + ( ( values.get( "tipo_outro" ) == null ) ? "" : "X" ) + "\n" ); texto.append( "ESPECIFIQUE: " + ( ( values.get( "tipo_outro" ) == null ) ? "" : values.get( "tipo_outro" ) ) + "" ); table.addCell( new Phrase( texto.toString(), FONT_NORMAL ) ); Cell cellVazia = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellDataExame = new Cell( new Phrase( 12f, "DATA DO EXAME: " + values.get( "exames.data" ) + "\n", FONT_NORMAL ) ); Cell cellTipo = new Cell( new Phrase( 12f, "TIPO\n", FONT_NORMAL ) ); Cell cellAdmissao = new Cell( new Phrase( 12f, "ADMISS\u00c3O ...................................................................................... ", FONT_NORMAL ) ); Cell cellAdmissaoValor = new Cell( new Phrase( 12f, ( ( values.get( "tipo_admissao" ) == null ) ? "" : "X" ), FONT_NORMAL ) ); Cell cellPeriodico = new Cell( new Phrase( 12f, "PERI\u00d3DICO ..................................................................................... ", FONT_NORMAL ) ); Cell cellPeriodicoValor = new Cell( new Phrase( 12f, ( ( values.get( "tipo_periodico" ) == null ) ? "" : "X" ), FONT_NORMAL ) ); Cell cellOcasional = new Cell( new Phrase( 12f, "OCASIONAL .................................................................................... ", FONT_NORMAL ) ); Cell cellOcasionalValor = new Cell( new Phrase( 12f, ( ( values.get( "tipo_ocasional" ) == null ) ? "" : "X" ), FONT_NORMAL ) ); Cell cellAposDoenca = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAposDoencaValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAposAcidente = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAposAcidenteValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellPedidoTrabalhador = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellPedidoTrabalhadorValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellPedidoServico = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellPedidoServicoValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellMudancaFuncao = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellMudancaFuncaoValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellCondicoes = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellCondicoesValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutro = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutroValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellEspecifique = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellResultado = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellApto = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAptoValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAptoCond = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellAptoCondValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellInaptoTemp = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellInaptoTempValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellInaptoDef = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellInaptoDefValor = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutrasFuncoes = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutrasFuncoes1 = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutrasFuncoes2 = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutrasFuncoes3 = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); Cell cellOutrasFuncoes4 = new Cell( new Phrase( 12f, "", FONT_NORMAL ) ); // table.endHeaders(); // table.addCell( cellDataExame ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellResultado ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellTipo ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellApto ); // table.addCell( cellAptoValor ); // table.addCell( cellAdmissao ); // table.addCell( cellAdmissaoValor ); // table.addCell( cellAptoCond ); // table.addCell( cellAptoCondValor ); // table.addCell( cellPeriodico ); // table.addCell( cellPeriodicoValor ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellOcasional ); // table.addCell( cellOcasionalValor ); // table.addCell( cellInaptoTemp ); // table.addCell( cellInaptoTempValor ); // table.addCell( cellAposDoenca ); // table.addCell( cellAposDoencaValor ); // table.addCell( cellInaptoDef ); // table.addCell( cellInaptoDefValor ); // table.addCell( cellAposAcidente ); // table.addCell( cellAposAcidenteValor ); // table.addCell( cellOutrasFuncoes ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellPedidoTrabalhador ); // table.addCell( cellPedidoTrabalhadorValor ); // table.addCell( cellOutrasFuncoes1 ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellPedidoServico ); // table.addCell( cellPedidoServicoValor ); // table.addCell( cellOutrasFuncoes2 ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellMudancaFuncao ); // table.addCell( cellMudancaFuncaoValor ); // table.addCell( cellOutrasFuncoes3 ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellCondicoes ); // table.addCell( cellCondicoesValor ); // table.addCell( cellOutrasFuncoes4 ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellOutro ); // table.addCell( cellOutroValor ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( cellEspecifique ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); // table.addCell( new Cell( new Phrase( 12f, "", FONT_NORMAL ) ) ); texto = new StringBuffer(); Phrase ph = new Phrase( 12f ); texto.append( "RESULTADO" ); ph.add( new Chunk( texto.toString(), FONT_NORMAL ) ); // texto.append( "APTO ................................................................................................ " // + ( ( values.get( "resultado_apto" ) == null ) ? "" : "X" ) + "\n" ); texto = new StringBuffer( "\nAPTO ............................................................................................ " ); ph.add( doCheckedPhrase( texto.toString(), values.get( "resultado_apto" ) != null ) ); texto = new StringBuffer( "\nAPTO CONDICIONALMENTE ..................................................... " ); ph.add( doCheckedPhrase( texto.toString(), values.get( "resultado_apto_condicionalmente" ) != null ) ); texto = new StringBuffer( "INAPTO TEMPORARIAMENTE ................................................... " ); ph.add( doCheckedPhrase( texto.toString(), values.get( "resultado_inapto_temp" ) != null ) ); texto = new StringBuffer( "INAPTO DEFINITIVAMENTE ....................................................... " ); ph.add( doCheckedPhrase( texto.toString(), values.get( "resultado_inapto_def" ) != null ) ); texto = new StringBuffer(); texto.append( "OUTRAS FUN\u00c7\u00d5ES QUE PODE DESEMPENHAR\n" ); texto.append( " 1 " + ( ( values.get( "outra_funcao_1" ) == null ) ? "" : values.get( "outra_funcao_1" ) ) + "\n" ); texto.append( " 2 " + ( ( values.get( "outra_funcao_2" ) == null ) ? "" : values.get( "outra_funcao_2" ) ) + "\n" ); texto.append( " 3 " + ( ( values.get( "outra_funcao_3" ) == null ) ? "" : values.get( "outra_funcao_3" ) ) + "\n" ); texto.append( " 4 " + ( ( values.get( "outra_funcao_4" ) == null ) ? "" : values.get( "outra_funcao_4" ) ) + "" ); ph.add( new Chunk( texto.toString(), FONT_NORMAL ) ); // table.addCell( new Phrase( 14f, texto.toString(), FONT_NORMAL ) ); table.addCell( ph ); document.add( table ); table = new Table( 1 ); table.setBorderWidth( 1 ); table.setOffset( 0 ); table.setPadding( 5 ); table.setWidth( 100 ); table.addCell( new Phrase( "Outras Recomenda\u00e7\u00f5es", FONT_BOLD ) ); texto = new StringBuffer(); texto.append( "PR\u00d3XIMO EXAME: " + values.get( "proximo_exame" ) + "\n" ); texto.append( "" + values.get( "outras_recomendacoes" ) + "" ); table.addCell( new Phrase( 12f, texto.toString(), FONT_NORMAL ) ); document.add( table ); table = new Table( 1 ); table.setBorderWidth( 1 ); table.setOffset( 0 ); table.setPadding( 5 ); table.setWidth( 100 ); texto = new StringBuffer(); texto.append( "M\u00c9DICO DO TRABALHO: " + values.get( "medicos.nome" ) + " C.P. " + values.get( "numero_cedula" ) + "\n\n" ); texto.append( "ASSINATURA _____________________________________________________________________________________\n\n" ); texto.append( "TOMEI CONHECIMENTO ___________________________________________________________ DATA:____/____/________\n" ); texto.append( " O RESPONS\u00c1VEL DOS RECURSOS HUMANOS" ); table.addCell( new Phrase( 18f, texto.toString(), FONT_NORMAL ) ); document.add( table ); } catch( Exception e ) { e.printStackTrace(); return null; } document.close(); return bos.toByteArray(); } private Phrase doCheckedPhrase( String text, boolean checked ) { Phrase p = new Phrase( 12f ); p.add( new Chunk( text, FONT_NORMAL ) ); p.add( new Chunk( "" + ( char )( checked? 108: 109), FONT_ZAPFDINGBATS ) ); return p; } }