
PDF JAVA
Publicado por Hector (4 intervenciones) el 11/02/2016 05:43:33
Hola gente, espero me puedan ayudar...
Tengo el siguiente problemilla xD, resulta que tengo un proyecto java en el cual genero un archivo PDF como reporte el cual al ejecutarlo con netbeans me genera el PDF sin ningún problema, pero cuando genero el archivo JAR me crea un PDF vacio inclusive ni sikiera lo puedo visualisar (pesa 0 bts), estoy usando una libreria FILE para darle un destino al PDF por ejemplo escritorio, he probado con artas direcciones en el pc y nada ni sikiera en las donde está el proyecto almacenado.. Espero me entiendan y que me puedan ayudar.. por siacaso les dejaré el codigo de fuente aquí, y de antemano Gracias!!!
BOTÓN CREAR PDF:
BOTON PARA DAR LA DIRECCIÓN DE ALMACENAMIENTO DEL PDF:
Espero sus comentarios.... Un Saludo.
Tengo el siguiente problemilla xD, resulta que tengo un proyecto java en el cual genero un archivo PDF como reporte el cual al ejecutarlo con netbeans me genera el PDF sin ningún problema, pero cuando genero el archivo JAR me crea un PDF vacio inclusive ni sikiera lo puedo visualisar (pesa 0 bts), estoy usando una libreria FILE para darle un destino al PDF por ejemplo escritorio, he probado con artas direcciones en el pc y nada ni sikiera en las donde está el proyecto almacenado.. Espero me entiendan y que me puedan ayudar.. por siacaso les dejaré el codigo de fuente aquí, y de antemano Gracias!!!
BOTÓN CREAR PDF:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
if(t_direccionReporte.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Proporcione una dirección de destino para el PDF!!!");
}
else
{
String d = t_direccionReporte.getText();
try {
Document documento = new Document();
BarcodeQRCode my_code = new BarcodeQRCode("Folio del Equipo: "+t_reportefolio.getText(),75, 75, null);
//Image qr_image = my_code.getImage();
FileOutputStream archivo = new FileOutputStream(d+".pdf");
Document document = new Document();
PdfWriter.getInstance(document, archivo);
document.open();
//insercion de foto ------------------------//
Image foto = Image.getInstance("src/hevaro/icons/hevaro.jpg");
foto.scaleToFit(75, 75);
foto.setAlignment(Chunk.ALIGN_LEFT);
document.add(foto);
//----------------------------------//
//fuente para titulo//
Font fuente = new Font();
fuente.setSize(16);
fuente.setStyle(Font.BOLD);
//fuente para "datos cliente"//
Font fuente1 = new Font();
fuente1.setSize(12);
fuente1.setStyle(Font.BOLD);
//fuente para datos de "datos cliente"//
Font fuente2 = new Font();
fuente1.setSize(10);
fuente1.setStyle(Font.BOLD);
Paragraph titulo = new Paragraph("FICHA INGRESO EQUIPO",fuente);
titulo.setAlignment(Paragraph.ALIGN_CENTER);
document.add(titulo);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
// Este codigo genera una tabla de 3 columnas
PdfPTable table = new PdfPTable(4);
PdfPCell celdaInicial = new PdfPCell(new Paragraph("DATOS CLIENTE",fuente1));
celdaInicial.setColspan(4);
table.addCell(celdaInicial);
// addCell() agrega una celda a la tabla, el cambio de fila
// ocurre automaticamente al llenar la fila
table.addCell("Nombre : ");
table.addCell(t_reportenombre.getText());
table.addCell("Apellido :");
table.addCell(t_reporteapes.getText());
table.addCell("Rut :");
table.addCell(t_reporterut.getText());
table.addCell("Dirección :");
table.addCell(t_reportedir.getText());
table.addCell("Teléfono :");
table.addCell(t_reportetel.getText());
table.addCell("ID Cliente");
table.addCell(t_reporteidcliente.getText());
// Si desea crear una celda de mas de una columna
// Cree un objecto Cell y cambie su propiedad span
PdfPCell celdaFinal = new PdfPCell(new Paragraph(" "));
// Indicamos cuantas columnas ocupa la celda
celdaFinal.setColspan(3);
table.addCell(celdaFinal);
// Agregamos la tabla al documento
document.add(table);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
PdfPTable table2 = new PdfPTable(4);
PdfPCell celdaInicial2 = new PdfPCell(new Paragraph("DATOS EQUIPO",fuente1));
celdaInicial2.setColspan(4);
table2.addCell(celdaInicial2);
// addCell() agrega una celda a la tabla, el cambio de fila
// ocurre automaticamente al llenar la fila
table2.addCell("Folio Equipo: ");
table2.addCell(t_reportefolio.getText());
table2.addCell("Tipo Equipo : ");
table2.addCell(t_reportetipo.getText());
table2.addCell("Marca Equipo: ");
table2.addCell(t_reportemarca.getText());
table2.addCell("Modelo Equipo: ");
table2.addCell(t_reportemodelo.getText());
table2.addCell("Serie: ");
table2.addCell(t_reporteserie.getText());
table2.addCell("Estado de equipo: ");
table2.addCell(t_reporteestado.getText());
// Si desea crear una celda de mas de una columna
// Cree un objecto Cell y cambie su propiedad span
PdfPCell celdaFinal2 = new PdfPCell(new Paragraph("Final de la tabla"));
// Indicamos cuantas columnas ocupa la celda
celdaFinal2.setColspan(3);
table2.addCell(celdaFinal2);
// Agregamos la tabla al documento
document.add(table2);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
//inicia otra tabla para descripción y detalle del problema//
PdfPTable tabla = new PdfPTable(1);
PdfPCell celda1 = new PdfPCell(new Paragraph("Diagnóstico y detalle de reparación:",fuente1));
celda1.setColspan(4);
tabla.addCell(celda1);
tabla.addCell(t_reporteproblema.getText());
document.add(tabla);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
// document.add(qr_image);
Paragraph piepag = new Paragraph("Puede hacer el seguimiento de su equipo en : consultashevaro.ddns.net");
piepag.setAlignment(Paragraph.ALIGN_CENTER);
document.add(piepag);
document.close();
JOptionPane.showMessageDialog(null, "Archivo creado con exito!!!");
this.dispose();
} catch (FileNotFoundException ex) {
Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, ex);
} catch (DocumentException ex) {
Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Reportes.class.getName()).log(Level.SEVERE, null, ex);
}
}
BOTON PARA DAR LA DIRECCIÓN DE ALMACENAMIENTO DEL PDF:
1
2
3
4
5
6
7
8
9
JFileChooser dlg = new JFileChooser();
int Option = dlg.showSaveDialog(this);
if(Option == JFileChooser.APPROVE_OPTION){
File f = dlg.getSelectedFile();
String f1 = f.toString();
t_direccionReporte.setText(f1);
}
Espero sus comentarios.... Un Saludo.
Valora esta pregunta


0