Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
assignfeedback_editpdf\pdf Class Reference

Library code for manipulating PDFs. More...

Inheritance diagram for assignfeedback_editpdf\pdf:

Public Member Functions

 add_annotation ($sx, $sy, $ex, $ey, $colour, $type, $path, $imagefolder)
 Add an annotation to the current page.
 
 add_comment ($text, $x, $y, $width, $colour='yellow')
 Add a comment to the current page.
 
 add_comment_marker ($pageno, $index, $x, $y, $link, $colour='yellow')
 Add a comment marker to the specified page.
 
 add_image_page ($imagestoredfile)
 This function add an image file to PDF page.
 
 append_comments ($allcomments)
 Append all comments to the end of the document.
 
 combine_pdfs ($pdflist, $outfilename)
 Combine the given PDF files into a single PDF.
 
 copy_page ()
 Copy the next page from the source file and set it as the current page.
 
 copy_remaining_pages ()
 Copy all the remaining pages in the file.
 
 current_page ()
 The number of the current page in the PDF being processed.
 
 get_image ($pageno)
 Generate an image of the specified page in the PDF.
 
 get_images ()
 Generate images from the PDF.
 
 load_pdf ($filename)
 Load the specified PDF and set the initial output configuration Used when processing comments and outputting a new PDF.
 
 page_count ()
 The total number of pages in the PDF being processed.
 
 save_pdf ($filename)
 Save the completed PDF to the given file.
 
 set_export_font_name ($fontname)
 Set font name.
 
 set_image_folder ($folder)
 Set the path to the folder in which to generate page image files.
 
 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)
 

Static Public Member Functions

static ensure_pdf_compatible (\stored_file $file)
 Check to see if PDF is version 1.4 (or below); if not: use ghostscript to convert it.
 
static ensure_pdf_file_compatible ($tempsrc)
 Flatten and convert file using ghostscript then load pdf.
 
static get_error_image ($errorimagefolder, $pageno)
 Generate an localised error image for the given pagenumber.
 
static send_test_image ()
 If the test image has been generated correctly - send it direct to the browser.
 
static test_gs_path ($generateimage=true)
 Test that the configured path to ghostscript is correct and working.
 

Public Attributes

const BLANK_PDF = '/mod/assign/feedback/editpdf/fixtures/blank.pdf'
 Blank PDF file used during error.
 
const GSPATH_DOESNOTEXIST = 'doesnotexist'
 Does not exist.
 
const GSPATH_EMPTY = 'empty'
 Not set.
 
const GSPATH_ERROR = 'error'
 Any other error.
 
const GSPATH_ISDIR = 'isdir'
 Is a dir.
 
const GSPATH_NOTESTFILE = 'notestfile'
 Test file missing.
 
const GSPATH_NOTEXECUTABLE = 'notexecutable'
 Not executable.
 
const GSPATH_OK = 'ok'
 No errors.
 
const IMAGE_PAGE = 'image_page'
 Page image file name prefix.
 
const MIN_ANNOTATION_HEIGHT = 5
 Min.
 
const MIN_ANNOTATION_WIDTH = 5
 Min.
 

Protected Member Functions

 create_page_from_source ($pageno)
 Create a page from a source PDF.
 
 precheck_generate_image ()
 Make sure the file name and image folder are ready before generate image.
 

Protected Attributes

int $currentpage = 0
 the number of the current page in the PDF being processed
 
string $filename = null
 the path to the PDF currently being processed
 
string $fontname = null
 the fontname used when the PDF being processed
 
string $imagefolder = null
 the path in which to store generated page images
 
int $pagecount = 0
 the total number of pages in the PDF being processed
 
float $scale = 0.0
 used to scale the pixel position of annotations (in the database) to the position in the final PDF
 

Detailed Description

Library code for manipulating PDFs.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ add_annotation()

assignfeedback_editpdf\pdf::add_annotation ( $sx,
$sy,
$ex,
$ey,
$colour,
$type,
$path,
$imagefolder )

Add an annotation to the current page.

Parameters
int$sxstarting x-coordinate (in pixels)
int$systarting y-coordinate (in pixels)
int$exending x-coordinate (in pixels)
int$eyending y-coordinate (in pixels)
string$colouroptional the colour of the annotation (red, yellow, green, blue, white, black)
string$typeoptional the type of annotation (line, oval, rectangle, highlight, pen, stamp)
int[] | string$pathoptional for 'pen' 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)
string$imagefolder- Folder containing stamp images.
Return values
booltrue if successful (always)

◆ add_comment()

assignfeedback_editpdf\pdf::add_comment ( $text,
$x,
$y,
$width,
$colour = 'yellow' )

Add a comment to the current page.

Parameters
string$textthe text of the comment
int$xthe x-coordinate of the comment (in pixels)
int$ythe y-coordinate of the comment (in pixels)
int$widththe width of the comment (in pixels)
string$colouroptional the background colour of the comment (red, yellow, green, blue, white, clear)
Return values
booltrue if successful (always)

◆ add_comment_marker()

assignfeedback_editpdf\pdf::add_comment_marker ( $pageno,
$index,
$x,
$y,
$link,
$colour = 'yellow' )

Add a comment marker to the specified page.

Parameters
int$pagenoThe page number to add markers to (starting at 0).
int$indexThe comment index.
int$xThe x-coordinate of the marker (in pixels).
int$yThe y-coordinate of the marker (in pixels).
int$linkThe link identifier pointing to the full comment text.
string$colourThe fill colour of the marker (red, yellow, green, blue, white, clear).
Return values
boolSuccess status.

◆ add_image_page()

assignfeedback_editpdf\pdf::add_image_page ( $imagestoredfile)

This function add an image file to PDF page.

Parameters
stored_file$imagestoredfileImage file to be added

◆ append_comments()

assignfeedback_editpdf\pdf::append_comments ( $allcomments)

Append all comments to the end of the document.

Parameters
array$allcommentsAll comments, indexed by page number (starting at 0).
Return values
array|boolAn array of links to comments, or false.

◆ combine_pdfs()

assignfeedback_editpdf\pdf::combine_pdfs ( $pdflist,
$outfilename )

Combine the given PDF files into a single PDF.

Optionally add a coversheet and coversheet fields.

Parameters
string[]$pdflistthe filenames of the files to combine
string$outfilenamethe filename to write to
Return values
intthe number of pages in the combined PDF

◆ copy_page()

assignfeedback_editpdf\pdf::copy_page ( )

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

Return values
booltrue if successful

◆ create_page_from_source()

assignfeedback_editpdf\pdf::create_page_from_source ( $pageno)
protected

Create a page from a source PDF.

Parameters
int$pageno

◆ current_page()

assignfeedback_editpdf\pdf::current_page ( )

The number of the current page in the PDF being processed.

Return values
int

◆ ensure_pdf_compatible()

static assignfeedback_editpdf\pdf::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
Return values
stringpath to copy or converted pdf (false == fail)

◆ ensure_pdf_file_compatible()

static assignfeedback_editpdf\pdf::ensure_pdf_file_compatible ( $tempsrc)
static

Flatten and convert file using ghostscript then load pdf.

Parameters
string$tempsrcThe path to the file on disk.
Return values
stringpath to copy or converted pdf (false == fail)

◆ get_error_image()

static assignfeedback_editpdf\pdf::get_error_image ( $errorimagefolder,
$pageno )
static

Generate an localised error image for the given pagenumber.

Parameters
string$errorimagefolderpath of the folder where error image needs to be created.
int$pagenopage number for which error image needs to be created.
Return values
stringFile name
Exceptions
coding_exception

◆ get_image()

assignfeedback_editpdf\pdf::get_image ( $pageno)

Generate an image of the specified page in the PDF.

Parameters
int$pagenothe page to generate the image of
Exceptions
moodle_exception
coding_exception
Return values
stringthe filename of the generated image

◆ get_images()

assignfeedback_editpdf\pdf::get_images ( )

Generate images from the PDF.

Return values
arrayArray of filename of the generated images

◆ load_pdf()

assignfeedback_editpdf\pdf::load_pdf ( $filename)

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

Parameters
string$filenamethe path to the PDF to load
Return values
intthe number of pages in the PDF

◆ page_count()

assignfeedback_editpdf\pdf::page_count ( )

The total number of pages in the PDF being processed.

Return values
int

◆ precheck_generate_image()

assignfeedback_editpdf\pdf::precheck_generate_image ( )
protected

Make sure the file name and image folder are ready before generate image.

Return values
bool

◆ save_pdf()

assignfeedback_editpdf\pdf::save_pdf ( $filename)

Save the completed PDF to the given file.

Parameters
string$filenamethe filename for the PDF (including the full path)

◆ set_export_font_name()

assignfeedback_editpdf\pdf::set_export_font_name ( $fontname)

Set font name.

Parameters
string$fontnameFont name which is
Return values
void

◆ set_image_folder()

assignfeedback_editpdf\pdf::set_image_folder ( $folder)

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

Parameters
string$folder

◆ set_pdf()

assignfeedback_editpdf\pdf::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
string$filenamethe path to the PDF to process
int$pagecountoptional the number of pages in the PDF, if known
Return values
intthe number of pages in the PDF

◆ test_gs_path()

static assignfeedback_editpdf\pdf::test_gs_path ( $generateimage = true)
static

Test that the configured path to ghostscript is correct and working.

Parameters
bool$generateimage- If true - a test image will be generated to verify the install.
Return values
stdClass

Member Data Documentation

◆ MIN_ANNOTATION_HEIGHT

const assignfeedback_editpdf\pdf::MIN_ANNOTATION_HEIGHT = 5

Min.

height an annotation should have

◆ MIN_ANNOTATION_WIDTH

const assignfeedback_editpdf\pdf::MIN_ANNOTATION_WIDTH = 5

Min.

width an annotation should have


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