public class PDFViewCtrl
extends android.view.ViewGroup
PDFViewCtrl is derived from anroid.view.ViewGroup and encapsulates a rich set of functionalities for interactive viewing of PDF documents.
PDFViewCtrl makes use of PDFTron's PDFNet library that is compiled as a native library to ensure real-time viewing experience. It provides a comprehensive set of functionalities, including multi-threaded rendering, PDF rendering settings, scrolling, zooming, page navigation, different page viewing modes, coordinates conversion, text selection, text search, and etc. In addition, PDFViewCtrl also allows for extension to accommodate a user's specific needs, which can be achieved in one of the following two ways:
(1) Derive from PDFViewCtrl and override its functions such as
onMeasure(int, int), onDraw(Canvas), onScroll(MotionEvent, MotionEvent, float, float) and etc. However, note
that since PDFViewCtrl implements these functions, it is necessary to call
PDFViewCtrl's implementations first.
(2) The recommended way is to use PDFViewCtrl's PDFViewCtrl.ToolManager and
PDFViewCtrl.Tool interfaces. These two interfaces provide a way for users to
interact with PDFViewCtrl, including customizing responses to gestures and
drawing extra contents on top of the PDF content. In fact, PDFNet SDK also
ships with a separate library, Tools.jar, that is programmed via these two
interfaces. This library utilizes functions offered by PDFNet and implements
several ready-to-use UI modules such as annotation editing, text selection,
text search, page navigation and etc. PDFNet customers can have access to the
source code of Tools.jar for full customization.
| Modifier and Type | Class and Description |
|---|---|
static interface |
PDFViewCtrl.DocumentDownloadListener
Used for receiving updates from document downloading, which can be
started by
PDFViewCtrl#openURL(String, String). |
static interface |
PDFViewCtrl.PageChangeListener
Used for receiving notifications in UI thread when the current page changes.
|
static interface |
PDFViewCtrl.RenderingListener
Used for receiving notifications of the start and end of the rendering of
the client area.
|
class |
PDFViewCtrl.Selection
Class that represents the current text selection by PDFViewCtrl.
|
static interface |
PDFViewCtrl.TextSearchListener
Used for receiving notifications in UI thread during the process of text search.
|
static interface |
PDFViewCtrl.Tool
Tool interface.
|
static interface |
PDFViewCtrl.ToolManager
Tool manager interface that is used for creating tools.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DOWNLOAD_FAIL
Downloading has failed.
|
static int |
DOWNLOAD_FINISH
Downloading has finished.
|
static int |
DOWNLOAD_PAGE
A page is downloaded.
|
static int |
DOWNLOAD_START
Downloading has started.
|
protected static int |
mContinuousModeCanvasId |
protected static int |
mMaxTileNumPerCanvas |
static int |
OVERPRINT_OFF
Overprint is disabled.
|
static int |
OVERPRINT_ON
Overprint is enabled.
|
static int |
OVERPRINT_PDFX
Overprint is enabled only for PDF/X documents.
|
static int |
PAGE_CHANGE_BEGIN
Page change is beginning.
|
static int |
PAGE_CHANGE_END
Page change is ended.
|
static int |
PAGE_CHANGE_ONGOING
Page change is ongoing.
|
static int |
PAGE_PRESENTATION_FACING
Display pages two at a time, with odd-numbered pages on left (non-continuous mode).
|
static int |
PAGE_PRESENTATION_FACING_CONT
Display pages in two columns, with odd-numbered pages on left (continuous mode).
|
static int |
PAGE_PRESENTATION_FACING_COVER
Display pages two at a time, with odd-numbered pages on right (non-continuous mode).
|
static int |
PAGE_PRESENTATION_FACING_COVER_CONT
Display pages in two columns, with odd-numbered pages on right (continuous mode).
|
static int |
PAGE_PRESENTATION_SINGLE
Display one page at a time (non-continuous mode).
|
static int |
PAGE_PRESENTATION_SINGLE_CONT
Display pages in one column (continuous mode).
|
static int |
PAGE_VIEW_FIT_HEIGHT
Zoom is automatically adjusted so that the page height fits into available space.
|
static int |
PAGE_VIEW_FIT_PAGE
Zoom is automatically adjusted so that the entire page fits into available space.
|
static int |
PAGE_VIEW_FIT_WIDTH
Zoom is automatically adjusted so that the page width fits into available space.
|
static int |
PAGE_VIEW_ZOOM
Page is zoomed, and the zoom factor is specified using
#setZoom(). |
static int |
PRIOR_EVENT_DBLTAP
Prior event is double tap.
|
static int |
PRIOR_EVENT_FLING
Prior event is fling.
|
static int |
PRIOR_EVENT_OTHER
Prior event is any other types.
|
static int |
PRIOR_EVENT_PINCH
Prior event is pinching/zooming.
|
static int |
PRIOR_EVENT_SCROLLING
Prior event is scrolling.
|
static int |
TEXT_SEARCH_CANCELED
Text Search was canceled.
|
static int |
TEXT_SEARCH_FOUND
Text Search finishes normally and a result was found.
|
static int |
TEXT_SEARCH_INVALID_INPUT
Text Search input string is invalid.
|
static int |
TEXT_SEARCH_NOT_FOUND
Text Search finishes normally and nothing was found.
|
static int |
ZOOM_LIMIT_ABSOLUTE
Zoom limit mode is absolute.
|
static int |
ZOOM_LIMIT_NONE
Zoom limit is not applied.
|
static int |
ZOOM_LIMIT_RELATIVE
Zoom limit mode is relative.
|
| Constructor and Description |
|---|
PDFViewCtrl(Context context,
AttributeSet attrs)
Constructor that is called when inflating a view from XML.
|
PDFViewCtrl(Context context,
AttributeSet attrs,
int defStyle)
Perform inflation from XML and apply a class-specific base style.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancelFindText()
Cancels the current text search thread, if exists.
|
void |
cancelRendering()
Cancels the rendering thread, if running.
|
void |
clearSelection()
Removes all text
PDFViewCtrl.Selection. |
void |
closeDoc()
Closes the current document.
|
void |
closeTool()
Closes the current tool.
|
protected int |
computeHorizontalScrollRange()
The overloaded implementation of android.view.computeHorizontalScrollRange().
|
void |
computeScroll()
The overloaded implementation of android.view.computeScroll().
|
protected int |
computeVerticalScrollRange()
The overloaded implementation of android.view.computeVerticalScrollRange().
|
double[] |
convCanvasPtToClientPt(double x,
double y)
Convert a point in canvas space to client space.
|
double[] |
convCanvasPtToPagePt(double x,
double y)
Convert a point in canvas space to the current page space.
|
double[] |
convCanvasPtToPagePt(double x,
double y,
int page_num)
Convert a point in canvas space to the specified page space.
|
double[] |
convClientPtToCanvasPt(double x,
double y)
Converts a point in client space to (PDF) canvas space.
|
double[] |
convClientPtToPagePt(double x,
double y)
Convert a point in client space to the current page space.
|
double[] |
convClientPtToPagePt(double x,
double y,
int page_num)
Convert a point in client space to the specified page space.
|
double[] |
convPagePtToCanvasPt(double x,
double y)
Convert a point in the current page space to canvas space.
|
double[] |
convPagePtToCanvasPt(double x,
double y,
int page_num)
Convert a point in the specified page space to canvas space.
|
double[] |
convPagePtToClientPt(double x,
double y,
int page_num)
Convert a point in the specified page space to client space.
|
void |
destroy()
Should be called in android.app.Activity.onDestroy() to destroy
PDFViewCtrl and clean up memory and used resources.
|
void |
executeAction(Action a)
Executes the action.
|
protected void |
finalize()
Protected functions.
|
int |
findText(java.lang.String search_str,
boolean match_case,
boolean match_whole_word,
boolean search_up,
boolean reg_exp,
PDFViewCtrl.TextSearchListener listener)
Searches, starting from the current page, for the given text and selects
it, if found.
|
Annot |
getAnnotationAt(int x,
int y)
Gets the annotation at a given point, specified in client space.
|
double |
getCanvasHeight()
Returns the height of Zoomed PDF Canvas Space.
|
double |
getCanvasWidth()
Returns the width of Zoomed PDF Canvas Space.
|
int |
getCurrentPage()
Gets the current page number.
|
PDFDoc |
getDoc()
Gets the current PDF document.
|
int |
getPageNumberFromClientPt(double x,
double y)
Get the number of the page on which the specified point in client space.
|
int |
getPagePresentationMode()
Gets the current page presentation mode.
|
int |
getPageRefViewMode()
Gets the reference page view mode.
|
Matrix |
getPageSlidingCanvasTransform()
Gets the extra transformation matrix applied to the
android.graphics.Canvas object used by PDFViewCtrl during page sliding.
|
int |
getPageViewMode()
Gets the current page view mode.
|
boolean |
getProgressiveRendering()
Checks if progressive rendering is used.
|
boolean |
getRightToLeftLanguage()
Checks if PDFViewCtrl thinks the content in the viewed PDF document reads
from right to left.
|
PDFViewCtrl.Selection |
getSelection(int page)
Gets the text
PDFViewCtrl.Selection on a give page. |
int |
getSelectionBeginPage()
Returns the first page number that has text
PDFViewCtrl.Selection on it. |
int |
getSelectionEndPage()
Returns the last page number that has text
PDFViewCtrl.Selection on it. |
PDFViewCtrl.Tool |
getTool()
Gets the current
PDFViewCtrl.Tool instance used by PDFViewCtrl. |
PDFViewCtrl.ToolManager |
getToolManager()
Gets the
PDFViewCtrl.ToolManager instance used by PDFViewCtrl. |
int |
getViewCanvasHeight()
Returns the height of PDFViewCtrl Canvas space.
|
int |
getViewCanvasWidth()
Returns the width of PDFViewCtrl Canvas space.
|
double |
getZoom()
Gets the current zoom factor.
|
boolean |
gotoFirstPage()
Sets the current page to the first page.
|
boolean |
gotoLastPage()
Sets the current page to the last page.
|
boolean |
gotoNextPage()
Sets the current page to the next page.
|
boolean |
gotoPage(int page_num)
Deprecated.
use
setCurrentPage(int) instead. |
boolean |
gotoPreviousPage()
Sets the current page to the previous page.
|
boolean |
hasSelection()
Checks if there is any text
PDFViewCtrl.Selection. |
boolean |
hasSelectionOnPage(int page)
Checks if there is any text
PDFViewCtrl.Selection on a give page. |
void |
initScrollbars(TypedArray a)
Initialize the scroll bars.
|
boolean |
isContinuousPagePresentationMode(int mode)
Checks if the current page presentation mode is continuous.
|
boolean |
isFacingPagePresentationMode(int mode)
Checks if the current page presentation mode is facing.
|
boolean |
isFinishedRendering()
Checks if the rendering thread has finished.
|
boolean |
isFinishedRendering(boolean visible_region_only)
Checks if the rendering thread finishes or the current visible region has
been fully rendered.
|
boolean |
isHardwareAccelerated()
Checks if PDFViewCtrl is hardware accelerated.
|
void |
lockDoc(boolean cancel_rendering)
Locks the PDFDoc instance used by PDFViewCtrl.
|
protected boolean |
onDoubleTap(MotionEvent e)
Notified when a double-tap occurs.
|
protected boolean |
onDoubleTapEvent(MotionEvent e)
Notified when an event within a double-tap gesture occurs, including the
down, move, and up events.
|
protected boolean |
onDown(MotionEvent e)
Notified when a tap occurs with the down MotionEvent that triggered it.
|
protected void |
onDraw(Canvas canvas)
The overloaded implementation of android.view.View.onDraw().
|
protected boolean |
onFling(MotionEvent e1,
MotionEvent e2,
float x_vel,
float y_vel)
Notified when a fling event occurs with a scroll event.
|
protected void |
onFlingStop()
Notified when a fling motion stops.
|
protected void |
onLayout(boolean changed,
int l,
int t,
int r,
int b)
The overloaded implementation of android.view.View.onLayout().
|
protected void |
onLongPress(MotionEvent e)
Notified when a long press occurs with the initial on down MotionEvent
that triggered it.
|
protected void |
onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
The overloaded implementation of android.view.View.onMeasure().
|
protected boolean |
onScale(ScaleGestureDetector detector)
Responds to scaling events for a gesture in progress.
|
protected boolean |
onScaleBegin(ScaleGestureDetector detector)
Responds to the beginning of a scaling gesture.
|
protected void |
onScaleEnd(ScaleGestureDetector detector)
Responds to the end of a scale gesture.
|
protected boolean |
onScroll(MotionEvent e1,
MotionEvent e2,
float x_dist,
float y_dist)
Notified when a scroll event occurs with a scroll event.
|
protected void |
onShowPress(MotionEvent e)
The user has performed a down MotionEvent and not performed a move or up
yet.
|
protected boolean |
onSingleTapConfirmed(MotionEvent e)
Notified when a single-tap occurs.
|
protected boolean |
onSingleTapUp(MotionEvent e)
Notified when a tap occurs with the up MotionEvent that triggered it.
|
boolean |
onTouchEvent(MotionEvent event)
The overloaded implementation of android.view.onTouchEvent().
|
protected boolean |
onUp(MotionEvent e,
int prior_event_type)
Notified when an up event occurs with the up MotionEvent that triggered
it.
|
void |
openURL(java.lang.String url,
java.lang.String cache_file,
java.lang.String password)
Sets the PDF document, from a URL, that is to be displayed.
|
void |
pause()
Should be called in android.app.Activity.onPause() to pause PDFViewCtrl.
|
void |
postToolOnCustomEvent(java.lang.Object o)
Post a message to cause
PDFViewCtrl.Tool.onCustom(Object) to be called in the
next main message loop. |
void |
purgeMemory()
Call this method to lower PDFViewCtrl's memory consumption, such as in
Activity.onLowMemory().
|
void |
requestLayout()
Overloaded version of android.view.View.requestLayout().
|
void |
requestRendering()
Requests that PDFViewCtrl start rendering, if necessary.
|
void |
resume()
Should be called in android.app.Activity.onResume() to resume PDFViewCtrl.
|
void |
scrollBy(int dx,
int dy)
Overloaded implementation of android.view.View.scrollBy().
|
void |
scrollTo(int x,
int y)
Overloaded implementation of android.view.View.scrollTo().
|
void |
selectAll()
Selects all the text in the document.
|
boolean |
selectByHighlights(Highlights hlts)
Selects texts by Highlights.
|
boolean |
selectByRect(double x1,
double y1,
double x2,
double y2)
Selects the words that intersect the rectangle which is the axis-aligned
bounding box of point (x1, y1) and point (x2, y2).
|
boolean |
selectByStruct(double x1,
double y1,
double x2,
double y2)
Selects text taking into account page logical structure.
|
void |
setAntiAliasing(boolean enable_aa)
Enables or disables anti-aliasing.
|
void |
setBuiltInPageSlidingEnabled(boolean enabled)
Enable/disable the built-in page turning animation effect (sliding) when
it is under non-continuous page presentation mode (
setPagePresentationMode(int)). |
void |
setBuiltInPageSlidingSpeed(int sliding_dp_per_second,
int fling_dp_per_second)
Sets the parameters of built-in page turning effect.
|
void |
setCaching(boolean enabled)
Enables or disables caching.
|
void |
setClientBackgroundColor(int r,
int g,
int b,
boolean transparent)
Set the background color of the client area.
|
boolean |
setCurrentPage(int page_num)
Goes to the specified page.
|
void |
setDefaultPageColor(int c)
Set the default 'paper' color used to draw background of each page.
|
void |
setDefaultPageColor(int r,
int g,
int b)
Set the default 'paper' color used to draw background of each page.
|
void |
setDoc(PDFDoc doc)
Sets the PDF document to be displayed.
|
void |
setDocumentDownloadListener(PDFViewCtrl.DocumentDownloadListener listener)
Sets the document download listener.
|
void |
setDrawAnnotations(boolean render_annots)
Enables or disables annotation and forms rendering.
|
void |
setGamma(double exp)
Sets the gamma factor used for anti-aliased rendering.
|
void |
setHighlightFields(boolean highlight_fields)
Enable or disable highlighting form fields.
|
void |
setImageSmoothing(boolean smoothing)
Sets if image smoothing is used.
|
void |
setInteractionEnabled(boolean enabled)
Enable or disable use input for PDFViewCtrl.
|
void |
setOverprint(int overprint)
Enables or disables support for overprint.
|
void |
setPageChangeListener(PDFViewCtrl.PageChangeListener listener)
Sets the page change listener.
|
void |
setPagePresentationMode(int mode)
Sets the page presentation mode.
|
void |
setPageRefViewMode(int mode)
Sets the reference page view mode.
|
void |
setPageSpacing(int horiz_col_space,
int vert_col_space,
int horiz_pad,
int vert_pad)
Sets the vertical and horizontal padding and column spacing between
adjacent pages in the view.
|
void |
setPageViewMode(int mode)
Sets the page viewing mode.
|
void |
setPathHinting(boolean path_hinting)
Enable or disable path hinting.
|
void |
setProgressiveRendering(boolean progressive)
Enables or disables progressive rendering.
|
void |
setProgressiveRendering(boolean progressive,
int delay_ms,
int interval_ms)
Enables or disables progressive rendering and sets the initial delay and
interval in milliseconds.
|
void |
setRenderedContentCacheSize(long allowed_max)
Sets the suggested memory size of the rendered content.
|
void |
setRenderingListener(PDFViewCtrl.RenderingListener listener)
Sets the rendering listener.
|
void |
setRightToLeftLanguage(boolean flag)
Tells PDFViewCtrl the content in the viewed PDF document reads from right
to left.
|
void |
setThinLineAdjustment(boolean pixel_grid_fit,
boolean stroke_adjust)
Sets thin line adjustment parameters.
|
void |
setTool(PDFViewCtrl.Tool t)
Sets the current
PDFViewCtrl.Tool instance used by PDFViewCtrl. |
void |
setToolManager(PDFViewCtrl.ToolManager mgr)
Sets the
PDFViewCtrl.ToolManager instance used by PDFViewCtrl. |
void |
setUseThumbView(boolean use_thumb,
boolean runtime_thumb_generation)
Enables or disables the use of thumb view and runtime thumb view
generation.
|
static void |
setViewerCache(SDFDoc document,
int max_cache_size,
int max_zoom_factor)
Sets the cache parameters of the page cache on disk (which caches content
streams and mipmapped images) for this specific document.
|
boolean |
setZoom(double zoom)
Sets the zoom factor and re-render.
|
boolean |
setZoom(double zoom,
boolean use_snapshot)
Sets the zoom factor and re-render.
|
boolean |
setZoom(int x,
int y,
double zoom)
Sets the zoom factor and re-render using the given coordinate (x,y) as a
zoom center.
|
boolean |
setZoom(int x,
int y,
double zoom,
boolean use_snapshot)
Sets the zoom factor and re-render using the given coordinate (x,y) as a
zoom center.
|
void |
setZoomLimits(int zoom_limit_mode,
double min_zoom,
double max_zoom)
Sets the minimum and maximum zoom bounds of PDFViewCtrl.
|
boolean |
showRect(int page_num,
Rect rect)
Adjusts the viewing area to fit a rectangle on a specified page.
|
boolean |
tryLockDoc()
Tries to lock the PDFDoc instance used by PDFViewCtrl.
|
void |
unlockDoc()
Unlocks the PDFDoc instance used by PDFViewCtrl and restarts the
rendering thread if it was canceled by calling
unlockDoc(). |
void |
update()
Redraws the contents of the visible region.
|
void |
update(Annot annot,
int page_num)
Redraws the area covered with a given annotation.
|
void |
update(boolean all)
Redraws the contents.
|
void |
update(Rect rec)
Redraws the given area in the client space.
|
void |
updatePageLayout()
Updates the page layout within the view.
|
void |
waitForRendering()
Waits about 1500 milliseconds or until the visible region is done
rendering, whichever is less.
|
void |
waitForRendering(int milliseconds)
Waits about specified milliseconds or until the visible region is done
rendering, whichever is less.
|
protected static final int mMaxTileNumPerCanvas
protected static final int mContinuousModeCanvasId
public static final int PRIOR_EVENT_SCROLLING
public static final int PRIOR_EVENT_PINCH
public static final int PRIOR_EVENT_FLING
public static final int PRIOR_EVENT_DBLTAP
public static final int PRIOR_EVENT_OTHER
public static final int PAGE_VIEW_FIT_PAGE
public static final int PAGE_VIEW_FIT_WIDTH
public static final int PAGE_VIEW_FIT_HEIGHT
public static final int PAGE_VIEW_ZOOM
#setZoom().public static final int PAGE_PRESENTATION_SINGLE
public static final int PAGE_PRESENTATION_SINGLE_CONT
public static final int PAGE_PRESENTATION_FACING
public static final int PAGE_PRESENTATION_FACING_CONT
public static final int PAGE_PRESENTATION_FACING_COVER
public static final int PAGE_PRESENTATION_FACING_COVER_CONT
public static final int TEXT_SEARCH_NOT_FOUND
public static final int TEXT_SEARCH_FOUND
public static final int TEXT_SEARCH_CANCELED
public static final int TEXT_SEARCH_INVALID_INPUT
public static final int OVERPRINT_OFF
public static final int OVERPRINT_ON
public static final int OVERPRINT_PDFX
public static final int ZOOM_LIMIT_ABSOLUTE
public static final int ZOOM_LIMIT_RELATIVE
public static final int ZOOM_LIMIT_NONE
public static final int PAGE_CHANGE_BEGIN
public static final int PAGE_CHANGE_ONGOING
public static final int PAGE_CHANGE_END
public static final int DOWNLOAD_START
public static final int DOWNLOAD_PAGE
public static final int DOWNLOAD_FINISH
public static final int DOWNLOAD_FAIL
public PDFViewCtrl(Context context,
AttributeSet attrs)
context - The Context the view is running in, through which it can
access the current theme, resources, etc.attrs - The attributes of the XML tag that is inflating the view.public PDFViewCtrl(Context context,
AttributeSet attrs,
int defStyle)
context - The Context the view is running in, through which it can
access the current theme, resources, etc.attrs - The attributes of the XML tag that is inflating the view.defStyle - The default style to apply to this view. If 0, no style will
be applied (beyond what is included in the theme). This may
either be an attribute resource, whose value will be retrieved
from the current theme, or an explicit style resource.public void initScrollbars(TypedArray a)
protected void onLayout(boolean changed,
int l,
int t,
int r,
int b)
protected void onMeasure(int widthMeasureSpec,
int heightMeasureSpec)
public boolean onTouchEvent(MotionEvent event)
protected void onDraw(Canvas canvas)
PDFViewCtrl.Tool.onDraw(Canvas, android.graphics.Matrix) to render a tool's
content on top, if exists.protected boolean onDoubleTap(MotionEvent e)
e - The down motion event of the first tap of the double-tap.PDFViewCtrl.Tool interface) can return true in the corresponding
function to bypass PDFViewCtrl's such behavior.protected boolean onDoubleTapEvent(MotionEvent e)
e - The motion event that occurred during the double-tap gesture.protected boolean onDown(MotionEvent e)
e - The down motion event.PDFViewCtrl.Tool interface).protected boolean onFling(MotionEvent e1,
MotionEvent e2,
float x_vel,
float y_vel)
e1 - The first down motion event that started the fling.e2 - The move motion event that triggered the current onFling.x_vel - The velocity of this fling measured in pixels per second along
the x axis.y_vel - The velocity of this fling measured in pixels per second along
the y axis.PDFViewCtrl.Tool interface) can return true in the PDFViewCtrl.Tool.onUp(MotionEvent, int)
function, where prior event type is PRIOR_EVENT_FLING, to
bypass PDFViewCtrl's such behavior.protected void onFlingStop()
protected void onLongPress(MotionEvent e)
e - The initial on down motion event that started the long press.protected boolean onScaleBegin(ScaleGestureDetector detector)
detector - The detector reporting the event - use this to retrieve
extended info about event state.onScale(ScaleGestureDetector) and onScaleEnd(ScaleGestureDetector)
functions, respectively. A tool (through the PDFViewCtrl.Tool
interface) can return true in the corresponding function to bypass
PDFViewCtrl's such behavior. However, the tool has to bypass this
function in order to bypass the subsequent two functions, which can
not be bypassed individually.protected boolean onScale(ScaleGestureDetector detector)
detector - The detector reporting the event - use this to retrieve
extended info about event state.PDFViewCtrl.Tool interface) can return
true in its onScaleBegin(ScaleGestureDetector) function.protected void onScaleEnd(ScaleGestureDetector detector)
detector - The detector reporting the event - use this to retrieve
extended info about event state.PDFViewCtrl.Tool interface) can return
true in its onScaleBegin(ScaleGestureDetector) function.protected boolean onSingleTapConfirmed(MotionEvent e)
e - The down motion event of the single-tap.protected boolean onScroll(MotionEvent e1,
MotionEvent e2,
float x_dist,
float y_dist)
e1 - The first down motion event that started the scrolling.e2 - The move motion event that triggered the current onScroll.x_dist - The distance along the X axis that has been scrolled since the
last call to onScroll. This is NOT the distance between e1 and
e2.y_dist - The distance along the Y axis that has been scrolled since the
last call to onScroll. This is NOT the distance between e1 and
e2.PDFViewCtrl.Tool interface) can return
true in its corresponding function.protected void onShowPress(MotionEvent e)
e - The down motion event.protected boolean onSingleTapUp(MotionEvent e)
e - The down motion event of the single-tap.protected boolean onUp(MotionEvent e,
int prior_event_type)
e - The up motion event.prior_event_type - indicates the prior event type. Possible values are:
protected int computeVerticalScrollRange()
protected int computeHorizontalScrollRange()
public void computeScroll()
public double getZoom()
public boolean setZoom(double zoom)
zoom - New zoom factor used to display the page content.setZoom(double, boolean), but
with the second parameter being false.public boolean setZoom(double zoom,
boolean use_snapshot)
zoom - New zoom factor used to display the page content.use_snapshot - If true, PDFViewCtrl takes a snapshot of the current client
area and shows it before the content after zooming is ready.
versionpublic boolean setZoom(int x,
int y,
double zoom)
The zoom center (x,y) is represented in the client space, whose origin is at the upper-left corner of the client region.
x - The horizontal coordinate of the center in client space.y - The vertical coordinate of the center in client space.zoom - New zoom factor used to display the page content.setZoom(int, int, double, boolean), but with
the last parameter being false.public boolean setZoom(int x,
int y,
double zoom,
boolean use_snapshot)
The zoom center (x,y) is represented in the client space, whose origin is at the upper-left corner of the client region.
x - The horizontal coordinate of the center in client space.y - The vertical coordinate of the center in client space.zoom - New zoom factor used to display the page content. * @param
use_snapshot If true, PDFViewCtrl takes a snapshot of the
current client area and shows it before the content after
zooming is ready. versionpublic void setZoomLimits(int zoom_limit_mode,
double min_zoom,
double max_zoom)
zoom_limit_mode - defines how the minimum and maximum zoom bounds are used.
Possible values are:
ZOOM_LIMIT_ABSOLUTE:
bounds are in absolute sense.
ZOOM_LIMIT_RELATIVE:
bounds are in relative sense.
ZOOM_LIMIT_NONE: zoom
bounds are not used, default value.
min_zoom - the minimum zoom bound.max_zoom - the maximum zoom bound.ZOOM_LIMIT_RELATIVE is used,
min_zoom and max_zoom are relative to the zoom level when the
current page is displayed in
PAGE_VIEW_FIT_PAGE mode. For
instance, if min_zoom = 1.0 and max_zoom = 3, it means that the
minimum zoom allowed by PDFViewCtrl is the same as the zoom when a
page is fit and the maximum zoom allowed is three times that when
the page is fit.public void scrollBy(int dx,
int dy)
x - the amount of pixels to scroll by horizontally.y - the amount of pixels to scroll by vertically.public void scrollTo(int x,
int y)
x - the x position to scroll to.y - the y position to scroll to.public int getCurrentPage()
public void setInteractionEnabled(boolean enabled)
public void setBuiltInPageSlidingEnabled(boolean enabled)
setPagePresentationMode(int)). Page turning is triggered by
fling and scroll events when the current page reaches its boundary.public void setBuiltInPageSlidingSpeed(int sliding_dp_per_second,
int fling_dp_per_second)
sliding_dp_per_second - After finger is lifted, current page slides into its position.
This parameter determines how many device independent pixels
it moves per second. The default value is 2000.fling_dp_per_second - This parameter sets the lowest speed of a fling event, in
device independent pixel per second, that could trigger the
built-in page turning effect. The default value is 1000.public boolean gotoFirstPage()
public boolean gotoLastPage()
public boolean gotoPreviousPage()
gotoPage(int)
(current_page-1) based on the current page presentation mode.public boolean gotoNextPage()
gotoPage(int)
(current_page-1) based on the current page presentation mode.public boolean setCurrentPage(int page_num)
page_num - specified page number.@Deprecated public boolean gotoPage(int page_num)
setCurrentPage(int) instead.page_num - specified page number.public boolean showRect(int page_num,
Rect rect)
page_num - specified page number.rect - the rectangle to fit in.public Matrix getPageSlidingCanvasTransform()
public boolean isContinuousPagePresentationMode(int mode)
public boolean isFacingPagePresentationMode(int mode)
public PDFDoc getDoc()
public void setDoc(PDFDoc doc)
public void openURL(java.lang.String url,
java.lang.String cache_file,
java.lang.String password)
throws PDFNetException
Sets the PDF document, from a URL, that is to be displayed. If successful, PDFViewCtrl will download the PDF document and display it. If the PDF file is linearized, PDFViewCtrl will download it incrementally while displaying it; otherwise, PDFViewCtrl will show blank pages until the entire document is downloaded.
Since this function starts the actual download work in a worker thread,
it returns quickly to avoid blocking UI.
setDocumentDownloadListener(DocumentDownloadListener) can be
used to listen to the download result, e.g., DOWNLOAD_FAIL.
url - The URL of the document to open.cache_file - If empty, PDFViewCtrl will re-download the entire document;
otherwise, it starts downloading where it stopped previously
and stores the upcoming data to the cached file. Note that
this parameter should contain the full path.password - The password used to open the document.PDFNetException
Download updates can be received from
PDFViewCtrl.Tool.onDocumentDownloadEvent(int, int, int, int) or
PDFViewCtrl.DocumentDownloadListener.
Currently, only HTTP protocol is supported.
public void closeDoc()
public void lockDoc(boolean cancel_rendering)
Simultaneous access to a PDFDoc instance is not allowed. Since
PDFViewCtrl renders a PDFDoc in a rendering thread, UI access to the same
PDFDOc instance should lock the document first and then unlock
unlockDoc() it afterwards.
cancel_rendering - If true, rendering thread is canceled first before trying to
lock the document. This ensures a quick return from this
function. Otherwise, this function can halt the UI and the app
may be unresponsive before the rendering thread finishes. If
the rendering thread is canceled, unlocking the document
unlockDoc() will restart the rendering thread.public boolean tryLockDoc()
public void unlockDoc()
unlockDoc().public void setToolManager(PDFViewCtrl.ToolManager mgr)
PDFViewCtrl.ToolManager instance used by PDFViewCtrl. By default, there is no
tool manager used by PDFViewCtrl.public PDFViewCtrl.ToolManager getToolManager()
PDFViewCtrl.ToolManager instance used by PDFViewCtrl. By default, there is no
tool manager used by PDFViewCtrl.public PDFViewCtrl.Tool getTool()
PDFViewCtrl.Tool instance used by PDFViewCtrl. By default, there is no
tool used by PDFViewCtrl.public void setTool(PDFViewCtrl.Tool t)
PDFViewCtrl.Tool instance used by PDFViewCtrl.ToolManager#createTool(int, PDFViewCtrl, Tool),
which is used during events. The other way is through this method,
which allows for setting the tool without any events.public void setDocumentDownloadListener(PDFViewCtrl.DocumentDownloadListener listener)
public void setPageChangeListener(PDFViewCtrl.PageChangeListener listener)
public void setRenderingListener(PDFViewCtrl.RenderingListener listener)
public void postToolOnCustomEvent(java.lang.Object o)
PDFViewCtrl.Tool.onCustom(Object) to be called in the
next main message loop. This is useful if a Tool needs to be called by
PDFViewCtrl in the main message loop without a touch event being
triggered.Object - An Object that can be passed back in
PDFViewCtrl.Tool.onCustom(Object) function.public void closeTool()
public double[] convClientPtToCanvasPt(double x,
double y)
When converting points, PDFViewCtrl may refer to the following spaces:
For example, if you want to know the coordinates of the upper-left corner of the Canvas Space in the client space, you can simply use convCanvasPtToClientPt(0,0). If you want to calculate the coordinates of the lower-left corner of page 1 in the client space, you can use convPagePtToClientPt(0, 0, 1). Or if you just want to know the coordinates of the upper left corner of the Client Space in View Canvas Space, it is simply (getScrollX(), getScrollY()).
x - x coordinate of the input point.y - y coordinate in the input pointpublic double[] convClientPtToPagePt(double x,
double y)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convClientPtToPagePt(double x,
double y,
int page_num)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convCanvasPtToClientPt(double x,
double y)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convCanvasPtToPagePt(double x,
double y)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convCanvasPtToPagePt(double x,
double y,
int page_num)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convPagePtToCanvasPt(double x,
double y)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convPagePtToCanvasPt(double x,
double y,
int page_num)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public double[] convPagePtToClientPt(double x,
double y,
int page_num)
x - x coordinate of the input point.y - y coordinate in the input point.convClientPtToCanvasPt(double, double).public int getPageNumberFromClientPt(double x,
double y)
x - x coordinate of the input point.y - y coordinate of the input point.convClientPtToCanvasPt(double, double).public boolean selectByRect(double x1,
double y1,
double x2,
double y2)
convClientPtToCanvasPt(double, double).public boolean selectByStruct(double x1,
double y1,
double x2,
double y2)
convClientPtToCanvasPt(double, double).public boolean selectByHighlights(Highlights hlts)
hlts - the Highlights to be selected.public void selectAll()
public boolean hasSelection()
PDFViewCtrl.Selection.public void clearSelection()
PDFViewCtrl.Selection.public PDFViewCtrl.Selection getSelection(int page)
PDFViewCtrl.Selection on a give page.page - the number of the given page.public int getSelectionBeginPage()
PDFViewCtrl.Selection on it.
Useful when there are selections on multiple pages at the same time.public int getSelectionEndPage()
PDFViewCtrl.Selection on it.
Useful when there are selections on multiple pages at the same time.public boolean hasSelectionOnPage(int page)
PDFViewCtrl.Selection on a give page.page - the page number of the given page.public int findText(java.lang.String search_str,
boolean match_case,
boolean match_whole_word,
boolean search_up,
boolean reg_exp,
PDFViewCtrl.TextSearchListener listener)
PDFViewCtrl.Selection for highlighting in
PDFViewCtrl and other purposes.
If the document is large, it is also recommended to run text search in a
separate thread by providing a valid TextSearchListener object via the
last parameter. In this case, the returned value of this function should
be ignored and the right result will be passed in by
PDFViewCtrl.TextSearchListener.onTextSearchEnd(int). Calling this function again will
automatically cancels any ongoing text search thread and searches from
the previous location. This method also automatically wrap around the
document.
search_str - the text to search for.match_case - indicates if it is case sensitive.match_whole_word - indicates if it matches an entire word only.search_up - indicates if it searches upward.reg_exp - indicates if it uses regular expressions. For more details
about the regular expression syntax, please refer to Regular Expression Syntax. listener - the text search listener of type PDFViewCtrl.TextSearchListener.
If provided, text search runs in a separate thread.public void cancelFindText()
public void cancelRendering()
public void requestRendering()
update() tells PDFViewCtrl to discard
the rendered content and start a rendering thread. This function
should be used if the content of the PDF is modified.public boolean isFinishedRendering()
public boolean isFinishedRendering(boolean visible_region_only)
public void waitForRendering(int milliseconds)
milliseconds - milli-seconds to wait up to.update() is called, it might be desirable to
call this method so that before onDraw(Canvas)
is called by OS, the new content will already be ready. This helps
to avoid flickering.
If unlockDoc() also has to be called, it should
be called before this function.
public void waitForRendering()
waitForRendering(int) for more details.public boolean isHardwareAccelerated()
public void updatePageLayout()
public void update()
public void update(boolean all)
if - true, all the rendered contents are discarded and re-rendered;
otherwise, only the visible region will be re-rendered.public void update(Rect rec)
rec - the rectangle specifying the given area.convClientPtToCanvasPt(double, double).public void update(Annot annot, int page_num)
annot - the annotation whose occupied region is to be updated.page_num - the number of the page that the annotation belongs to.public void resume()
public void pause()
public void destroy()
public void purgeMemory()
Note that onLowMemory() is called when a user is running too many applications and the OS needs to recover the memory from them. Exceeding your own application's VM heap quota does NOT cause onLowMemory() to be called. For this sake, it is a good practice in your code to catch OutOfMemoryError exception and then call this method.
public void requestLayout()
public double getCanvasWidth()
convClientPtToCanvasPt(double, double).public double getCanvasHeight()
convClientPtToCanvasPt(double, double).public int getViewCanvasWidth()
convClientPtToCanvasPt(double, double).public int getViewCanvasHeight()
convClientPtToCanvasPt(double, double).public int getPagePresentationMode()
public void setPagePresentationMode(int mode)
mode - the new page presentation mode. Possible values are:
public int getPageViewMode()
public void setPageViewMode(int mode)
mode - the new page viewing mode. Possible values are:
PAGE_VIEW_FIT_WIDTH (default value);
PAGE_VIEW_FIT_HEIGHT;
PAGE_VIEW_FIT_PAGE.
public int getPageRefViewMode()
setPageRefViewMode(int).public void setPageRefViewMode(int mode)
PAGE_VIEW_FIT_WIDTH, the new page coming in will
be displayed with width-fit mode.mode - The reference page view mode to set. Valid values are
PAGE_VIEW_FIT_PAGE, PAGE_VIEW_FIT_WIDTH, and
PAGE_VIEW_FIT_HEIGHT.public void setPageSpacing(int horiz_col_space,
int vert_col_space,
int horiz_pad,
int vert_pad)
horiz_col_space - horizontal column spacing (represented in pixels) between
adjacent pages in the view. Default is 3.vert_col_space - vertical column spacing (represented in pixels) between
adjacent pages in the view. Default is 3.horiz_pad - horizontal padding (represented in pixels) on the left and
right side of the view. Default is 0.vert_pad - vertical padding (represented in pixels) on the top and bottom
side of the view. Default is 0.public void setProgressiveRendering(boolean progressive)
progressive - If true, progressive rendering is enabled; otherwise, it is
disabled.public void setProgressiveRendering(boolean progressive,
int delay_ms,
int interval_ms)
progressive - If true, progressive rendering is enabled; otherwise, it is
disabled.delay_ms - The initial delay in milliseconds of starting progressive
rendering. This might be desirable due to the use of thumb
nail views. Only effective if progressive is true.interval_ms - The interval in milliseconds between two consecutive
progressive updates. Only effective if progressive is true.public void setUseThumbView(boolean use_thumb,
boolean runtime_thumb_generation)
Thumb nail view is used before a PDF page is fully rendered. If runtime thumb view generation is enabled, PDFViewCtrl generates thumb nail views at runtime. If a PDF file already contains the thumb nail views, runtime thumb view generation can be turned off, which is more efficient.
use_thumb - If true, thumb nail view is enabled; otherwise, it is
disabled.runtime_thumb_generation - If true, runtime thumb nail view generation is enabled;
otherwise, it is disabled.public boolean getProgressiveRendering()
public void setCaching(boolean enabled)
public void setRenderedContentCacheSize(long allowed_max)
PDFViewCtrl keeps invisible content in order to achieve smoother viewing experience; however, this increases memory usage. Android sets an upper bound on the VM heap size allowed for an app. By default, PDFViewCtrl is set to use half of that amount for keeping visible and invisible content. Based on the memory footprint of your app, you may want to customize it.
The following code shows a sample usage of this function:
long allowed_max = Runtime.getRuntime().maxMemory() / (1024 * 1024); setRenderedContentCacheSize((long) (allowed_max * 0.5)); //should NOT use close to allowed_max
allowed_max - the allowed heap memory usage in MB.If you want to minimize the heap memory usage at the cost of viewing experience quality, you can set allowed_max to 0 and PDFViewCtrl will not keep any invisible content. Also note that this function only controls the memory usage of VM heap size by PDFViewCtrl, but not the native memory that PDFViewCtrl might use.
On Android 3.0 and above, you can increase the allowed heap size of an app by setting android:largeHeap="true" in the app's manifest file.
public void setImageSmoothing(boolean smoothing)
public boolean getRightToLeftLanguage()
public void setRightToLeftLanguage(boolean flag)
public void setDefaultPageColor(int r,
int g,
int b)
r - red component of the color.g - green component of the color.b - blue component of the color.setDefaultPageColor(int) or
#setDefaultPageColor(int, int, int, int)public void setDefaultPageColor(int c)
c - the color.public void setClientBackgroundColor(int r,
int g,
int b,
boolean transparent)
r - red component of the background color.g - green component of the background color.b - blue component of the background color.transparent - if true, the client region is transparent.public void setDrawAnnotations(boolean render_annots)
public void setAntiAliasing(boolean enable_aa)
public void setHighlightFields(boolean highlight_fields)
highlight_fields - true to highlight, false otherwise.public void setPathHinting(boolean path_hinting)
path_hinting - if true path hinting is enabled. Path hinting is used to
slightly adjust paths in order to avoid or alleviate artifacts
of hair line cracks between certain graphical elements. This
option is turned on by default.public void setThinLineAdjustment(boolean pixel_grid_fit,
boolean stroke_adjust)
pixel_grid_fit - If true (horizontal/vertical) thin lines will be snapped to
integer pixel positions. This helps make thin lines look
sharper and clearer. This option is turned off by default and
it only works if path hinting is enabled.stroke_adjust - If true auto stroke adjustment is enabled. Currently, this
would make lines with sub-pixel width to be one-pixel wide.
This option is turned on by default.public void setOverprint(int overprint)
overprint - possible values are:
public void setGamma(double exp)
exp - is the exponent value of gamma function. Typical values
are in the range from 0.1 to 3.
Gamma correction can be used to improve the quality of anti-aliased
image output and can (to some extent) decrease the appearance common
anti-aliasing artifacts (such as pixel width lines between polygons).public Annot getAnnotationAt(int x, int y)
convClientPtToCanvasPt(double, double).public void executeAction(Action a)
public static void setViewerCache(SDFDoc document, int max_cache_size, int max_zoom_factor) throws PDFNetException
max_cache_size - The maximum size, in bytes, of the entire document's page
cache.max_zoom_factor - The maximum zoom factor (in percent) supported by the cache
(value is clamped to a minimum of 100)PDFNetExceptionsetCaching(boolean) will be ineffective.protected void finalize()
throws java.lang.Throwable
java.lang.Throwable