0

I am creating a pdf with android itext lib. it shows complete data in single page. i want to split the single page to A4 size multiple pages with page number on bottom.

 private void callDocument(File file, Bitmap screen) throws Exception {
    try {

        com.itextpdf.text.Rectangle pagesize = new com.itextpdf.text.Rectangle(webview.getWidth(), webview.getHeight());
        Document document = new Document(pagesize, 0f, 0f, 0f, 0f);
        PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        screen.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] byteArray = stream.toByteArray();
        addImage(document, byteArray);
        document.close();
        sendEmailToGuest();

    } catch (Exception e) {
        e.printStackTrace();
    }

}

want to split single page to the multiple pages

Android
  • 1,420
  • 4
  • 13
  • 23

1 Answers1

0

You can create your document like this:

Document pdfDoc = new Document(PageSize.A4, 0f, 0f, 0f, 0f);

if you want your page rotated to landscape you can add .Rotate() after .A4 If max height of content is reached iText will create the new page.

Have a look at this answer https://stackoverflow.com/a/11206227/5840866 on a similar question about the page number at the end of the page. You can also use PdfPageEventHelper

Also have a look at this amazing examples from the official iText site that might give you a helping hand https://itextpdf.com/en/resources/examples/itext-7/event-handlers-and-renderers

  • Thanx Artion Hasani.I have tried this code but it creates the 1/4 part of the complete sheet in a rectangle manner. it also devides the width & height in proportion.which is not my requiremnt.Anywase thanx alot to you. – Kritika Monga Jun 25 '19 at 10:14