JE DONNE MON CODE
Voici le fichier modules_xxx.php que jai généré :
<?php
/* Copyright (C) LAJ DEVELOPPEMENT
*/
/**
* \file htdocs/custom/agriculture/core/modules/agriculture/modules_arbre.php
* \ingroup agriculture
* \brief File that contains parent class for agriculture PDF models
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonnumrefgenerator.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // required for use by classes that inherit
/**
* Parent class for agriculture PDF models
*/
abstract class ModelePDFArbre extends CommonDocGenerator
{
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of active generation modules
*
* @param DoliDB $db Database handler
* @param integer $maxfilenamelength Max length of value to show
* @return array List of templates
*/
public static function liste_modeles($db, $maxfilenamelength = 0)
{
// phpcs:enable
$type = 'arbre';
$modeldir = DOL_DOCUMENT_ROOT . '/custom/agriculture/core/modules/agriculture/doc/';
$list = array();
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
$list = getListOfModels($db, $type, $maxfilenamelength);
return $list;
}
/**
* Generate a PDF document
*
* @param Object $object Object to generate
* @param Translate $langs Language object
* @param string $srctemplatepath Source template path
* @param int $hidedetails Hide details
* @param int $hidedesc Hide description
* @param int $hideref Hide reference
* @return int 1 if OK, <0 if KO
*/
/**
* Generate a PDF document
*
* @param Object $object Object to generate
* @param Translate $langs Language object
* @param string $srctemplatepath Source template path
* @param int $hidedetails Hide details
* @param int $hidedesc Hide description
* @param int $hideref Hide reference
* @return int 1 if OK, <0 if KO
*/
public function write_file($object, $langs, $srctemplatepath = '', $hidedetails = 0, $hidedesc = 0, $hideref = 0)
{
global $conf, $langs;
// Load translation files required by the page
$langs->loadLangs(array("main", "bills", "products", "dict", "companies"));
// Define output directory to custom/agriculture/arbre
$dir = DOL_DOCUMENT_ROOT . '/custom/agriculture/arbre';
dol_syslog("Output directory: " . $dir, LOG_DEBUG);
// Check if the directory exists
if (!file_exists($dir)) {
dol_syslog("Directory does not exist: " . $dir, LOG_DEBUG);
if (!dol_mkdir($dir)) {
setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), null, 'errors');
dol_syslog("Failed to create directory: " . $dir, LOG_ERR);
return -1;
}
dol_syslog("Directory created successfully: " . $dir, LOG_DEBUG);
} else {
dol_syslog("Directory already exists: " . $dir, LOG_DEBUG);
}
// Check directory permissions
if (!is_writable($dir)) {
setEventMessages($langs->trans("ErrorDirNotWritable", $dir), null, 'errors');
dol_syslog("Directory not writable: " . $dir, LOG_ERR);
return -1;
}
dol_syslog("Directory is writable: " . $dir, LOG_DEBUG);
// Define output file name
$file = $dir . "/arbre_" . $object->ref . ".pdf";
dol_syslog("Output file: " . $file, LOG_DEBUG);
// Create PDF document
$pdf = pdf_getInstance();
$default_font_size = pdf_getPDFFontSize($langs);
$pdf->SetAutoPageBreak(1, 0);
$pdf->SetFont(pdf_getPDFFont($langs));
// Add a page
$pdf->AddPage();
$pdf->SetFont('', 'B', $default_font_size + 3);
$pdf->MultiCell(0, 3, $langs->transnoentities("Arbre") . " " . $object->ref);
// Clear output buffer before generating the PDF
if (ob_get_length()) {
ob_end_clean();
}
// Output PDF
if ($pdf->Output($file, 'FI') === false) {
setEventMessages($langs->trans("ErrorFailedToCreatePDF", $file), null, 'errors');
dol_syslog("Failed to create PDF: " . $file, LOG_ERR);
return -1;
}
dol_syslog("PDF created successfully: " . $file, LOG_DEBUG);
return 1;
}
}
L’erreur est corrigé, je peut séléctionné le doctype(préalablement stocké dans ma BDD.
Je constate, lors de la génération, un message :
TCPDF ERROR: Unable to create output file: error-diroutput-not-defined-for-this-object=arbre/test/test.pdf
la bdd :
2
standard_arbre
1
arbre
standard_arbre
NULL
nom du fichier dans pdf_standard_arbre.php