Get count of Images Embedded in PDF File

[ ]

The following code snippet shows how to get names of images embedded inside PDF file.


 // Load source PDF file

Document pdfDocument = new Document("c:/input.pdf");

// create a variable to maintain total images count

int Total_Images=0;

// Iterate through each page of PDF document

 for (int pagecount = 1; pagecount <= pdfDocument.getPages().size(); pagecount++) {

	 // create a variable to track count of images in each page

	 int Images_per_page=0;

	 // Get the all images names from specific page of PDF file

	 for (int i = 0; i < pdfDocument.getPages().get_Item(pagecount).getResources().getImages().size(); i++) {

		 // Print the names of image file over console


		 // increase the count keeping track of images in each page

		 Images_per_page = Images_per_page+1;	


   // update the count of total images in PDF file

   Total_Images = Total_Images+Images_per_page;


 // print total images count in PDF file

 System.out.print("Total number of images = "+ Total_Images);