Count Pages of PDF Document

com.acadoid.pdfview.action.COUNT_PAGES

counts the number of pages in a given PDF file

Input:

  • Uri of PDF file via Intent.putDataAndType() (should point to a file located on the SD card)

Output:

  • number of pages via Intent.getExtras().getInt(“PAGES”) (the number is zero if a problem occurred)
  • Uri of PDF file via Intent.putDataAndType() (Uri of PDF file, mirrored for convenience)

Use

public void startCountPagesOfPdfDocument() {
    Intent intent = new Intent("com.acadoid.pdfview.action.COUNT_PAGES"); 
    intent.setData(dataUri); // PDF file Uri 
    if (intent.resolveActivity(getPackageManager()) != null) { 
      startActivityForResult(intent, REQUEST_CODE);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) { 
      int pages = data.getIntExtra(PAGES);
      // handle result
    }
}

Example intent filter

<activity ...>
    <intent-filter>
        <action android:name="com.acadoid.pdfview.action.COUNT_PAGES" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>
            

Apps Providing an Implementation

Search on Github

Search on Google Play, AppBrain, Amazon App store or similar (not yet available - please make this happen!)

For Specification Writers

Edit on Github