git-svn-id: https://svn.coded.pt/svn/SIPRP@2024 bb69d46d-e84e-40c8-a05a-06db0d633741

0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Carlos Roque 11 years ago
parent 41bc11ee9a
commit 23c6ae8daa

@ -1,171 +0,0 @@
/*
* Pdf.java
*
* Created on November 13, 2007, 11:33 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package pdf;
import beans.Acidentado;
import beans.AnaliseAcidente;
import com.evolute.utils.error.ErrorLogger;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import db.providers.AnalisesDataProvider;
import java.awt.Color;
import java.io.FileOutputStream;
import javax.faces.context.FacesContext;
/**
*
* @author lluis
*/
public class Pdf {
PdfPCell cell = null;
Paragraph p = null;
private final static int FONT_SIZE = 5;
/** Creates a new instance of Pdf */
public Pdf() {
}
public void generatePdf(String folder, AnaliseAcidente a)
{
PdfPTable table = null;
FacesContext ctx = FacesContext.getCurrentInstance();
////HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
Document document = new Document();
////response.setContentType("application/pdf");
try
{
////PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
PdfWriter.getInstance(document, new FileOutputStream(folder + "/" + a.getId().toString() + ".pdf"));
document.open();
//document.add(new Paragraph("Hello World"));
//document.add(new Paragraph(new Date().toString()));
table = createTableEmpresa(a);
document.add(table);
}
catch(Exception ex)
{
ErrorLogger.logException( ex );
}
document.close();
}
private PdfPTable createTableHeader(AnaliseAcidente a)
{
PdfPTable table = new PdfPTable(3);
return table;
}
private PdfPTable createTableEmpresa(AnaliseAcidente a)
{
String empresa_str = "";
String estabelecimento_str = "";
String trabalhador_str = "";
// AnalisesDataProvider adp = new AnalisesDataProvider();
try
{
AnalisesDataProvider adp = AnalisesDataProvider.getInstance();
String nome_empresa = adp.getEmpresaNome(a.getEmpresa_id());
empresa_str = utils.Utils.unicodeToHTML(nome_empresa);
}
catch(Exception ex)
{
ErrorLogger.logException( ex );
}
try
{
AnalisesDataProvider adp = AnalisesDataProvider.getInstance();
estabelecimento_str = adp.getEstabelecimentoNome(a.getEstabelecimento_id());
}
catch(Exception ex)
{
ErrorLogger.logException( ex );
}
Acidentado ac = null;
try
{
AnalisesDataProvider adp = AnalisesDataProvider.getInstance();
ac = adp.getAcidentado(a.getAcidentado_id());
trabalhador_str = ac.getNome();
}
catch(Exception ex)
{
ErrorLogger.logException( ex );
}
//TableEvents event = new TableEvents();
float[] widths = { 1f, 4f };
PdfPTable table = new PdfPTable(widths);
table.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP | Rectangle.BOTTOM);
//PdfPCell cell = new PdfPCell(new Paragraph("header with colspan 3"));
//cell.setColspan(3);
//table.addCell(cell);
cell = new PdfPCell(new Paragraph("Empresa:", FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE)));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(empresa_str, FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE, Font.NORMAL, new Color(255, 255, 255)) ));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Estabelecimento:", FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE)));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(estabelecimento_str, FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE, Font.NORMAL, new Color(255, 255, 255))));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Trabalhador:", FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE)));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
cell = new PdfPCell(new Paragraph(trabalhador_str, FontFactory.getFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED, FONT_SIZE, Font.NORMAL, new Color(255, 255, 255))));
cell.setBorder(Rectangle.NO_BORDER);
cell.setBackgroundColor(new Color(102, 133, 151));
table.addCell(cell);
table.getDefaultCell().setBackgroundColor(new Color(102, 133, 151));
table.getDefaultCell().setPadding(0f);
table.setSpacingAfter(0f);
table.setSpacingBefore(0f);
return table;
}
private PdfPTable createTableEmpresaHs(AnaliseAcidente a)
{
PdfPTable table = new PdfPTable(3);
return table;
}
}
Loading…
Cancel
Save