Accessing document's details on Android

Product: PDFTron Android SDK

Product Version: 9.2.1

Please give a brief summary of your issue:

Hi,

I have a problem using the library to be able to show document’s details on screen.

When I’m on another page than the viewer and I want to redirect the user to any document detail, I can’t seem to make it work properly.

I have the document relative path (something looking like “/document/145”). When I open the document in the viewer from another page with the document path it works just fine, but when I try creating a PDFDoc object so I can access all the document’s details, it doesn’t work as expected. I tried loading the document in the viewer first and then open the document details but for some reason it doesn’t work as well.

I tried giving the MANAGE_EXTERNAL_STORAGE permission in the app and nothing changed.

In the viewer we open the recent document that way :

if (showDetail) {
    documentViewModel.doc?.let {
        DocumentDetail(document = it, onNavigationIconClick = { setShowDetail(false) })
    }
}

In the recent document list code looks like that :

if (showDetail) {
    // Open the document in the viewer
    sdkViewModel.importDocument(Uri.parse(document.path))
    // Go to the viewer
    navHostController.navigate(Screen.Viewer.route)
    // Open the Document Detail view
    DocumentDetail(
        document = PDFDoc(Uri.parse(document.path).path),
        onNavigationIconClick = { setShowDetail(false) }
    )
}

Thanks.

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,

PDFDoc will require a full (absolute) path to your document. It will not work with a relative path (such as /document/145)

Could you provide a high level use case for your scenario so we can better understand the issue?

Could you explain the need for creating a PDFDoc object? Does it need to be separate from the Viewer? What kind of document details are you trying to extract?

Thanks,
Andrew.

I know that I need the absolute file path to create a PDFDoc but I can’t have it through Android. The most I can get from the file is this path : “content://com.android.providers.downloads.documents/document/145”.

The goal of the detail page is to look like that :

We already have this page available through the Viewer of our app, we use the PDFDoc object so we can access everything you can see on the screenshot above, and it’s actually working properly. But for some reason when from another page, I redirect to the Viewer and try opening the document’s details page it crash.
Here’s a gif of our app, what is supposed to happen at the end of the video is a redirect to the document’s details at the beginning of the gif.
ezgif.com-gif-maker

Hi @techbystamp

Thanks for getting back to us. From the GIF it appears you have the Viewer loading your document already. The viewer can provide the PDFDoc object for you to create your details page without the need to recreate the PDFDoc object.

Here is sample code on how to access it via the TabHostFragment:

Java:
PDFDoc pdfDoc = mPdfViewCtrlTabHostFragment.getCurrentPdfViewCtrlFragment().getPdfDoc();

Kotlin:
val pdfDoc = mPdfViewCtrlTabHostFragment?.currentPdfViewCtrlFragment?.pdfDoc

Thanks,
Andrew.