Flow Images and Text onto multiple Pages

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF Generator for Java (v8)  /  Flow Images and Text onto multiple Pages

DynamicPDF Generator for Java (v8) Forum

Hello there,
I am currently trying to Generate a PDF with images, texts and Lists. So far it is working fine, but now i need to cut it down automatically to A4-Pages. How can I manage that? I found a solution for text only via getOverflowTextArea but nothing for mixed Elements.
Posted by a ceTe Software moderator

Regardless of the page size you can add page elements to the page and flow to the next page by keeping track of Y position. This will allow you to check for the available space on the page and then decide on adding next page element to the page. If the space available is not enough to fit page element then you can create a new Page and then add the page element to the new page. Below is the codes sample for adding page elements one below the other using calculated Y position. Image class doesn’t have an overflow method so it is not possible to overflow part of the image to the next page if it doesn’t fit.

           float currentYPosition = 0;
            Document document = new Document();
            Page page = new Page();
            string text = "Some Text::";
            for(int i=0;i<7;i++)
                text += text;
            TextArea area = new TextArea(text, 0, 0, 300, 400);
            area.Height = area.GetRequiredHeight();
            currentYPosition = area.Y + area.Height;
            //Adding another page element after the TextArea.
            float Xposition=0;
            float Yposition = currentYPosition + 5;
            Label label = new Label(text, Xposition, Yposition, 400, (page.Dimensions.Body.Height - Yposition));
            currentYPosition = label.Y + label.Height+10;
            //checking for empty space in the page to add the new page element or else creating a new page and add the page element.
            Page newPage=null ;
            if (currentYPosition >= page.Dimensions.Body.Height)
                newPage= new Page();
                currentYPosition = 0;
            Image image = new Image(@"C:\Temp\SampleImage.jpg",0,currentYPosition);
            if(newPage != null)

ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 9:10 PM.