Open jangelcastanedap opened 1 year ago
package clases;
import com.itextpdf.text.BaseColor; import com.itextpdf.text.Chunk; import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException; import com.itextpdf.text.Paragraph; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.List; import javax.swing.event.DocumentListener; import javax.swing.event.UndoableEditListener; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException;
import javax.swing.text.Element; import javax.swing.text.Position; import javax.swing.text.Segment;
public class PDF { String Titulo; String Nombre; String Fecha;
Document documento;
FileOutputStream archivo;
Paragraph titulo;
public PDF (String Titulo, String Nombre, String Fecha, List<Usuario> usu)
{
this.Titulo = Titulo;
this.Nombre = Nombre;
this.Fecha = Fecha;
documento = new Document();
titulo = new Paragraph("Caso de prueba");
}
public void CrearPDF()
{
try {
archivo = new FileOutputStream(Nombre + ".pdf");
PdfWriter.getInstance(documento, archivo);
documento.open();
titulo.setAlignment(1);
documento.add(new Paragraph("Titulo: " + Titulo));
documento.add(new Paragraph("Nombre: " + Nombre));
documento.add(new Paragraph("Fecha: " + Fecha ));
documento.add(Chunk.NEWLINE);//creacion de linea en blanco
PdfPTable tabla = new PdfPTable(4);
tabla.setWidthPercentage(100);
PdfPCell titulo = new PdfPCell(new Phrase("Titulo."));
titulo.setBackgroundColor(BaseColor.BLUE);
PdfPCell NPruebas = new PdfPCell(new Phrase("N# de pruebas."));
NPruebas.setBackgroundColor(BaseColor.ORANGE);
PdfPCell Encargado = new PdfPCell(new Phrase("Encargado."));
Encargado.setBackgroundColor(BaseColor.ORANGE);
PdfPCell fecha = new PdfPCell(new Phrase("Fecha."));
fecha.setBackgroundColor(BaseColor.ORANGE);
tabla.addCell(titulo);
tabla.addCell(NPruebas);
tabla.addCell(Encargado);
tabla.addCell(fecha);
documento.close();
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
} catch (DocumentException e) {
System.err.println(e.getMessage());
}
}
}
-Deberá ser extensión .txt y mostrar al inicio del texto la fecha del día en el que se guardó el reporte, con nombre a escoger por el usuario, o, asignar como default: "Reporte de Casos de Prueba.txt"