Mass Exam Marker Plugin
A Moodle plugin to help mark massive exams.
 All Data Structures Namespaces Files Functions Variables
AssignPDFLib Class Reference
Inheritance diagram for AssignPDFLib:

Public Member Functions

 combine_pdfs ($pdflist, $outfilename, $coversheet=null, $fields=null)
 
 current_page ()
 
 page_count ()
 
 load_pdf ($filename)
 
 set_pdf ($filename, $pagecount=0)
 
 copy_page ()
 
 copy_remaining_pages ()
 
 add_comment ($text, $x, $y, $width, $colour= 'yellow')
 
 add_annotation ($sx, $sy, $ex, $ey, $colour= 'red', $type= 'line', $path=null)
 
 save_pdf ($filename)
 
 set_image_folder ($folder)
 
 get_image ($pageno)
 

Static Public Member Functions

static get_stamps ()
 
static get_stamp_file ($stampname)
 
static ensure_pdf_compatible (stored_file $file)
 
static test_gs_path ($generateimage=true)
 
static send_test_image ()
 

Data Fields

const GSPATH_OK = 'ok'
 
const GSPATH_EMPTY = 'empty'
 
const GSPATH_DOESNOTEXIST = 'doesnotexist'
 
const GSPATH_ISDIR = 'isdir'
 
const GSPATH_NOTEXECUTABLE = 'notexecutable'
 
const GSPATH_NOTESTFILE = 'notestfile'
 
const GSPATH_ERROR = 'error'
 

Protected Member Functions

 create_page_from_source ($pageno)
 

Protected Attributes

 $currentpage = 0
 
 $pagecount = 0
 
 $scale = 0.0
 
 $imagefolder = null
 
 $filename = null
 

Member Function Documentation

add_annotation (   $sx,
  $sy,
  $ex,
  $ey,
  $colour = 'red',
  $type = 'line',
  $path = null 
)

Add an annotation to the current page

Parameters
$sxint starting x-coordinate (in pixels)
$syint starting y-coordinate (in pixels)
$exint ending x-coordinate (in pixels)
$eyint ending y-coordinate (in pixels)
$colourstring optional the colour of the annotation (red, yellow, green, blue, white, black)
$typestring optional the type of annotation (line, oval, rectangle, highlight, freehand, stamp)
$pathmixed int[]|string optional for 'freehand' annotations this is an array of x and y coordinates for the line, for 'stamp' annotations it is the name of the stamp file (without the path)
Returns
bool true if successful (always)
add_comment (   $text,
  $x,
  $y,
  $width,
  $colour = 'yellow' 
)

Add a comment to the current page

Parameters
$textstring the text of the comment
$xint the x-coordinate of the comment (in pixels)
$yint the y-coordinate of the comment (in pixels)
$widthint the width of the comment (in pixels)
$colourstring optional the background colour of the comment (red, yellow, green, blue, white, clear)
Returns
bool true if successful (always)
combine_pdfs (   $pdflist,
  $outfilename,
  $coversheet = null,
  $fields = null 
)

Combine the given PDF files into a single PDF. Optionally add a coversheet and coversheet fields.

Parameters
$pdfliststring[] the filenames of the files to combine
$outfilenamestring the filename to write to
$coversheetstring optional the coversheet to include
$fieldsstdClass[] optional the fields to write onto the coversheet
Returns
int the number of pages in the combined PDF
copy_page ( )

Copy the next page from the source file and set it as the current page

Returns
bool true if successful
copy_remaining_pages ( )

Copy all the remaining pages in the file

create_page_from_source (   $pageno)
protected
current_page ( )

The number of the current page in the PDF being processed

Returns
int
static ensure_pdf_compatible ( stored_file  $file)
static

Check to see if PDF is version 1.4 (or below); if not: use ghostscript to convert it

Parameters
stored_file$file
Returns
bool false if the PDF is invalid, true if the PDF is valid (or has been converted)
get_image (   $pageno)

Generate an image of the specified page in the PDF

Parameters
$pagenoint the page to generate the image of
Exceptions
moodle_exception
coding_exception
Returns
string the filename of the generated image
static get_stamp_file (   $stampname)
static

Get the location of the image file for a given stamp (or false, if it does not exist)

Parameters
$stampname
Returns
mixed string|false the path to the image file for the stamp
static get_stamps ( )
static

Get a list of the available stamp images - the PNG files found within the mod/assign/feedback/pdf/pix/stamps folder

Returns
string[] 'stampname' => 'filepath'
load_pdf (   $filename)

Load the specified PDF and set the initial output configuration Used when processing comments and outputting a new PDF

Parameters
$filenamestring the path to the PDF to load
Returns
int the number of pages in the PDF
page_count ( )

The total number of pages in the PDF being processed

Returns
int
save_pdf (   $filename)

Save the completed PDF to the given file

Parameters
$filenamestring the filename for the PDF (including the full path)
static send_test_image ( )
static
set_image_folder (   $folder)

Set the path to the folder in which to generate page image files

Parameters
$folderstring
set_pdf (   $filename,
  $pagecount = 0 
)

Sets the name of the PDF to process, but only loads the file if the pagecount is zero (in order to count the number of pages) Used when generating page images (but not a new PDF)

Parameters
$filenamestring the path to the PDF to process
$pagecountint optional the number of pages in the PDF, if known
Returns
int the number of pages in the PDF
static test_gs_path (   $generateimage = true)
static

Field Documentation

$currentpage = 0
protected
$filename = null
protected
$imagefolder = null
protected
$pagecount = 0
protected
$scale = 0.0
protected
const GSPATH_DOESNOTEXIST = 'doesnotexist'
const GSPATH_EMPTY = 'empty'
const GSPATH_ERROR = 'error'
const GSPATH_ISDIR = 'isdir'
const GSPATH_NOTESTFILE = 'notestfile'
const GSPATH_NOTEXECUTABLE = 'notexecutable'
const GSPATH_OK = 'ok'

The documentation for this class was generated from the following file: