Olá, quando estou tentando gerar um relatório em PDF via Jasper. Quando quando acesso o projeto da minha máquina, funciona normalmente.
Mas quando acesso do servidor em que o projeto está hospedado, ele faz download de um arquivo .xht com o seguinte conteúdo:
Erro no processamento de XML: formatação incorreta
Posição: file:///C:/Users/WORK/Desktop/null.xht
Número da linha 1, coluna 9:%PDF-1.4
--------^
Estou gerando o relatório da seguinte maneira:
public DefaultStreamedContent getSampleReportPDF() {
JasperPrint relat;
try {
relat = this.gerar();
ByteArrayOutputStream Teste = new ByteArrayOutputStream();
JRExporter exporter = new net.sf.jasperreports.engine.export.JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "orcamento");
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "orcamento");
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, Teste);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, relat);
exporter.exportReport();
relatorio = new ByteArrayInputStream(Teste.toByteArray());
return new DefaultStreamedContent(relatorio);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public JasperPrint gerar() throws Exception {
JasperPrint rel = null;
Connection connection = null;
try {
connection = ConnectionFactory.getConnection();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ID_ORCAMENTO", orcamento.getCodigo());
String arquivoJasper = FacesContext.getCurrentInstance()
.getExternalContext().getRealPath("/RELATORIOS")
+ "/orcamento.jasper";
System.out.println(arquivoJasper);
rel = JasperFillManager.fillReport(arquivoJasper, map, connection);
} catch (JRException e) {
e.printStackTrace();
}
return rel;
}
<p:commandButton rendered="true" id="exportar1" value="PDF" ajax="false">
<p:fileDownload value="#{orcamentoBean.sampleReportPDF}" />
</p:commandButton>