Does JasperReports support alternating gutter boundaries?

Many people who create PDF files need to link them. Good linking requires that every other page support an extra margin size on the left and right sides. I know that JasperReports did not support this in its 3.x series. Is this supported in the 4.x series?

+5
source share
3 answers

You can do marginMirroring, as Dave pointed out, by subclassing JRPdfExporter by overriding the method, exportReportToStream. Unfortunately, you will need to copy the source for this method to your override. In your override, you change the page loop, for example:

for(int pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++)
{
    int margin = marginLeft;
    if (pageIndex % 2 == 1) margin = marginRight;

    parameters.put(JRExporterParameter.OFFSET_X, margin);
    setOffset();
    ...

The constructor of my subclass takes in the fields:

public MirroringJRPdfExporter(int left, int right, int top, int bottom) {
    this.marginLeft = left;
    this.marginRight = right;
    this.marginTop = top;
    this.marginBottom = bottom;
}    

, .

: exportReportToStream JRPdfExporterTagHelper 2 , init setPdfWriter, , , . :

public class JRPdfExporterTagHelper extends
        net.sf.jasperreports.engine.export.JRPdfExporterTagHelper {

    protected JRPdfExporterTagHelper(JRPdfExporter exporter) {
        super(exporter);
    }

    public void setPdfWriter2(PdfWriter pdfWriter) {
        setPdfWriter(pdfWriter);
    }

    public void init2(PdfContentByte pdfContentByte) {
        init(pdfContentByte);
    }
} 

:

MirroringJRPdfExporter exporter = new MirroringJRPdfExporter(72, 36, 44, 31);

exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, output);
exporter.exportReport();
+4

JasperReports 6.x (jrxml),

<property name="net.sf.jasperreports.export.pdf.odd.page.offset.x" value="10"/>
<property name="net.sf.jasperreports.export.pdf.even.page.offset.x" value="-10"/>

JasperReports demo/samples/query/reports/QueryReport.jrxml. .

JRPdfExporter pdf Java:

JRPdfExporter exporter = new JRPdfExporter();
SimplePdfReportConfiguration configuration = new SimplePdfReportConfiguration();
configuration.setOddPageOffsetX(10);
configuration.setEvenPageOffsetX(-10);
exporter.setConfiguration(configuration);
+1

To work with jasper 5.6, besides the answer to @bigspotteddog, I did:

@Override
protected PdfReportConfiguration getCurrentItemConfiguration() {
    SimplePdfReportConfiguration config = new SimplePdfReportConfiguration();
    PdfReportConfiguration currentItemConfiguration = super.getCurrentItemConfiguration();
    config.setCollapseMissingBookmarkLevels(currentItemConfiguration.isCollapseMissingBookmarkLevels());
    config.setForceLineBreakPolicy(currentItemConfiguration.isForceLineBreakPolicy());
    config.setForceSvgShapes(currentItemConfiguration.isForceSvgShapes());
    config.setIgnoreHyperlink(currentItemConfiguration.isIgnoreHyperlink());
    config.setOverrideHints(currentItemConfiguration.isOverrideHints());
    config.setSizePageToContent(currentItemConfiguration.isSizePageToContent());
    config.setEndPageIndex(currentItemConfiguration.getEndPageIndex());
    config.setExporterFilter(currentItemConfiguration.getExporterFilter());
    config.setHyperlinkProducerFactory(currentItemConfiguration.getHyperlinkProducerFactory());
    config.setPageIndex(currentItemConfiguration.getPageIndex());
    config.setProgressMonitor(currentItemConfiguration.getProgressMonitor());
    config.setStartPageIndex(currentItemConfiguration.getStartPageIndex());

    config.setOffsetX(margin);

    return config;
}

and:

margin = marginLeft;
if (pageIndex % 2 == 1) margin = marginRight;

in a loop.

0
source

All Articles