Fandom

Livecode Wiki

Viewing a PDF with the internal PDF viewer

2,161pages on
this wiki
Add New Page
Comments0 Share

At the present (22/April/2016) the internal PDF viewer is available only for business commercial edition.

It works like the revBrowser.

XPDFViewer commands Edit

Errors as documented will be returned in the result of the command or function. In all cases if the incorrect number of parameters were used a script execution error will be thrown with the error XPDF_ERROR: error message.

XPDFViewer_OpenEdit

Create a named PDF Viewer associated with a specific stack window.

Syntax:

XPDFViewer_Open viewer_name, stack_windowId

Example

XDFViewer_Open "Document1", the windowID of this stack

Errors:

XPDF_ERROR: PDF viewer with that name exists

XPDFViewer_GoToPageEdit

Navigate to a page using either one of the four navigation constants or a specific page number.

Syntax

XPDFViewer_GoToPage < viewer name>, {"last" | "first" | "next" | "prev" | < page number>}

Example

XPDFViewer_GoToPage "Document1", "next"

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_ChooseMouseModeEdit

Choose a mouse mode. The viewer defaults to browse mode. Choose selection to select text. Syntax

XPDFViewer_ChooseMouseMode < viewer name>, {"selection" | "browse" | "image" }

Example

XPDFViewer_ChooseMouseMode "Document1", "selection"

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_ZoomEdit

Zoom the page using either one of the five zoom constants or a specified percentage. Syntax:

XPDFViewer_Zoom < viewer name>, {"width" | "fit" | "actual" | "in" | "out" | < percent>}

Example

XPDFViewer_Zoom "Document1", 200

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_Close Edit

Close a named PDF viewer Example

XPDFViewer_Close "Document1"

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_SetEdit

Set a property of the PDF Viewer. See the [property reference](#markdown-header-property-reference) for detail of the specific properties.

Syntax

XPDFViewer_Set < viewer name>, < property>, < value>

Example:

XPDFViewer_Set "Document1", "rect", (100, 100, 500, 600)

Errors:

XPDF_ERROR: PDF viewer not found
XPDF_ERROR: can't set property

further will be described here.

XPDFViewer_GetEdit

Get the value of a property from a PDF Viewer. See the [property reference](#markdown-header-property-reference) for detail of the specific properties.

XPDFViewer_Get(< viewer name>, < property>)

Example

put XPDFViewer_Get("Document1", "rect") into thePDFRect

Errors:

XPDF_ERROR: PDF viewer not found
XPDF_ERROR: can't get property

XPDFViewer_TextEdit

Return the text of a page in ASCII. This function should be considered deprecated in favor of XPDFViewer_Unicode

Syntax

XPDFViewer_Text(< viewer name>, < page number>)

Example

put XPDFViewer_Text("Document1",3) into fld "page text"

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_UnicodeEdit

This command sets the value of a named variable to the UTF16 encoded text of a specific page.

Syntax

XPDFViewer_Unicode < viewer name>, < page number>, < variable name to set>

Example

local thePageText
XPDFViewer_Unicode "Document1", 3, "thePageText" 
set the text of fld "page text" to thePageText

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_CharacterCountEdit

Return the number of characters in a specified page.

Syntax

XPDFViewer_CharacterCount(< viewer name>, < page number>)

Example

put XPDFViewer_CharacterCount("Document1", 3) into theNumberOfChars

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_ImageEdit

This command sets the value of a named variable to the imageData of the rendered page. The page is rendered at the current viewer scale. LiveCode imageData does not contain any width or height information so you must set the width and height of the image correctly before setting the imageData. The command returns the size (width, height) of the image. As the image is drawn at the current scale of the PDF view the width/height returned will not match the width/height calculated from XPDFViewer_Get("Document1","width") and XPDFViewer_Get("Document1","height") on Mac retina and high DPI windows systems.

Syntax

XPDFViewer_Image < viewer name>, < page number>, < variable name to set>

Example

local tImageData
XPDFViewer_Image "Document1", 1, "tImageData"
put the result into tSize
set the width of image "page" to item 1 of tSize
set the height of image "page" to item 2 of tSize
set the imageData of image "page" to tImageData

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetSelectionRectEdit

Get the rect of the portion of the selection that appears on the currently loaded page. If there is no selection on the current page the function returns 0,0,0,0. Coordinates are in stack coordinates. Adjust the returned rect by the topLeft of the RECT property (viewport) to get coordinates relative to the PDF page.

An optional page number parameter may be used to get the rect of the selection or portion of selection that appears on the given page.

Syntax

XPDFViewer_GetSelectionRect(< viewer name>[, < page number>])

Example

put XPDFViewer_GetSelectionRect("Document1") into theSelectionRect

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetSelectionUnicodeEdit

This command sets the value of a named variable to the UTF16 encoded text of the current selection.

Syntax

XPDFViewer_GetSelectionUnicode < viewer name>, < variable name to set>

Example

local theSelectedText
XPDFViewer_GetSelectionUnicode "Document1", "theSelectedText"
set the text of fld "selected text" to theSelectedText

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetSelectionTextEdit

Return the selected text in ASCII. This function should be considered deprecated in favor of XPDFViewer_GetSelectionUnicode

Syntax

XPDFViewer_GetSelectionText(< viewer name>)

Example

put XPDFViewer_GetSelectionText("Document1") into fld "selected text"

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetSelectionRangeEdit

Get the current selection range from a PDF Viewer. The function returns the range as < start page number>, < start char on page>, < end page number>, < end char on page>

And insertion point is returned as < start page number>,< char insertion point is after>,< end page number - same as start>,< char insertion point is after - 1>

Syntax

XPDFViewer_GetSelectionRange(< viewer name>)

Example

put XPDFViewer_GetSelectionRange("Document1") into theCurrentSelection
If item 1 = item 3 AND item 4 < item 2 then 
  answer "it is an insertion point position."
 end if

The function will return empty if there is no selection.

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_SelectEdit

Set the current selection of the PDF Viewer to a specific range or clear the current selection of the PDF Viewer.

Syntax:

XPDFViewer_Select < viewer name>, < start page number>, < start char on page>, < end page number>, < end char on page>

Example

XPDFViewer_Select "Document1", 1, 300, 3, 20
XPDFViewer_Select "Document1","" #This clear the current selection

Errors:

XPDF_ERROR: PDF viewer not found

Image SelectionEdit

Get the rect of image selection. If there is no image selection the function returns 0,0,0,0. Coordinates are in stack coordinates. Adjust the returned rect by the topLeft of the RECT property (viewport) to get coordinates relative to the PDF page.

Syntax

XPDFViewer_GetImageSelectionRect(< viewer name>)

Example

put XPDFViewer_GetImageSelectionRect("Document1") into theSelectionRect

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetSelectionImageEdit

This command sets the value of a named variable to the imageData of the current image selection. The selection is rendered at the current viewer scale. LiveCode imageData does not contain any width or height information so you must set the width and height of the image correctly *before* setting the imageData. The command returns the size (width, height) of the image. As the image is drawn at the current scale of the PDF view the width/height returned will not match the width/height calculated from XPDFViewer_GetImageSelectionRect on Mac retina and high DPI windows systems.

Syntax

XPDFViewer_GetSelectionImage < viewer name>, < variable name to set>

Example

local tImageData
XPDFViewer_GetSelectionImage "Document1", "tImageData"
put the result into tSize
set the width of image "selection" to item 1 of tSize
set the height of image "selection" to item 2 of tSize
set the imageData of image "selection" to tImageData

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_GetImageSelectionRangeEdit

Get the current image selection range from a PDF Viewer. The function returns the range as < page number>, < left>, < top>, < right>, < bottom>. The coordinates are real numbers in pdf coordinates rather than integers stack coordinates.

The function will return empty if there is no selection.

Syntax

XPDFViewer_GetImageSelectionRange(< viewer name>)

Example

put XPDFViewer_GetImageSelectionRange("Document1") into theCurrentSelection

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer_SelectImageEdit

Set the current image selection of the PDF Viewer to a specific range. The coordinates are real numbers in pdf coordinates rather than integers stack coordinates. You can also clear the current selection of the PDF Viewer.

Syntax

XPDFViewer_SelectImage < viewer name>, < page number>, < left>, < top>, < right>, < bottom>

Example

XPDFViewer_SelectImage "Document1", 1, 10.5, 100.2, 200, 130.4
XPDFViewer_SelectImage "Document1",""  #This clear the selection

Errors:

XPDF_ERROR: PDF viewer not found

XPDFViewer MessagesEdit

You can use the following messages to activate something on user action.

XPDF_ScrollTopOfPageEdit

Sent when scrolling past the top of page

XPDF_SelectTopOfPageEdit

Sent when selecting past the top of page

XPDF_ScrollBottomOfPageEdit

Sent when scrolling past the bottom of page

XPDF_SelectBottomOfPageEdit

Sent when selecting past the bottom of page

XPDF_SelectionChangedEdit

Sent when the selected text is changed. If there is no selection then the parameter is empty.

Sytax

on XPDF_SelectionChanged < start page number>, < start char on page>, < end page number>, < end char on page>
  ...
end XPDF_SelectionChanged 

XPDF_ImageSelectionChangedEdit

Sent when the selected image is changed. If there is no selection then the parameter is empty. The rect is in PDF coordinates rather than stack coordinates.

Syntax

on XPDF_ImageSelectionChanged < page number>, < left>, < top>, < right>, < bottom>
  ...
end XPDF_ImageSelectionChanged


XPDF_ScrollbarDraggedEdit

Sent when the user scrolls the view.

Syntax

on XPDF_ScrollbarDragged < hscroll>, < vscroll>
   ...
end XPDF_ScrollbarDragged

XPDF_LinkClickedEdit

Sent when the user clicks on a link

Syntax

on XPDF_LinkClicked < uri or file path>
  ...
end XPDF_LinkClicked


PropertiesEdit

RECTEdit

The rect of the PDF Viewer relative to the top left of the stack window.

Errors:

XPDF_ERROR: invalid rect

FILENAMEEdit

The full file path to the PDF file being viewed

Errors:

XPDF_ERROR: could not open file
XPDF_ERROR: password required or incorrect password

VISIBLEEdit

The visibility of the PDF Viewer

PAGENUMBEREdit

The currently displayed page of the PDF Viewer

FORMATTEDWIDTH (read only)Edit

The width in pixels of the PDF Page with no scaling applied.

FORMATTEDHEIGHT (read only)Edit

The height in pixels of the PDF Page with no scaling applied.

WIDTH (read only)Edit

The width in pixels of the PDF page with scaling applied.

HEIGHT (read only)Edit

The height in pixels of the PDF page with no scaling applied.

PAGECOUNT (read only)Edit

The total number of pages in the PDF document.

TOTALCHARACTERCOUNT (read only)Edit

The total number of characters in the PDF document.

CONTINUOUSSCROLLMODEEdit

The continuous scroll mode of the PDF document.

SCROLLEdit

The current scroll of the displayed page as < horizontal scroll>,< vertical scroll>.

Errors:

XPDF_ERROR: invalid scroll

PAGEGRAVITYEdit

The gravity of the page when the view is larger than the scaled page in either width or height. Currently supported page gravities are:

  • topLeft (default) - top left of page sticks to the top left of the view
  • center - the page is centered in the view

HSCROLLBAREdit

Boolean property to show or hide the horizontal scrollbar

VSCROLLBAREdit

Boolean property to show or hide the vertical scrollbar

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.