Skip to content

Commit

Permalink
Merge pull request #161 from felipewmartins/implementacao-danfe
Browse files Browse the repository at this point in the history
Alterando retorno do método de geração do danfe para byte[].
  • Loading branch information
fincatto committed Jun 12, 2016
2 parents cf0dc98 + 1877147 commit 42b1c65
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class NFDanfeReport {
private static InputStream in = null;
private static Document doc;
private static final Logger logger = LoggerFactory.getLogger(NFDanfeReport.class);
private static byte[] reportByte;

public static boolean imprimirDanfe(NFNota xmlNota, String pathDestino) {
public static byte[] imprimirDanfe(NFNota xmlNota) {

boolean retorno = false;
try {
classloader = Thread.currentThread().getContextClassLoader();
in = classloader.getResourceAsStream("danfe/danfeR3.jrxml");
Expand All @@ -42,20 +42,19 @@ public static boolean imprimirDanfe(NFNota xmlNota, String pathDestino) {
JRProperties
.setProperty("net.sf.jasperreports.xpath.executer.factory",
"net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");
logger.info("Montando estrutura...");
JasperPrint print = JasperFillManager.fillReport(report, null,
new JRXmlDataSource(
convertStringXMl2DOM(xmlNota.toString()),
"/NFe/infNFe/det"));
logger.info("Montando estrutura...");
JasperExportManager.exportReportToPdfFile(print, pathDestino);
logger.info("Gravando PDF...");
logger.info("Danfe impresso em: " + pathDestino);
retorno = true;
logger.info("Gerando array de bytes do PDF...");
reportByte = JasperExportManager.exportReportToPdf(print);
logger.info("danfe gerado!");
} catch (JRException e) {
// TODO Auto-generated catch block
e.getMessage();
}
return retorno;
return reportByte;

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.fincatto.nfe310.classes.danfe;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;

import com.fincatto.nfe310.FabricaDeObjetosFake;
Expand All @@ -10,7 +15,7 @@
public class NFGeraDanfeTest {

@Test
public void deveGerarDanfeAPartirDoXML() {
public void deveGerarDanfeAPartirDoXML() throws IOException {
final NFNota nota = new NFNota();
final NFSignature assinatura = new NFSignature();
assinatura.setSignatureValue("NFe89172658591754401086218048846976493475937081");
Expand All @@ -20,8 +25,10 @@ public void deveGerarDanfeAPartirDoXML() {
nota.setInfo(notaInfo);
nota.setIdentificadorLocal(identificadorLocal);
nota.toString();
NFDanfeReport.imprimirDanfe(nota, "/home/felipe/teste.pdf");
//Assert.assertTrue(NFDanfeReport.imprimirDanfe(nota, "/tmp/"));
FileOutputStream fos = new FileOutputStream("/tmp/danfe.pdf");
fos.write(NFDanfeReport.imprimirDanfe(nota));
fos.close();
Assert.assertTrue(new File("/tmp/danfe.pdf").exists());
}

}

0 comments on commit 42b1c65

Please sign in to comment.