Skip to content

Open a Document

PDFViewCtrl provides multiple ways to open PDF documents: file paths, Android Uri, in-memory buffers, network URLs, and custom data sources.

Open from File Path

The most common approach. openDoc() creates PDFDoc, loads the document, and attaches it to PDFViewCtrl:

java
String path = "/sdcard/FoxitSDK/Sample.pdf";
pdfViewCtrl.openDoc(path, null);

You can also create PDFDoc manually and set it with setDoc():

java
try {
    PDFDoc doc = new PDFDoc(path);
    doc.load(null);
    pdfViewCtrl.setDoc(doc);
} catch (PDFException e) {
    e.printStackTrace();
}

Open from Android Uri

For files obtained via Intent, DocumentProvider, or SAF (Storage Access Framework):

java
Uri uri = data.getData();
pdfViewCtrl.openDoc(uri, null);

Open from Memory Buffer

When document data is already in memory (for example, decrypted bytes):

java
byte[] pdfBuffer = loadPdfBytes();
pdfViewCtrl.openDocFromMemory(pdfBuffer, null);

Open from Custom Data Source

Implement FileReaderCallback for custom read logic (encrypted storage, network streams, etc.):

java
pdfViewCtrl.openDoc(fileReaderCallback, null);

INFO

With a custom data source, you can also create PDFDoc via Core SDK:

java
PDFDoc doc = new PDFDoc(fileReaderCallback);
doc.load(null);
pdfViewCtrl.setDoc(doc);

Open from URL

openDocFromUrl() opens a PDF from a network URL; the SDK handles download and caching:

java
PDFViewCtrl.CacheOption cacheOption = new PDFViewCtrl.CacheOption();
cacheOption.setCacheFile("/sdcard/FoxitSDK/cache/sample.pdf");

pdfViewCtrl.openDocFromUrl(
    "https://example.com/sample.pdf", null, cacheOption, null);

CacheOption sets the local cache path; HttpRequestProperties sets custom HTTP headers.

NOTE

If opening from a URL shows incomplete content or fails to open, see Open PDF from URL troubleshooting.

Go to a Page After Open

The SDK renders on multiple threads. Call gotoPage() only after the document opens successfully. Use IDocEventListener.onDocOpened():

java
pdfViewCtrl.registerDocEventListener(new PDFViewCtrl.IDocEventListener() {
    @Override
    public void onDocWillOpen() {}

    @Override
    public void onDocOpened(PDFDoc pdfDoc, int errCode) {
        pdfViewCtrl.gotoPage(2);
    }

    @Override
    public void onDocWillClose(PDFDoc pdfDoc) {}

    @Override
    public void onDocClosed(PDFDoc pdfDoc, int i) {}

    @Override
    public void onDocWillSave(PDFDoc pdfDoc) {}

    @Override
    public void onDocSaved(PDFDoc pdfDoc, int i) {}
});

pdfViewCtrl.openDoc(path, null);

Close a Document

java
pdfViewCtrl.closeDoc();

After closeDoc(), PDFViewCtrl releases document resources and fires onDocWillClose and onDocClosed on IDocEventListener.

API Reference

See the API Reference for full PDFDoc and PDFViewCtrl documentation.