Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250530) (c39b7370636)
assignfeedback_editpdf\pdf Class Reference

Library code for manipulating PDFs. More...

Inheritance diagram for assignfeedback_editpdf\pdf:
Fpdi FpdfTpl pdf FpdfTpl

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_export_fontlist ()
 Get font list from config.
 
 get_font_families ()
 Returns list of font families and types of fonts.
 
 get_image ($pageno)
 Generate an image of the specified page in the PDF.
 
 get_images ()
 Generate images from the PDF.
 
 getTemplateSize ($tpl, $width=null, $height=null)
 Get the size of an imported page.
 
 is_core_font_family ($fontfamily)
 Is this font family one of core fonts?
 
 load_pdf ($filename)
 Load the specified PDF and set the initial output configuration Used when processing comments and outputting a new PDF.
 
 Output ($name='doc.pdf', $dest='I')
 Send the document to a given destination: string, local file or browser.
 
 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)
 
 useImportedPage ($pageId, $x=0, $y=0, $width=null, $height=null, $adjustPageSize=false)
 Draws an imported page onto the page.
 
 useTemplate ($tpl, $x=0, $y=0, $width=null, $height=null, $adjustPageSize=false)
 Draws an imported page onto the page or another template.
 

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.
 
useImportedPage as fpdiUseImportedPage
 
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.
 
const VERSION = '2.6.3'
 FPDI version.
 

Protected Member Functions

 _enddoc ()
 
 _getxobjectdict ()
 
 _newobj ($objid='')
 Begin a new object and return the object number.
 
 _put ($s, $newLine=true)
 Append content to the buffer of TCPDF.
 
 _putxobjects ()
 
 adjustLastLink ($externalLink, $xPt, $scaleX, $yPt, $newHeightPt, $scaleY, $importedPage)
 This method will add additional data to the last created link/annotation.
 
 create_page_from_source ($pageno)
 Create a page from a source PDF.
 
 getNextTemplateId ()
 Get the next template id.
 
 precheck_generate_image ()
 Make sure the file name and image folder are ready before generate image.
 
 writePdfType (PdfType $value)
 Writes a PdfType object to the resulting buffer.
 

Protected Attributes

int null $currentObjectNumber
 The currently used object number.
 
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
 
int $templateId = 0
 A counter for template ids.
 

Detailed Description

Library code for manipulating PDFs.

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

Member Function Documentation

◆ _getxobjectdict()

Fpdi::_getxobjectdict ( )
protectedinherited

Return values
string

◆ _newobj()

Fpdi::_newobj ( $objid = '')
protectedinherited

Begin a new object and return the object number.

Parameters
int | string$objidObject ID (leave empty to get a new ID).
Return values
intobject number

◆ _put()

Fpdi::_put ( $s,
$newLine = true )
protectedinherited

Append content to the buffer of TCPDF.

Parameters
string$s
bool$newLine

◆ _putxobjects()

Fpdi::_putxobjects ( )
protectedinherited

◆ 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

◆ adjustLastLink()

Fpdi::adjustLastLink ( $externalLink,
$xPt,
$scaleX,
$yPt,
$newHeightPt,
$scaleY,
$importedPage )
protectedinherited

This method will add additional data to the last created link/annotation.

It will copy styling properties (supported by TCPDF) of the imported link.

Parameters
array$externalLink
float | int$xPt
float | int$scaleX
float | int$yPt
float | int$newHeightPt
float | int$scaleY
array$importedPage
Return values
void

◆ 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_export_fontlist()

pdf::get_export_fontlist ( )
inherited

Get font list from config.

Return values
array|string[]

◆ get_font_families()

pdf::get_font_families ( )
inherited

Returns list of font families and types of fonts.

Return values
arraymultidimensional array with font families as keys and B, I, BI and N as values.

◆ 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

◆ getNextTemplateId()

Fpdi::getNextTemplateId ( )
protectedinherited

Get the next template id.

Return values
int

◆ getTemplateSize()

Fpdi::getTemplateSize ( $tpl,
$width = null,
$height = null )
inherited

Get the size of an imported page.

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
mixed$tplThe template id
float | int | null$widthThe width.
float | int | null$heightThe height.
Return values
array|boolAn array with following keys: width, height, 0 (=width), 1 (=height), orientation (L or P)

◆ is_core_font_family()

pdf::is_core_font_family ( $fontfamily)
inherited

Is this font family one of core fonts?

Parameters
string$fontfamily
Return values
bool

◆ 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

◆ Output()

pdf::Output ( $name = 'doc.pdf',
$dest = 'I' )
inherited

Send the document to a given destination: string, local file or browser.

In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.
The method first calls Close() if necessary to terminate the document.

Parameters
$name(string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character.
$dest(string) Destination where to send the document. It can take one of the following values:
  • I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.
  • D: send to the browser and force a file download with the name given by name.
  • F: save to a local server file with the name given by name.
  • S: return the document as a string (name is ignored).
  • FI: equivalent to F + I option
  • FD: equivalent to F + D option
  • E: return the document as base64 mime multi-part email attachment (RFC 2045)
Since
Moodle 1.0
See also
Close()

◆ 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

◆ useImportedPage()

Fpdi::useImportedPage ( $pageId,
$x = 0,
$y = 0,
$width = null,
$height = null,
$adjustPageSize = false )
inherited

Draws an imported page onto the page.

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
mixed$pageIdThe page id
float | int | array$xThe abscissa of upper-left corner. Alternatively you could use an assoc array with the keys "x", "y", "width", "height", "adjustPageSize".
float | int$yThe ordinate of upper-left corner.
float | int | null$widthThe width.
float | int | null$heightThe height.
bool$adjustPageSize
Return values
arrayThe size.
See also
Fpdi::getTemplateSize()

◆ useTemplate()

Fpdi::useTemplate ( $tpl,
$x = 0,
$y = 0,
$width = null,
$height = null,
$adjustPageSize = false )
inherited

Draws an imported page onto the page or another template.

Give only one of the size parameters (width, height) to calculate the other one automatically in view to the aspect ratio.

Parameters
mixed$tplThe template id
float | int | array$xThe abscissa of upper-left corner. Alternatively you could use an assoc array with the keys "x", "y", "width", "height", "adjustPageSize".
float | int$yThe ordinate of upper-left corner.
float | int | null$widthThe width.
float | int | null$heightThe height.
bool$adjustPageSize
Return values
arrayThe size
See also
FpdiTrait::getTemplateSize()

◆ writePdfType()

Fpdi::writePdfType ( PdfType $value)
protectedinherited

Writes a PdfType object to the resulting buffer.

Parameters
PdfType$value
Exceptions
PdfTypeException

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

◆ VERSION

const Fpdi::VERSION = '2.6.3'
inherited

FPDI version.

@string


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