Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By yangli0516 on
I want to use the FPDF library in my custom module. So I installed the Libraries module and put FPDF library under:
'sites\all\libraries\fpdf'. The structure of the fpdf folder is:
-font
-changelog.htm
-fpdf.php
In my module, I implemented hook_libraries_info. However, it failed to load the library. Is there something I did wrong in the following code?
/**
* Implement hook_libraries_info
*/
function mymodule_libraries_info() {
$libraries['fpdf'] = array(
'name' => 'FPDF',
'vendor url' => 'http://www.fpdf.org/',
'download url' => 'http://www.fpdf.org/',
'version arguments' => array(
'file' => 'changelog.htm', // Could be any file with version info
'pattern' => '/v\d\.\d+/',
),
'files' => array(
'php' => array('fpdf.php'),
),
);
return $libraries;
}
/**
* Create pdf file for a quote
*/
function mymodule_create_quote_pdf() {
if (($library = libraries_load('fpdf')) && !empty($library['loaded'])) {
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->MultiCell(100,3,'On the Insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look');
$pdf->Output(drupal_realpath('public://').'/quote.pdf', 'F');
drupal_set_message('PDF saved.');
}
else {
drupal_set_message('Could not load fpdf library', 'error');
}
}