title: how to add images into pdf with multiple pages in android
body: <p>Hi friends using below code i can able to add images into pdf file,in my case i have 3 images i am adding 3 images into pdf,now all three images are showing in pdf file single page,but i need to display 3 images in 3 pages into pdf file,below is my code can you any suggest me thank you..</p>
  
  <pre><code> MainActivity.class:
      public class MainActivity extends Activity {
  Integer imagesf[] = { R.drawable.apple_50, R.drawable.ic_launcher};
  Bitmap bitmap;
  Image myImg;
  private Button b;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) 
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      b= (Button)findViewById(R.id.button1);
      b.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              createPDF();
  
          }
      });
  
  }
  
  
  public void createPDF()
  {
      Document doc = new Document();
  
  
       try {
              String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/droidText";
  
              File dir = new File(path);
                  if(!dir.exists())
                      dir.mkdirs();
  
              Log.d("PDFCreator", "PDF Path: " + path);
  
  
              File file = new File(dir, "sample.pdf");
              FileOutputStream fOut = new FileOutputStream(file);
  
              PdfWriter.getInstance(doc, fOut);
  
              //open the document
              doc.open();
  
  
              Paragraph p1 = new Paragraph("Hi! I am generating my first PDF using DroidText");
              Font paraFont= new Font(Font.COURIER);
              p1.setAlignment(Paragraph.ALIGN_CENTER);
              p1.setFont(paraFont);
  
               //add paragraph to document    
               doc.add(p1);
  
               Paragraph p2 = new Paragraph("This is an example of a simple paragraph");
               Font paraFont2= new Font(Font.COURIER,14.0f,Color.GREEN);
               p2.setAlignment(Paragraph.ALIGN_CENTER);
               p2.setFont(paraFont2);
  
               doc.add(p2);
  
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.bg_w);
               bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream);
               Image myImg = Image.getInstance(stream.toByteArray());
               myImg.setAlignment(Image.MIDDLE);
                    doc.add(myImg);
  
               for(int i=0;i&lt;imagesf.length;i++)
                 {
                    ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
                  bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), imagesf[i]);
                  bitmap.compress(Bitmap.CompressFormat.JPEG, 100 , stream2);
                   myImg = Image.getInstance(stream2.toByteArray());
                  myImg.setAlignment(Image.MIDDLE);
                  doc.add(myImg);
  
                  }
  
              } catch (DocumentException de) {
               Log.e("PDFCreator", "DocumentException:" + de);
       } catch (IOException e) {
               Log.e("PDFCreator", "ioException:" + e);
       } 
       finally
       {
               doc.close();
       }
  
  }      
   }
  </code></pre>