'Get values from a checkbox to create PDF
I'm working with dataTable in JSP. I need you to generate a PDF file with the data attached to a document X; I can already generate the PDF, the problem I have is that I need to only attach in the PDF the values I select in a checkBox.
The code I have in JSP is as follows:
<h:column>
<f:facet name="header">
<h:outputText value="Sel." />
</f:facet>
<h:selectBooleanCheckbox
value="#{edi.seleccion}"
title="Seleccionar" />
</h:column>
And the java code that generates the PDF file for me is as follows (a part of the code):
public void generarPdfDeclaracionLevante() throws IOException {
List<RobEdifactTO> listaRadicados = new ArrayList<RobEdifactTO>();
dataItemRobEdifactTO.setNuDo(dataItemRobAdminImpoTO.getNuDo());
dataItemRobEdifactTO.setNuAnoDo(dataItemRobAdminImpoTO.getNuAnoDo());
Integer cantidadDeclaraciones = robEdifactCtrl.consultarCantidadDeclaraciones(dataItemRobEdifactTO);
Integer cantidadEdifact = robEdifactCtrl.consultarCantidadDeclaracionesLevante(dataItemRobEdifactTO);
if(cantidadDeclaraciones > 0 && (cantidadEdifact > 0 || cantidadEdifact == 0)) {
if(cantidadDeclaraciones == cantidadEdifact) {
listaRadicados = robEdifactCtrl.consultaImprimeAceptacionDef(dataItemRobEdifactTO);
if(listaRadicados.size() > 0)
{
HttpServletResponse response = (HttpServletResponse) this.getFacesContext().getExternalContext().getResponse();
List<RobEdifactTO> listaDeclaraciones = new ArrayList<RobEdifactTO>();
List < Document > listaHtmlJsoup = new ArrayList <> ( );
PdfDocument pdf = new PdfDocument ( new PdfWriter(response.getOutputStream()) );
PdfMerger merger = new PdfMerger ( pdf );
// Configuracion de los header de la respuesta
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=\"declaraciones.pdf\"");
// Configuracion de objeto properties
ConverterProperties properties = new ConverterProperties ( );
// Configuracion de las fuentes del sistema
properties.setFontProvider(new DefaultFontProvider(true, false, false));
// Consulta de los datos que se van a imprimir
listaDeclaraciones = listaRadicados;
// Recorremos los html para modificar sus atributos
for ( RobEdifactTO declaracion : listaDeclaraciones) {
listaHtmlJsoup.add ( generarFrenteDeclaracion(declaracion.getCaDeclaracionFrente()) );
listaHtmlJsoup.addAll ( generarDorsoDeclaracion(declaracion.getCaDeclaracionDorso()) );
}
try {
for ( Document htmlItem : listaHtmlJsoup ) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream ( );
PdfDocument paginaTemporalPdf = new PdfDocument ( new PdfWriter ( byteArrayOutputStream ) );
HtmlConverter.convertToPdf ( new ByteArrayInputStream ( htmlItem.toString ( ).getBytes ( StandardCharsets.UTF_8 ) ), paginaTemporalPdf, properties );
paginaTemporalPdf = new PdfDocument ( new PdfReader ( new ByteArrayInputStream ( byteArrayOutputStream.toByteArray ( ) ) ) );
merger.merge ( paginaTemporalPdf, 1, paginaTemporalPdf.getNumberOfPages ( ) );
paginaTemporalPdf.close ( );
}
contador = 0;
pdf.close ( );
this.getFacesContext().getCurrentInstance().responseComplete();
} catch (IOException e) {
e.printStackTrace ( );
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|