Jump to content
Changes to the Jaspersoft community edition download ×

How To Merge a Landscape Document in the PDF Document Resizing and Fitting within Border Using Jasper


Recommended Posts

I have a program in java which uses Jasper to generate the Reports. It merges the Bill Receipt while merging them in the main Report. Bill Receipt can be in Landscape or Portrait form.Below is the code to Merge. If its a Portrait Receipt its merging fine. But for Landscape Receipt, the borders are exceeding the A4 size leading to loss of receipt at both sides. Therefore I want to Resize the receipt if its in a Landscape format and fit it within the boundaries of the PDF document while merging. Also giving some spaces at borders.

 

public void mergeCtcDocument(List<InputStream> list, OutputStream outputStream) throws DocumentException, IOException {    Document document = new Document();    PdfWriter writer = PdfWriter.getInstance(document, outputStream);    document.open();    PdfContentByte cb = writer.getDirectContent();    for (InputStream in : list) {        PdfReader reader = new PdfReader(in);        for (int i = 1; i <= reader.getNumberOfPages(); i++) {            document.newPage();            //import the page from source pdf            PdfImportedPage page = writer.getImportedPage(reader, i);            //Set content to the center            float x = (document.getPageSize().getWidth() - page.getWidth())/2;            float y = (document.getPageSize().getHeight() - page.getHeight())/2;            //add the page to the destination pdf            cb.addTemplate(page, x, y);        }    }    outputStream.flush();    document.close();    outputStream.close();    for(InputStream in : list) {        in.close();    }}[/code]
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...