Created
April 10, 2012 14:51
-
-
Save dennysfredericci/2351936 to your computer and use it in GitHub Desktop.
Download de boleto com vraptor e bopepo(jrimum.org)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
No controller: | |
@Get("/cobrancas/{cobranca.id}/boleto") | |
public Download gerarBoleto(@Load Cobranca cobranca) { | |
Boleto boleto = cobranca.gerarBoleto(); | |
BoletoDownload download = new BoletoDownload(boleto); | |
return download; | |
} | |
Classe para auxiliar o download: | |
public class BoletoDownload implements Download { | |
private List<Boleto> boletos = new LinkedList<Boleto>(); | |
private String filename = "boleto.pdf"; | |
public BoletoDownload(Boleto boleto) { | |
boletos.add(boleto); | |
} | |
public BoletoDownload(List<Boleto> boletos) { | |
this.boletos = boletos; | |
} | |
@Override | |
public void write(HttpServletResponse response) throws IOException { | |
byte[] bytes = BoletoViewer.groupInOnePDF(boletos); | |
ByteArrayDownload download = new ByteArrayDownload(bytes, "application/pdf", filename, true); | |
download.write(response); | |
} | |
public void setFilename(String filename) { | |
this.filename = filename + ".pdf"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment