0

I have a JasperPrint that is exported to PDF and it's showing embedded into a web page.

Is it possible to set the initial zoom in any way?

I know how to do it with POI (by javascript), but I don't find the way to add the JavaScript code in Jasper...

EDIT:

Thanks to the link of @ AlexK, I found the solution :)

public ByteArrayOutputStream fillPDF(JasperPrint jasperPrint) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try{
        JRPdfExporter exporter = new  JRPdfExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.zoom = 70;");
        exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,baos); 
        exporter.exportReport(); 
    }catch (Throwable e){
    }
    return baos;
}
ganzux
  • 874
  • 3
  • 15
  • 35

1 Answers1

0

The answer by @ganzux. The zoom can be set with help of JavaScript.

The expression will be: this.zoom = 70;

The snippet is:

public ByteArrayOutputStream fillPDF(JasperPrint jasperPrint) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try{
        JRPdfExporter exporter = new  JRPdfExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRPdfExporterParameter.PDF_JAVASCRIPT, "this.zoom = 70;");
        exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM,baos); 
        exporter.exportReport(); 
    }catch (Throwable e){
    }
    return baos;
}
Alex K
  • 22,315
  • 19
  • 108
  • 236