Jhipster中报告的javascript生成
我正在开发一个以Jhipster为框架的应用程序,我需要在其中生成PDF格式的报告。 我的报告是用jasperreport开发的,或者是一个“.jasper”文件,它完成了参数传递,然后我必须返回一个“字节[]”,用angular打开它。 问题是,当我从服务器端打印到报表时,它工作正常,但当我通过“REST”将数据传递到angular并尝试在前端打开它时,它返回以下错误(加载文档PDF时出错)
下面我详细介绍了我的文件及其各自的代码:
印象。java(服务)
public ByteArrayOutputStream getImprimePresupuesto(PresupuestoDTO presupuestoDTO){
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
//Crear el mapa de parametros
Map<String,Object> parameters = new HashMap<>();
/// Datos de la empresa
parameters.put("p_empresa", presupuestoDTO.getSucursal().getEmpresa().getDescripcion());
parameters.put("p_eslogan", "Aca lo tengo que agregar en empresa");
parameters.put("p_ingBrutos", "Agregar ingresos Brutos a Empresa");
parameters.put("p_inicAct", "Agregar inicio de act a empresa");
parameters.put("p_domicEmpresa", "Agregar campo domicilio que sea string");
parameters.put("p_contactoEmpresa", "Agregar campo contacto que sea string el que sale en la factura");
parameters.put("p_cuitEmpresa", presupuestoDTO.getSucursal().getEmpresa().getCuit().toString() + " - Condicio IVA agregar Campo");
parameters.put("p_sucursal", presupuestoDTO.getSucursal().getDescripcion());
if (presupuestoDTO.getSucursal().getDomicilios() != null){
parameters.put("p_domicSucursal", presupuestoDTO.getSucursal().getDomicilios().toString());
}else{
parameters.put("p_domicSucursal", "Agregar campo domicilio que sea string");
}
if(presupuestoDTO.getSucursal().getContactos() != null){
parameters.put("p_contactoSucursal", presupuestoDTO.getSucursal().getContactos().toString());
}else{
parameters.put("p_contactoSucursal", "Agregar campo contacto que sea string el que sale en la factura");
}
//// Datos presupuesto
parameters.put("p_numero", presupuestoDTO.getNumero().toString());
parameters.put("p_fecha", presupuestoDTO.getFecha().toString());
parameters.put("p_validez", presupuestoDTO.getValidez().toString());
parameters.put("p_total", presupuestoDTO.getMonto().toString());
/// Datos Cliente
parameters.put("p_cliente", presupuestoDTO.getCliente().getPersona().getCuit().toString() + " - " + presupuestoDTO.getCliente().getPersona().getNombreCompleto());
if (presupuestoDTO.getCliente().getPersona().getDomicilios() != null){
parameters.put("p_domicCliente", presupuestoDTO.getCliente().getPersona().getDomicilios().toString());
}else{
parameters.put("p_domicCliente", "");
}
if (presupuestoDTO.getCliente().getPersona().getContactos() != null){
parameters.put("p_contactoCliente", presupuestoDTO.getCliente().getPersona().getContactos().toString());
}else{
parameters.put("p_contactoCliente", "");
}
/// Detalle del presupuesto
// /////
JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(presupuestoDTO.getDetallePresupuestos());
//// generacion del reporte
JasperReport report = (JasperReport) JRLoader.loadObject(this.getClass().getResourceAsStream("/reportes/transacciones/presupuesto.jasper"));
JasperPrint print = JasperFillManager.fillReport(report,parameters, ds);
JRPdfExporter exporter = new JRPdfExporter();
//JasperPrintManager.printReport(print, false);
exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, out);
exporter.exportReport();
log.debug("Presupuesto Impresion: {}", out);
return out;
} catch (JRException e) {
return null;
}
}
这是我们的资源。爪哇(其余)
@RestController
@RequestMapping("/api")
public class PresupuestoResource {
@GetMapping("/imprimirPresupuestos/{id}")
@Timed
public ResponseEntity<byte[]> getImprimirPresupuesto(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) throws JRException, IOException {
log.debug("Metodo GET de Imprimir Presupuesto : {}", id);
ServletContext scontext = request.getSession().getServletContext();
ByteArrayOutputStream reporte = presupuestoService.imprimir(id, scontext);
String filename = "presupuesto.pdf";
log.debug("Imprimir Presupuesto Sale sin error del service: {}", reporte);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("application/pdf"));
//headers.setContentType(MediaType.parseMediaType("application/pdf;charset=utf-8"));
headers.setContentDispositionFormData(filename, filename);
//headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-Disposition","attachment;filename=\"" + filename + "\"");
response.setContentType("application/pdf");
response.setContentLength(reporte.size());
if (reporte.toByteArray() != null && reporte.toByteArray().length > 0){
//ResponseEntity<byte[]> retorno = new ResponseEntity<byte[]>(reporte.toByteArray(), headers, HttpStatus.OK);
ResponseEntity<byte[]> retorno = ResponseEntity.ok()
.headers(HeaderUtil.createEntityUpdateAlert("presupuesto", String.valueOf(reporte.toByteArray().length)))
.body(reporte.toByteArray());
return retorno;
}
String erro = "Error";
return new ResponseEntity<byte[]>(erro.getBytes(), headers, HttpStatus.OK);
}
}
预先假定。服务js(服务角度)
(function() {
'use strict';
angular
.module('gcApp')
.factory('PresupuestoImp', PresupuestoImp);
PresupuestoImp.$inject = ['$resource'];
function PresupuestoImp ($resource) {
var resourceUrl = 'api/imprimirPresupuestos/:id';
return $resource(resourceUrl, {}, {
'query': { method: 'GET', isArray: true},
'get': {
method: 'GET',
responseType: 'arraybuffer'
//responseType: 'blob'
},
'update': { method:'PUT' }
});
}
})();
普雷斯托。控制器。js(控制器角度)
vm.imprimir = function (p_id) {
PresupuestoImp.get({id : p_id}, function (result) {
console.log(result.data);
var file = new window.Blob([result], {type: 'application/pdf'});
console.log(file);
var fileURL = URL.createObjectURL(file);
/*var a = document.createElement('a');
a.href = fileURL;
a.target = '_blank';
a.download = 'presupuesto.pdf';
document.body.appendChild(a);
a.click();*/
window.open(fileURL);
});
}
。JRXML
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1 -->
<!-- 2017-03-31T17:52:02 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="presupuesto" pageWidth="595" pageHeight="842" whenNoDataType="NoPages" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0c2b8f60-92c5-457b-8b2e-d798a44afcf2">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="p_empresa" class="java.lang.String"/>
<parameter name="p_eslogan" class="java.lang.String"/>
<parameter name="p_domicEmpresa" class="java.lang.String"/>
<parameter name="p_contactoEmpresa" class="java.lang.String"/>
<parameter name="p_cuitEmpresa" class="java.lang.String"/>
<parameter name="p_numero" class="java.lang.String"/>
<parameter name="p_fecha" class="java.lang.String"/>
<parameter name="p_validez" class="java.lang.String"/>
<parameter name="p_inicAct" class="java.lang.String"/>
<parameter name="p_ingBrutos" class="java.lang.String"/>
<parameter name="p_cliente" class="java.lang.String"/>
<parameter name="p_domicCliente" class="java.lang.String"/>
<parameter name="p_contactoCliente" class="java.lang.String"/>
<parameter name="p_total" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<pageHeader>
<band height="147" splitType="Stretch">
<staticText>
<reportElement x="221" y="36" width="100" height="13" uuid="9f24402a-9c42-48f7-9f10-e77a01c647bd"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[PRESUPUESTO]]></text>
</staticText>
<textField>
<reportElement x="452" y="99" width="95" height="15" uuid="3747741e-2468-45a5-b758-2caddf559d44"/>
<textFieldExpression><![CDATA[$P{p_inicAct}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="452" y="115" width="95" height="15" uuid="d3919bcc-adb3-44c4-859f-5c898ab74d87"/>
<textFieldExpression><![CDATA[$P{p_ingBrutos}]]></textFieldExpression>
</textField>
<rectangle>
<reportElement x="245" y="4" width="50" height="30" uuid="8dc1ee61-5c32-41fe-8aae-6d9b62e70ade"/>
</rectangle>
<staticText>
<reportElement x="342" y="4" width="102" height="20" uuid="947d5341-f3bc-43f7-8a59-f95ab836ddeb"/>
<textElement textAlignment="Right">
<font size="12" isBold="true"/>
</textElement>
<text><![CDATA[NUMERO :]]></text>
</staticText>
<textField>
<reportElement x="8" y="92" width="237" height="20" uuid="a8afab15-5e11-4494-b516-316096db8de9"/>
<textElement>
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_contactoEmpresa}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="245" y="5" width="50" height="30" uuid="a647a6f0-5dd7-424e-a5e5-6ee96cd20990"/>
<textElement textAlignment="Center">
<font size="18" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
</textElement>
<text><![CDATA[X]]></text>
</staticText>
<textField>
<reportElement x="8" y="36" width="187" height="20" uuid="6a0e8cff-0195-4e32-9138-cc93e352b43e"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_eslogan}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="346" y="115" width="102" height="15" uuid="e6166e57-ec07-4428-a727-928a349ef985"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Ing. Brutos :]]></text>
</staticText>
<textField>
<reportElement x="452" y="35" width="95" height="15" uuid="2c985390-a194-4a56-bad9-2cc57f5b0e8e"/>
<textFieldExpression><![CDATA[$P{p_fecha}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="8" y="8" width="187" height="20" uuid="9a535ca1-4fe8-4a77-869f-19b24f6026e6"/>
<textElement>
<font size="12"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_empresa}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="8" y="116" width="33" height="15" uuid="22c9bf5e-7027-49e8-8689-e57e432dc511"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[CUIT : ]]></text>
</staticText>
<staticText>
<reportElement x="346" y="99" width="102" height="15" uuid="c59db18d-6217-4acf-8fc3-91d507833d3f"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Inicio Actividades :]]></text>
</staticText>
<textField>
<reportElement x="8" y="71" width="237" height="20" uuid="948c445d-7bd0-4eef-a2a2-3907e2df80e8"/>
<textElement>
<font size="10" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_domicEmpresa}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="195" y="49" width="150" height="20" uuid="b499dc3f-7313-41de-932d-2fe8fc219b31"/>
<textElement textAlignment="Center"/>
<text><![CDATA[( NO Válido como FACTURA )]]></text>
</staticText>
<staticText>
<reportElement x="346" y="35" width="102" height="15" uuid="6873b2be-e935-4a88-83f8-dcd572cb2405"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Fecha :]]></text>
</staticText>
<textField>
<reportElement x="41" y="116" width="204" height="15" uuid="000715ee-fa1d-4a22-a947-ed22cc5d394c"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_cuitEmpresa}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="449" y="4" width="100" height="20" uuid="5ef97bae-6c17-4344-9fa1-947a9fef7529"/>
<textElement>
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_numero}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="346" y="54" width="102" height="15" uuid="700bae7d-f184-4f60-a179-e93d220b0e99"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Fecha Validez:]]></text>
</staticText>
<textField>
<reportElement x="452" y="54" width="95" height="15" uuid="d3d126ef-26fc-4eff-8575-b965e9216936"/>
<textFieldExpression><![CDATA[$P{p_validez}]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="89" splitType="Stretch">
<staticText>
<reportElement x="8" y="73" width="90" height="15" uuid="593263b4-260d-430d-bd56-19c4b687b22f"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Código]]></text>
</staticText>
<staticText>
<reportElement x="8" y="7" width="56" height="15" uuid="7ada98b9-5495-499d-8b41-572198a6b3bd"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Cliente :]]></text>
</staticText>
<textField>
<reportElement x="68" y="7" width="479" height="15" uuid="315b7bf7-d8c2-40e0-90ae-c15c12041811"/>
<textFieldExpression><![CDATA[$P{p_cliente}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="8" y="23" width="56" height="15" uuid="ff8d8f1b-da1a-482c-8ffc-62a4e10aa5a7"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Domicilio :]]></text>
</staticText>
<textField>
<reportElement x="68" y="23" width="479" height="15" uuid="752aa1de-f5ac-4e13-983f-6984b1c00ae8"/>
<textFieldExpression><![CDATA[$P{p_domicCliente}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="8" y="39" width="56" height="15" uuid="85955b43-91e9-4dd1-94e3-49989e5a8e9c"/>
<textElement textAlignment="Right">
<font isBold="true"/>
</textElement>
<text><![CDATA[Contacto :]]></text>
</staticText>
<textField>
<reportElement x="68" y="39" width="479" height="15" uuid="97a09610-1c1f-4757-a5d5-67730e029172"/>
<textFieldExpression><![CDATA[$P{p_contactoCliente}]]></textFieldExpression>
</textField>
<line>
<reportElement x="8" y="62" width="539" height="1" uuid="3186a9f2-4694-450d-9635-acb1c21396ba"/>
</line>
<staticText>
<reportElement x="98" y="73" width="237" height="15" uuid="82e4a5ef-5e2c-4442-ae60-471ad9bbb55d"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Descripción]]></text>
</staticText>
<staticText>
<reportElement x="335" y="73" width="70" height="15" uuid="a79152f4-3780-4eb1-9d91-d5d06e98ac2b"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[P. Unitario]]></text>
</staticText>
<staticText>
<reportElement x="405" y="73" width="58" height="15" uuid="0281fb18-dd96-4efe-866c-d54be9d1c038"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Cantidad]]></text>
</staticText>
<staticText>
<reportElement x="463" y="73" width="84" height="15" uuid="81c98750-5faf-416f-8006-e42425b14463"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Sub Total]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="18" splitType="Stretch">
<line>
<reportElement x="97" y="0" width="1" height="17" uuid="c75e9d08-001d-4935-a535-15f039e39834"/>
</line>
<line>
<reportElement x="335" y="0" width="1" height="17" uuid="f04b882f-607b-4044-9ad6-1c639f3bd5dc"/>
</line>
<line>
<reportElement x="405" y="0" width="1" height="17" uuid="64656ae1-d684-458d-8d62-6ac345d76b87"/>
</line>
<line>
<reportElement x="463" y="0" width="1" height="17" uuid="66f642ad-ade1-4780-9283-baa7e644e944"/>
</line>
<textField>
<reportElement x="8" y="0" width="89" height="17" uuid="37689cbc-89dd-49e3-a6b5-a5b6e3bfd3f4"/>
<textFieldExpression><![CDATA["123"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="97" y="0" width="238" height="17" uuid="689afa9d-650f-4ee3-8d71-26dd7181f9fa"/>
<textFieldExpression><![CDATA["Pruebas de impresion Fija"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="335" y="0" width="70" height="17" uuid="da224715-bbbe-4f1b-98a6-6432101340dd"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["200"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="405" y="0" width="58" height="17" uuid="79b9e1c0-1b26-4086-bf74-6712f2581f50"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["1"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="464" y="0" width="83" height="17" uuid="3417e7d7-d24a-4fff-8040-7ac20f38b994"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["200"]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="30" splitType="Stretch">
<textField>
<reportElement x="448" y="0" width="99" height="20" uuid="b1095b28-18c7-4c4e-9dd7-f38473cb410d"/>
<textElement textAlignment="Right">
<font size="11" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{p_total}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="394" y="0" width="54" height="20" uuid="f7c5b7d9-f63d-4078-8800-3eb247a0d6cd"/>
<textElement textAlignment="Right">
<font size="11" isBold="true"/>
</textElement>
<text><![CDATA[Total : ]]></text>
</staticText>
</band>
</columnFooter>
<pageFooter>
<band height="68" splitType="Stretch">
<textField>
<reportElement x="215" y="46" width="78" height="20" uuid="f657afd4-ce9d-42d2-ac9a-03db3b968057"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Página "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="293" y="46" width="52" height="20" uuid="77a13f9f-a104-4ddc-8a7f-4cccceff1982"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="8" y="4" width="54" height="15" uuid="689f5e8f-5897-4bfd-9f5c-b31f2a1d972a"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[Recuerde : ]]></text>
</staticText>
<staticText>
<reportElement x="62" y="4" width="485" height="28" uuid="41cbc489-f25c-402e-be81-d3e2eddd3424"/>
<textElement>
<font isBold="false"/>
</textElement>
<text><![CDATA[El presente presupuesto posee una validez, la cual se especifica en la cabecera del mismo.
Los precios de la mercadería pueden variar sin previo aviso, LA EMPRESA NO se responsabiliza.]]></text>
</staticText>
</band>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
共 (0) 个答案