Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions) Summary: [Nested Classes](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#nestedclasses) \| [Constants](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#constants) \| [Ctors](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#pubctors) \| [Methods](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#inhmethods)

# PdfRendererPreV

*** ** * ** ***

` public final class PdfRendererPreV `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/java/lang/AutoCloseable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.pdf.PdfRendererPreV |

<br />

*** ** * ** ***

<br />

This class enables rendering a PDF document and selecting, searching, fast scrolling, annotations, etc from Android R till Android U. This class is thread safe and can be called by multiple threads however only one thread will be executed at a time as the access is synchronized by internal locking.

If you want to render a PDF, you will need to create a new instance of renderer for each document. To render each page, you open the page using the renderer instance created earlier, render it, and close the page. After you are done with rendering, you close the renderer. After the renderer is closed it should not be used anymore. Note that the pages are rendered one by one, i.e. you can have only a single page opened at any given time.

A typical use of the APIs to render a PDF looks like this:

```
// create a new renderer
try (PdfRendererPreV renderer = new PdfRendererPreV(getSeekableFileDescriptor(), loadParams)) {
     // let us just render all pages
     final int pageCount = renderer.getPageCount();
     for (int i = 0; i < pageCount; i++) {
         Page page = renderer.openPage(i);
         RenderParams params = new RenderParams.Builder(Page.RENDER_MODE_FOR_DISPLAY).build();

         // say we render for showing on the screen
         page.render(mBitmap, params, null, null);

         // do stuff with the bitmap

         // close the page
         page.close();
     }
}
```

### Print preview and print output

Please refer to `https://developer.android.com/reference/android/graphics/pdf/PdfRenderer` for fulfilling this usecase.

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV.Page` This class represents a PDF document page for rendering. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#DOCUMENT_LINEARIZED_TYPE_LINEARIZED` Represents a linearized PDF document. |
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#DOCUMENT_LINEARIZED_TYPE_NON_LINEARIZED` Represents a non-linearized PDF document. |
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_ACRO_FORM` Represents a PDF with form fields specified using the AcroForm spec |
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_NONE` Represents a PDF without form fields |
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_XFA_FOREGROUND` Represents a PDF with form fields specified using the XFAF subset of the XFA spec |
| `int` | `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_XFA_FULL` Represents a PDF with form fields specified using the entire XFA spec |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PdfRendererPreV(android.os.ParcelFileDescriptor)(https://developer.android.com/reference/android/os/ParcelFileDescriptor fileDescriptor) ` Creates a new instance of PdfRendererPreV class. |
| ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PdfRendererPreV(android.os.ParcelFileDescriptor,%20android.graphics.pdf.LoadParams)(https://developer.android.com/reference/android/os/ParcelFileDescriptor fileDescriptor, https://developer.android.com/reference/android/graphics/pdf/LoadParams params) ` Creates a new instance of PdfRendererPreV class. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()() ` Closes this renderer and destroys any cached instance of the document. |
| ` int` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#getDocumentLinearizationType()() ` Gets the type of the PDF document. |
| ` int` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#getPageCount()() ` Gets the number of pages in the document. |
| ` int` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#getPdfFormType()() ` Returns the form type of the loaded PDF |
| ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV.Page` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#openPage(int)(int index) ` Opens a `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV.Page` for rendering. |
| ` void` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#write(android.os.ParcelFileDescriptor,%20boolean)(https://developer.android.com/reference/android/os/ParcelFileDescriptor destination, boolean removePasswordProtection) ` <br /> Saves the current state of the loaded PDF document to the given writable `https://developer.android.com/reference/android/os/ParcelFileDescriptor`. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/java/lang/AutoCloseable ` ` abstract void` ` https://developer.android.com/reference/java/lang/AutoCloseable#close()() `

Closes this resource, relinquishing any underlying resources.

## Constants

### DOCUMENT_LINEARIZED_TYPE_LINEARIZED

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int DOCUMENT_LINEARIZED_TYPE_LINEARIZED
```

Represents a linearized PDF document.

<br />

Constant Value: 1 (0x00000001)

### DOCUMENT_LINEARIZED_TYPE_NON_LINEARIZED

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int DOCUMENT_LINEARIZED_TYPE_NON_LINEARIZED
```

Represents a non-linearized PDF document.

<br />

Constant Value: 0 (0x00000000)

### PDF_FORM_TYPE_ACRO_FORM

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int PDF_FORM_TYPE_ACRO_FORM
```

Represents a PDF with form fields specified using the AcroForm spec

<br />

Constant Value: 1 (0x00000001)

### PDF_FORM_TYPE_NONE

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int PDF_FORM_TYPE_NONE
```

Represents a PDF without form fields

<br />

Constant Value: 0 (0x00000000)

### PDF_FORM_TYPE_XFA_FOREGROUND

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int PDF_FORM_TYPE_XFA_FOREGROUND
```

Represents a PDF with form fields specified using the XFAF subset of the XFA spec

<br />

Constant Value: 3 (0x00000003)

### PDF_FORM_TYPE_XFA_FULL

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public static final int PDF_FORM_TYPE_XFA_FULL
```

Represents a PDF with form fields specified using the entire XFA spec

<br />

Constant Value: 2 (0x00000002)

## Public constructors

### PdfRendererPreV

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public PdfRendererPreV (ParcelFileDescriptor fileDescriptor)
```

Creates a new instance of PdfRendererPreV class.

**Note:** The provided file descriptor must be **seekable**, i.e. its data being randomly accessed, e.g. pointing to a file.

**Note:** This class takes ownership of the passed in file descriptor and is responsible for closing it when the renderer is closed.

If the file is from an untrusted source it is recommended to run the renderer in a separate, isolated process with minimal permissions to limit the impact of security exploits.

<br />

| Parameters ||
|---|---|
| `fileDescriptor` | `ParcelFileDescriptor`: Seekable file descriptor to read from. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an error occurs while reading the file. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the `https://developer.android.com/reference/android/os/ParcelFileDescriptor` is not seekable. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | If the file descriptor is null. |
| `https://developer.android.com/reference/java/lang/SecurityException` | If the file requires a password or the security scheme is not supported by the renderer. |

### PdfRendererPreV

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public PdfRendererPreV (ParcelFileDescriptor fileDescriptor, 
                LoadParams params)
```

Creates a new instance of PdfRendererPreV class.

**Note:** The provided file descriptor must be **seekable** , i.e. its data being randomly accessed, e.g. pointing to a file. If the password passed in `https://developer.android.com/reference/android/graphics/pdf/LoadParams` is incorrect, the `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV` will throw a `https://developer.android.com/reference/java/lang/SecurityException`.

**Note:** This class takes ownership of the passed in file descriptor and is responsible for closing it when the renderer is closed.

If the file is from an untrusted source it is recommended to run the renderer in a separate, isolated process with minimal permissions to limit the impact of security exploits.

<br />

| Parameters ||
|---|---|
| `fileDescriptor` | `ParcelFileDescriptor`: Seekable file descriptor to read from. This value cannot be `null`. <br /> |
| `params` | `LoadParams`: Instance of `https://developer.android.com/reference/android/graphics/pdf/LoadParams` specifying params for loading PDF document. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If an error occurs while reading the file. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the `https://developer.android.com/reference/android/os/ParcelFileDescriptor` is not seekable. |
| `https://developer.android.com/reference/java/lang/NullPointerException` | If the file descriptor or load params is null. |
| `https://developer.android.com/reference/java/lang/SecurityException` | If the file requires a password or the security scheme is not supported by the renderer. |

## Public methods

### close

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void close ()
```

Closes this renderer and destroys any cached instance of the document. You should not use this instance after this method is called.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()` is called before invoking this. |

### getDocumentLinearizationType

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public int getDocumentLinearizationType ()
```

Gets the type of the PDF document.

<br />

| Returns ||
|---|---|
| `int` | The PDF document type. Value is one of the following: - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#DOCUMENT_LINEARIZED_TYPE_NON_LINEARIZED` - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#DOCUMENT_LINEARIZED_TYPE_LINEARIZED` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()` is called before invoking this. |

### getPageCount

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public int getPageCount ()
```

Gets the number of pages in the document.

<br />

| Returns ||
|---|---|
| `int` | The page count. Value is 0 or greater <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()` is called before invoking this. |

### getPdfFormType

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public int getPdfFormType ()
```

Returns the form type of the loaded PDF

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_NONE` - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_ACRO_FORM` - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_XFA_FULL` - `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#PDF_FORM_TYPE_XFA_FOREGROUND` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | if an unexpected PDF form type is returned |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the renderer is closed |

### openPage

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public PdfRendererPreV.Page openPage (int index)
```

Opens a `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV.Page` for rendering.

<br />

| Parameters ||
|---|---|
| `index` | `int`: The page index to open, starting from index 0. Value is 0 or greater <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV.Page` | A page that can be rendered. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the page number is less than 0 or greater than or equal to the total page count. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()` is called before invoking this. |

### write

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 13](https://developer.android.com/sdkExtensions)

```
public void write (ParcelFileDescriptor destination, 
                boolean removePasswordProtection)
```

<br />

Saves the current state of the loaded PDF document to the given writable `https://developer.android.com/reference/android/os/ParcelFileDescriptor`. If the document is password-protected then setting `removePasswordProtection` removes the protection before saving. The PDF document should already be decrypted with the correct password before writing. Useful for printing or sharing. **Note:** This method closes the provided file descriptor.

<br />

| Parameters ||
|---|---|
| `destination` | `ParcelFileDescriptor`: The writable `https://developer.android.com/reference/android/os/ParcelFileDescriptor` This value cannot be `null`. <br /> |
| `removePasswordProtection` | `boolean`: If true, removes password protection from the PDF before saving. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/io/IOException` | If there's a write error, or if 'removePasswordSecurity' is `true` but the document remains encrypted. |
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If `https://developer.android.com/reference/android/graphics/pdf/PdfRendererPreV#close()` is called before invoking this. |

## Protected methods

### finalize

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void finalize ()
```

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the `finalize` method to dispose of system resources or to perform other cleanup.

The general contract of `finalize` is that it is invoked if and when the Java virtual machine has determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, except as a result of an action taken by the finalization of some other object or class which is ready to be finalized. The `finalize` method may take any action, including making this object available again to other threads; the usual purpose of `finalize`, however, is to perform cleanup actions before the object is irrevocably discarded. For example, the finalize method for an object that represents an input/output connection might perform explicit I/O transactions to break the connection before the object is permanently discarded.

The `finalize` method of class `Object` performs no special action; it simply returns normally. Subclasses of `Object` may override this definition.

The Java programming language does not guarantee which thread will invoke the `finalize` method for any given object. It is guaranteed, however, that the thread that invokes finalize will not be holding any user-visible synchronization locks when finalize is invoked. If an uncaught exception is thrown by the finalize method, the exception is ignored and finalization of that object terminates.

After the `finalize` method has been invoked for an object, no further action is taken until the Java virtual machine has again determined that there is no longer any means by which this object can be accessed by any thread that has not yet died, including possible actions by other objects or classes which are ready to be finalized, at which point the object may be discarded.

The `finalize` method is never invoked more than once by a Java virtual machine for any given object.

Any exception thrown by the `finalize` method causes the finalization of this object to be halted, but is otherwise ignored.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |