jasper报告每页生成一个pdf

时间:2019-06-27 06:46:11

标签: jasper-reports export-to-pdf

(使用Jaspersoft Studio 6.6.0,尚无Jasper Server) 我的数据集看起来像这样

import { Component, ViewChild } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import "ag-grid-enterprise";

@Component({
  selector: "my-app",
  template: `
    <ag-grid-angular
      #agGrid
      style="width: 100%; height: 100%;"
      id="myGrid"
      class="ag-theme-balham"
      [columnDefs]="columnDefs"
      [components]="components"
      [rowData]="rowData"
      (gridReady)="onGridReady($event)"
    ></ag-grid-angular>
<div style="position: absolute; top: 10px; left: 0px;">
      <div>
        <input type="checkbox" (change)="toggleCheckbox($event)"/>
      </div>
    </div>
  `
})
export class AppComponent {
  private gridApi;
  private gridColumnApi;

  private columnDefs;
  private defaultColDef;
  private components;
  private rowData: [];
  dataCopy;

  constructor(private http: HttpClient) {
    this.columnDefs = [
      {
        headerName: "Name",
        field: "name",
        width: 150,
        filter: "agSetColumnFilter",
        menuTabs: ['filterMenuTab']
      },
      {
        headerName: "Flag",
        field: "flag",
        width: 90,
        filter: "agNumberColumnFilter"
      }
    ];
    this.defaultColDef = {
      resizable: true,
      filter: true
    };
  }

  toggleCheckbox(event){
  if (event.target.checked) {
    this.rowData = this.dataCopy;
  } else {
    this.rowData = this.dataCopy.filter(obj => obj.flag === true);
  }
}

  onGridReady(params) {
    this.gridApi = params.api;
    this.gridColumnApi = params.columnApi;

    this.rowData = [
      {
        name: "A",
        flag: true
      },
      {
        name: "B",
        flag: false
      },
      {
        name: "C",
        flag: false
      },
      {
        name: "C",
        flag: true
      },
      {
        name: "W",
        flag: true
      },
      {
        name: "X",
        flag: false
      },
      {
        name: "Y",
        flag: false
      },
      {
        name: "Z",
        flag: true
      }
    ];
    this.dataCopy = [...this.rowData];
    this.rowData = this.dataCopy.filter(obj => obj.flag === true);
  }
}

该报告旨在每页显示一行

id|question1|question2|question3
1 |answer1.1|answer1.2|answer1.3
8 |answer8.1|answer8.2|answer8.3

如果我将报告生成为PDF,我将得到一份PDF,其页面数与行数相同。

但是我需要的是拥有与行一样多的单独PDF文件。这可能吗?

1 个答案:

答案 0 :(得分:0)

有一种简单的方法可以做到这一点。我不知道您是否是一名程序员,但我已经使用Java导出了多个报告。您可以简单地遍历行,每次循环时,使用ID或类似名称作为文件名来导出文件(否则,由于文件名已经存在,您将收到一个错误消息,或者您将覆盖旧的文件名, '最后一行仅取决于您的导出配置)

否则,您只需使用工具即可分割您的PDF,实际上有大量的PDF甚至在线。因此,您可以从这些解决方案中选择最适合您的方式。