public class

ViewerUtils

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.utils.ViewerUtils

Class Overview

A utility class for pdf viewer

Summary

Constants
String IMAGE_DPI_CONVERSION_OPTION
Public Constructors
ViewerUtils()
Public Methods
static void addPageToBookmark(Context context, boolean isReadOnly, PDFViewCtrl pdfViewCtrl, int page)
Adds a page bookmark
static void animateScreenRect(PDFViewCtrl pdfViewCtrl, Rect screenRect)
static void animateUndoRedo(PDFViewCtrl pdfViewCtrl, Rect annotRect, int pageNum)
Animates for showing undo/redo action.
static boolean checkImageIntent(Map imageIntent)
Checks whether the internal image intent map is valid.
static StateListDrawable createBackgroundSelector(Drawable drawable)
static void createFileAttachment(Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, PointF targetPoint)
static void createFileIntent(Activity activity, Fragment fragment, String fileName, String mimeType)
Send a generic file creation intent
static void createImageSignature(Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, Uri outputFileUri, PointF targetPoint, int targetPage, Long widget)
static void createImageStamp(Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, Uri outputFileUri, PointF imageStampTargetPoint)
static boolean exportFileAttachment(PDFViewCtrl pdfViewCtrl, FileAttachment attachment, Uri targetUri)
Export file attachment to target URI, return whether successful.
static String exportFileAttachment(PDFViewCtrl pdfViewCtrl, FileAttachment attachment, File directory)
static String exportFileAttachment(PDFViewCtrl pdfViewCtrl, FileAttachment attachment)
static String extractFileFromPortfolio(int type, Context context, PDFDoc portfolioDoc, String destFolderPath, String fileName)
static String extractFileFromPortfolio(int type, Context context, PDFDoc portfolioDoc, String destFolderPath, Uri destFileUri, String fileName)
static extractFileFromPortfolioDisposable(int type, Context context, PDFDoc portfolioDoc, String destFolderPath, Uri destFileUri, String fileName)
static void flattenDoc(PDFDoc doc)
static Annot getAnnotById(PDFDoc pdfDoc, String id, int pageNum)
Returns annotation by providing its ID.
static Annot getAnnotById(PDFViewCtrl ctrl, String id, int pageNum)
Returns annotation by providing its ID.
static BitmapDrawable getBitmapDrawable(Context context, int drawableId, int width, int height, int targetColor, boolean roundedCorner, boolean nonWhiteOnly)
static BitmapDrawable getBitmapDrawable(Context context, int drawableId, int width, int height, int targetColor, boolean roundedCorner)
static Intent getFileIntent(String fileName, String mimeType)
Send a generic file creation intent
static Bitmap getImageBitmap(Context context, Map imageIntent)
Returns the image bitmap.
static Bitmap getImageBitmap(Context context, Uri imageUri, String filePath)
Returns the image bitmap.
static String getImageFilePath(Map imageIntent)
Returns the image file path.
static String getImageSignaturePath(Activity activity, Intent data, Uri outputFileUri)
static Uri getImageUri(Map imageIntent)
Returns the image URI
static Uri getImageUriFromIntent(Intent data, Activity activity, Uri outputFileUri)
static int getLastHPosForURL(Context context, String url)
static int getLastPageForURL(Context context, String url)
static int getLastVPosForURL(Context context, String url)
static double getLastZoomForURL(Context context, String url)
static ArrayList<MenuEditorItem> getMenuEditorItemsArray(String savedToolbarMenu)
This method is deprecated. No replacement.
static String getMenuEditorItemsJSON(ArrayList<MenuEditorItem> newMenuItems)
This method is deprecated. No replacement.
static PageSet getPageSet(SparseBooleanArray positions)
Converts page positions to the page set
static int getRotationForURL(Context context, String url)
static String getSelectedString(PDFViewCtrl pdfViewCtrl, boolean appendNewLine)
Returns selected text in pdf
static String getSelectedString(PDFViewCtrl pdfViewCtrl)
Returns selected text in pdf
static String imageIntentToPdf(Context context, Uri imageUri, String imagePath, ExternalFileInfo documentFile)
Converts image to PDF from an image intent
static String imageIntentToPdf(Context context, Uri imageUri, String imagePath, String outputPath)
Converts image to PDF from an image intent
static void importAnnotationCommand(PDFViewCtrl pdfViewCtrl, String xfdfCommand)
Import annotation XFDF command to the document
static boolean isContinuousPageMode(PDFViewCtrl pdfViewCtrl)
Checks if the tab is in continuous page mode.
static boolean isImageFromCamera(Map imageIntent)
Checks whether the image is taken from camera.
static boolean isInFullScreenMode(Context context)
static boolean isNonContinuousVerticalPageMode(PDFViewCtrl pdfViewCtrl)
Checks if the tab is in continuous snapping page mode.
static boolean isSinglePageMode(PDFViewCtrl pdfViewCtrl)
Checks if the tab is in single page mode.
static boolean isViewerZoomed(PDFViewCtrl pdfViewCtrl)
Checks whether the PDFViewCtrl is zoomed.
static void jumpToAnnotation(PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)
Jumps to the specified annotation.
static void jumpToRect(PDFViewCtrl pdfViewCtrl, Rect rect, int pageNum)
static void keepOnScreenAfterClick(Context context, MenuItem item)
Prevents menu item from closing its popup menu on click
static Uri openCameraIntent(Activity activity, int requestCode)
static void openFileIntent(Fragment fragment)
Send a generic file picker intent
static void openFileIntent(Activity activity, Fragment fragment)
Send a generic file picker intent
static void openFileIntent(Activity activity)
Send a generic file picker intent
static Uri openGalleryIntent(Activity activity, int requestCode)
static Uri openGalleryIntent(Activity activity, int requestCode, boolean multiSelect)
static Uri openImageIntent(Fragment fragment, boolean multiSelect)
static Uri openImageIntent(Activity activity, int requestCode)
static Uri openImageIntent(Fragment fragment, int requestCode)
static Uri openImageIntent(Fragment fragment)
static Uri openImageIntent(Activity activity)
static void passwordDoc(PDFDoc doc, String password)
static Map readImageIntent(Intent data, Context context, Uri outputFileUri)
Reads an image intent.
static List<Map<String, Object>> readMultiImageIntent(Intent data, Context context, Uri outputFileUri, boolean parseMultiImage)
Reads an image intent with option to parse multi image.
static void removePageBookmark(Context context, boolean isReadOnly, PDFViewCtrl pdfViewCtrl, int page)
Removes a page bookmark
static void renameAllFields(Page page)
static void safeUpdatePageLayout(PDFViewCtrl pdfViewCtrl)
static void safeUpdatePageLayout(PDFViewCtrl pdfViewCtrl, ExceptionHandlerCallback callback)
Safe version of updatePageLayout, will call readLock before and unlock after this operation as recommended by Core Team

Updates the page layout within the view.

static Rect scrollToAnnotRect(PDFViewCtrl pdfViewCtrl, Rect annotRect, int pageNum)
Scroll to annotation rect.
static void setLastPageForURL(Context context, String url, int page)
static void setLastPageStateForURL(Context context, String url, double zoom, int hPos, int vPos, int rotation)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String IMAGE_DPI_CONVERSION_OPTION

Constant Value: "{"DPI": 96.0}"

Public Constructors

public ViewerUtils ()

Public Methods

public static void addPageToBookmark (Context context, boolean isReadOnly, PDFViewCtrl pdfViewCtrl, int page)

Adds a page bookmark

Parameters
context the context
isReadOnly whether to edit the original pdf
pdfViewCtrl the PDFViewCtrl
page the page to add to bookmark

public static void animateScreenRect (PDFViewCtrl pdfViewCtrl, Rect screenRect)

public static void animateUndoRedo (PDFViewCtrl pdfViewCtrl, Rect annotRect, int pageNum)

Animates for showing undo/redo action.

Parameters
pdfViewCtrl The PDFViewCtrl
annotRect The annotation rectangle to be animated
pageNum The page number

public static boolean checkImageIntent (Map imageIntent)

Checks whether the internal image intent map is valid.

Parameters
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)
Returns
  • True if the internal image intent is valid

public static StateListDrawable createBackgroundSelector (Drawable drawable)

public static void createFileAttachment (Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, PointF targetPoint)

public static void createFileIntent (Activity activity, Fragment fragment, String fileName, String mimeType)

Send a generic file creation intent

public static void createImageSignature (Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, Uri outputFileUri, PointF targetPoint, int targetPage, Long widget)

public static void createImageStamp (Activity activity, Intent data, PDFViewCtrl pdfViewCtrl, Uri outputFileUri, PointF imageStampTargetPoint)

public static boolean exportFileAttachment (PDFViewCtrl pdfViewCtrl, FileAttachment attachment, Uri targetUri)

Export file attachment to target URI, return whether successful.

public static String exportFileAttachment (PDFViewCtrl pdfViewCtrl, FileAttachment attachment, File directory)

public static String exportFileAttachment (PDFViewCtrl pdfViewCtrl, FileAttachment attachment)

public static String extractFileFromPortfolio (int type, Context context, PDFDoc portfolioDoc, String destFolderPath, String fileName)

public static String extractFileFromPortfolio (int type, Context context, PDFDoc portfolioDoc, String destFolderPath, Uri destFileUri, String fileName)

public static extractFileFromPortfolioDisposable (int type, Context context, PDFDoc portfolioDoc, String destFolderPath, Uri destFileUri, String fileName)

public static void flattenDoc (PDFDoc doc)

public static Annot getAnnotById (PDFDoc pdfDoc, String id, int pageNum)

Returns annotation by providing its ID.

Parameters
pdfDoc The PDFDoc
id The ID of the annotation
pageNum The page number
Returns
  • The annotation having the specified ID

public static Annot getAnnotById (PDFViewCtrl ctrl, String id, int pageNum)

Returns annotation by providing its ID.

Parameters
ctrl The PDFViewCtrl
id The ID of the annotation
pageNum The page number
Returns
  • The annotation having the specified ID

public static BitmapDrawable getBitmapDrawable (Context context, int drawableId, int width, int height, int targetColor, boolean roundedCorner, boolean nonWhiteOnly)

public static BitmapDrawable getBitmapDrawable (Context context, int drawableId, int width, int height, int targetColor, boolean roundedCorner)

public static Intent getFileIntent (String fileName, String mimeType)

Send a generic file creation intent

public static Bitmap getImageBitmap (Context context, Map imageIntent)

Returns the image bitmap.

Parameters
context The context
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)
Returns
  • The image bitmap

public static Bitmap getImageBitmap (Context context, Uri imageUri, String filePath)

Returns the image bitmap.

Parameters
context The context
imageUri Uri to image
Returns
  • The image bitmap

public static String getImageFilePath (Map imageIntent)

Returns the image file path.

Parameters
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)
Returns
  • The image file path

public static String getImageSignaturePath (Activity activity, Intent data, Uri outputFileUri)

public static Uri getImageUri (Map imageIntent)

Returns the image URI

Parameters
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)
Returns
  • The image URI

public static Uri getImageUriFromIntent (Intent data, Activity activity, Uri outputFileUri)

public static int getLastHPosForURL (Context context, String url)

public static int getLastPageForURL (Context context, String url)

public static int getLastVPosForURL (Context context, String url)

public static double getLastZoomForURL (Context context, String url)

public static ArrayList<MenuEditorItem> getMenuEditorItemsArray (String savedToolbarMenu)

This method is deprecated.
No replacement.

Throws
JSONException

public static String getMenuEditorItemsJSON (ArrayList<MenuEditorItem> newMenuItems)

This method is deprecated.
No replacement.

Throws
JSONException

public static PageSet getPageSet (SparseBooleanArray positions)

Converts page positions to the page set

Parameters
positions The page positions as boolean
Returns
  • The page set

public static int getRotationForURL (Context context, String url)

public static String getSelectedString (PDFViewCtrl pdfViewCtrl, boolean appendNewLine)

Returns selected text in pdf

Parameters
pdfViewCtrl The PDFViewCtrl
appendNewLine Whether to append new line on line break
Returns
  • The selected text in pdf

public static String getSelectedString (PDFViewCtrl pdfViewCtrl)

Returns selected text in pdf

Parameters
pdfViewCtrl The PDFViewCtrl
Returns
  • The selected text in pdf

public static String imageIntentToPdf (Context context, Uri imageUri, String imagePath, ExternalFileInfo documentFile)

Converts image to PDF from an image intent

Parameters
context the context
imageUri the image intent
imagePath the image path
documentFile the result file path
Returns
  • null if failed, otherwise returns the result file path
Throws
IOException
PDFNetException

public static String imageIntentToPdf (Context context, Uri imageUri, String imagePath, String outputPath)

Converts image to PDF from an image intent

Parameters
context the context
imagePath the image intent
outputPath the result file path
Returns
  • null if failed, otherwise returns the result file path
Throws
FileNotFoundException
PDFNetException

public static void importAnnotationCommand (PDFViewCtrl pdfViewCtrl, String xfdfCommand)

Import annotation XFDF command to the document

Parameters
pdfViewCtrl the viewer
xfdfCommand the XFDF command string

public static boolean isContinuousPageMode (PDFViewCtrl pdfViewCtrl)

Checks if the tab is in continuous page mode.

Returns
  • True if the tab is in continuous page mode

public static boolean isImageFromCamera (Map imageIntent)

Checks whether the image is taken from camera.

Parameters
imageIntent The internal image intent map obtained from readImageIntent(Intent, Context, Uri)
Returns
  • True if the image is taken from camera

public static boolean isInFullScreenMode (Context context)

public static boolean isNonContinuousVerticalPageMode (PDFViewCtrl pdfViewCtrl)

Checks if the tab is in continuous snapping page mode.

Returns
  • True if the tab is in continuous snapping page mode

public static boolean isSinglePageMode (PDFViewCtrl pdfViewCtrl)

Checks if the tab is in single page mode.

Returns
  • True if the tab is in single page mode

public static boolean isViewerZoomed (PDFViewCtrl pdfViewCtrl)

Checks whether the PDFViewCtrl is zoomed.

Parameters
pdfViewCtrl The PDFViewCtrl
Returns
  • True if the PDFViewCtrl is zoomed

public static void jumpToAnnotation (PDFViewCtrl pdfViewCtrl, Annot annot, int pageNum)

Jumps to the specified annotation.

Parameters
pdfViewCtrl The PDFViewCtrl
annot The annotation
pageNum The page number where the annotation is on

public static void jumpToRect (PDFViewCtrl pdfViewCtrl, Rect rect, int pageNum)

public static void keepOnScreenAfterClick (Context context, MenuItem item)

Prevents menu item from closing its popup menu on click

Parameters
item menu item to prevent from closing menu

public static Uri openCameraIntent (Activity activity, int requestCode)

public static void openFileIntent (Fragment fragment)

Send a generic file picker intent

Parameters
fragment the fragment

public static void openFileIntent (Activity activity, Fragment fragment)

Send a generic file picker intent

Parameters
activity the activity
fragment the fragment

public static void openFileIntent (Activity activity)

Send a generic file picker intent

Parameters
activity the activity

public static Uri openGalleryIntent (Activity activity, int requestCode)

public static Uri openGalleryIntent (Activity activity, int requestCode, boolean multiSelect)

public static Uri openImageIntent (Fragment fragment, boolean multiSelect)

public static Uri openImageIntent (Activity activity, int requestCode)

Parameters
activity the activity in which you can expect onActivityResult will be called with given request code
requestCode the request code to returned in onActivityResult
Returns
  • the output file Uri

public static Uri openImageIntent (Fragment fragment, int requestCode)

Parameters
fragment the fragment in which you can expect onActivityResult will be called with given request code
requestCode the request code to returned in onActivityResult
Returns
  • the output file Uri

public static Uri openImageIntent (Fragment fragment)

Parameters
fragment the fragment in which you can expect onActivityResult will be called with request code PICK_PHOTO_CAM
Returns
  • the output file Uri

public static Uri openImageIntent (Activity activity)

Parameters
activity the activity in which you can expect onActivityResult will be called with request code PICK_PHOTO_CAM
Returns
  • the output file Uri

public static void passwordDoc (PDFDoc doc, String password)

public static Map readImageIntent (Intent data, Context context, Uri outputFileUri)

Reads an image intent.

Parameters
data The intent
context The context
outputFileUri The output URI
Returns
  • The internal image intent map
Throws
FileNotFoundException FileNotFound exception

public static List<Map<String, Object>> readMultiImageIntent (Intent data, Context context, Uri outputFileUri, boolean parseMultiImage)

Reads an image intent with option to parse multi image.

Throws
FileNotFoundException

public static void removePageBookmark (Context context, boolean isReadOnly, PDFViewCtrl pdfViewCtrl, int page)

Removes a page bookmark

Parameters
context the context
isReadOnly whether to edit the original pdf
pdfViewCtrl the PDFViewCtrl
page the page to remove from bookmark

public static void renameAllFields (Page page)

public static void safeUpdatePageLayout (PDFViewCtrl pdfViewCtrl)

public static void safeUpdatePageLayout (PDFViewCtrl pdfViewCtrl, ExceptionHandlerCallback callback)

Safe version of updatePageLayout, will call readLock before and unlock after this operation as recommended by Core Team

Updates the page layout within the view. This function must be called after document page sequence is modified (such as when a page is being added to or removed from a document) or after changes to page dimensions (e.g. after a page is rotated or resized).

Parameters
pdfViewCtrl the PDFViewCtrl
callback Callback object to provide exception handling, can be null

public static Rect scrollToAnnotRect (PDFViewCtrl pdfViewCtrl, Rect annotRect, int pageNum)

Scroll to annotation rect.

Parameters
pdfViewCtrl the PDFViewCtrl
annotRect the annot rect
pageNum the annot page number
Returns
  • final rect in client space after scrolling
Throws
PDFNetException PDFNet exception

public static void setLastPageForURL (Context context, String url, int page)

public static void setLastPageStateForURL (Context context, String url, double zoom, int hPos, int vPos, int rotation)