Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Library code for manipulating PDFs. More...
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. | |
Library code for manipulating PDFs.
assignfeedback_editpdf\pdf::add_annotation | ( | $sx, | |
$sy, | |||
$ex, | |||
$ey, | |||
$colour, | |||
$type, | |||
$path, | |||
$imagefolder ) |
Add an annotation to the current page.
int | $sx | starting x-coordinate (in pixels) |
int | $sy | starting y-coordinate (in pixels) |
int | $ex | ending x-coordinate (in pixels) |
int | $ey | ending y-coordinate (in pixels) |
string | $colour | optional the colour of the annotation (red, yellow, green, blue, white, black) |
string | $type | optional the type of annotation (line, oval, rectangle, highlight, pen, stamp) |
int[] | string | $path | optional 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. |
bool | true if successful (always) |
assignfeedback_editpdf\pdf::add_comment | ( | $text, | |
$x, | |||
$y, | |||
$width, | |||
$colour = 'yellow' ) |
Add a comment to the current page.
string | $text | the text of the comment |
int | $x | the x-coordinate of the comment (in pixels) |
int | $y | the y-coordinate of the comment (in pixels) |
int | $width | the width of the comment (in pixels) |
string | $colour | optional the background colour of the comment (red, yellow, green, blue, white, clear) |
bool | true if successful (always) |
assignfeedback_editpdf\pdf::add_comment_marker | ( | $pageno, | |
$index, | |||
$x, | |||
$y, | |||
$link, | |||
$colour = 'yellow' ) |
Add a comment marker to the specified page.
int | $pageno | The page number to add markers to (starting at 0). |
int | $index | The comment index. |
int | $x | The x-coordinate of the marker (in pixels). |
int | $y | The y-coordinate of the marker (in pixels). |
int | $link | The link identifier pointing to the full comment text. |
string | $colour | The fill colour of the marker (red, yellow, green, blue, white, clear). |
bool | Success status. |
assignfeedback_editpdf\pdf::add_image_page | ( | $imagestoredfile | ) |
This function add an image file to PDF page.
stored_file | $imagestoredfile | Image file to be added |
assignfeedback_editpdf\pdf::append_comments | ( | $allcomments | ) |
Append all comments to the end of the document.
array | $allcomments | All comments, indexed by page number (starting at 0). |
array|bool | An array of links to comments, or false. |
assignfeedback_editpdf\pdf::combine_pdfs | ( | $pdflist, | |
$outfilename ) |
Combine the given PDF files into a single PDF.
Optionally add a coversheet and coversheet fields.
string[] | $pdflist | the filenames of the files to combine |
string | $outfilename | the filename to write to |
int | the number of pages in the combined PDF |
assignfeedback_editpdf\pdf::copy_page | ( | ) |
Copy the next page from the source file and set it as the current page.
bool | true if successful |
|
protected |
Create a page from a source PDF.
int | $pageno |
assignfeedback_editpdf\pdf::current_page | ( | ) |
The number of the current page in the PDF being processed.
int |
|
static |
Check to see if PDF is version 1.4 (or below); if not: use ghostscript to convert it.
stored_file | $file |
string | path to copy or converted pdf (false == fail) |
|
static |
Flatten and convert file using ghostscript then load pdf.
string | $tempsrc | The path to the file on disk. |
string | path to copy or converted pdf (false == fail) |
|
static |
Generate an localised error image for the given pagenumber.
string | $errorimagefolder | path of the folder where error image needs to be created. |
int | $pageno | page number for which error image needs to be created. |
string | File name |
coding_exception |
assignfeedback_editpdf\pdf::get_image | ( | $pageno | ) |
Generate an image of the specified page in the PDF.
int | $pageno | the page to generate the image of |
moodle_exception | |
coding_exception |
string | the filename of the generated image |
assignfeedback_editpdf\pdf::get_images | ( | ) |
Generate images from the PDF.
array | Array of filename of the generated images |
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.
string | $filename | the path to the PDF to load |
int | the number of pages in the PDF |
assignfeedback_editpdf\pdf::page_count | ( | ) |
The total number of pages in the PDF being processed.
int |
|
protected |
Make sure the file name and image folder are ready before generate image.
bool |
assignfeedback_editpdf\pdf::save_pdf | ( | $filename | ) |
Save the completed PDF to the given file.
string | $filename | the filename for the PDF (including the full path) |
assignfeedback_editpdf\pdf::set_export_font_name | ( | $fontname | ) |
Set font name.
string | $fontname | Font name which is |
void |
assignfeedback_editpdf\pdf::set_image_folder | ( | $folder | ) |
Set the path to the folder in which to generate page image files.
string | $folder |
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)
string | $filename | the path to the PDF to process |
int | $pagecount | optional the number of pages in the PDF, if known |
int | the number of pages in the PDF |
|
static |
Test that the configured path to ghostscript is correct and working.
bool | $generateimage | - If true - a test image will be generated to verify the install. |
stdClass |
const assignfeedback_editpdf\pdf::MIN_ANNOTATION_HEIGHT = 5 |
Min.
height an annotation should have
const assignfeedback_editpdf\pdf::MIN_ANNOTATION_WIDTH = 5 |
Min.
width an annotation should have