Skip to content

Instantly share code, notes, and snippets.

@dennysfredericci
Created April 10, 2012 14:51
Show Gist options
  • Save dennysfredericci/2351936 to your computer and use it in GitHub Desktop.
Save dennysfredericci/2351936 to your computer and use it in GitHub Desktop.
Download de boleto com vraptor e bopepo(jrimum.org)
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