Jump to content
We've recently updated our Privacy Statement, available here ×

two A5 in one A4


Rocco_swiss

Recommended Posts

Hi Friends. I am new to iReports & Japser Reports.

Im using i report 1.2.7.

I have designed a Report A5 format in landscape orientation.

My problem is to print the same Report A5 (2 copies)in one sheet A4.

 

something like that :

 

<A4>

<A5>

My report

</A5>

<A5>

Copy of My report

</A5>

</A4>

 

 

Thank for your suggestions!!

 

Rocco

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

 

It depends on how do you print your report and whether you always print it on A4.

But first thing I would try is to see if there is a printer setting that allows printing two pages in one.

I know my HP printer has that.

 

Another approach would be to take the JasperPrint object produced when generating the report and create a little program that creates another JasperPrint object by copying the styles and other report level information, but then creating half the number of pages in the initial document by merging the elements from two consecutive pages into one.

You'll be able to use the JR API to create and manipulate JasperPrint object content. You can check the /demo/samples/noreport sample provided with the project.

 

Yet a third approach would be to redesign the report and use it like a subreport into a master report that displays two records per page.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 5 years later...

Hi,

I have the same problem, I solved doing this:

 

 

JasperDesign jd = JRXmlLoader.load(ResourceUtils.getFile(getFileResourcesJRXML("myjasper_A5.jrxml")));
JasperReport jrRH02 = JasperCompileManager.compileReport(jd);
jp = JasperFillManager.fillReport(jrRH02, data, dataSource);
 
getResponse().setContentType("application/pdf");
ServletOutputStream outputStream = getResponse().getOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT, jp);
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, baos);
exporter.exportReport();
 
exporter.reset();
exporter = null;
System.gc();
 
Document document = new Document();
document.setPageSize(new Rectangle(jp.getPageWidth(), jp.getPageHeight() * 2)); // This is because A4 Size == 2 * A5
PdfReader pdfReader = new PdfReader(baos.toByteArray());
PdfWriter writer = PdfWriter.getInstance(document, outputStream);
document.open();
PdfContentByte cb = writer.getDirectContent();
for(int i = 1; i <= pdfReader.getNumberOfPages(); i++){
document.newPage();
PdfImportedPage page = writer.getImportedPage(pdfReader, i);
cb.addTemplate(page, 0, 0);
cb.addTemplate(page, 0, jp.getPageHeight());
}
 
outputStream.flush();
document.close();
 
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...