Commit e5e18b31 authored by Jean-Baptiste Oellers's avatar Jean-Baptiste Oellers
Browse files

Ajout génération pdf

parent 31294b2f
Loading
Loading
Loading
Loading
+36 −0
Changes for module/Oscar/src/Oscar/Controller/ConventionModeleInstanceController.php: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -181,8 +181,44 @@ class ConventionModeleInstanceController extends AbstractOscarController impleme
                //->setDateDeposit($dateDeposit)
                //->setDateSend($dateSend);


            $infoPDF = pathinfo($newDocumentPath);

            $output=null;
            $retval=null;
            exec('HOME=/tmp/ libreoffice --headless --convert-to pdf ' . escapeshellarg($newDocumentPath) . ' --outdir ' . escapeshellarg($infoPDF['dirname']) . ' 2>&1', $output, $retval);
            if ($retval !== 0) {
                throw new \RuntimeException('libreoffice returned error status ' . $retval . ' and output: ' . print_r($output));
            }

            $newDocumentPathPDF = $infoPDF['dirname'] . DIRECTORY_SEPARATOR . $infoPDF['filename'] . '.pdf';

            $renameOriginalPDF = basename($renameOriginal, '.odt') . '.pdf';
            $renamedPDF = basename($renamed, '.odt') . '.pdf';

            $fileSizePDF = filesize($newDocumentPathPDF);

            // Création du document PDF
            $documentPDF = new \Oscar\Entity\ContractDocument();
            $this->getEntityManager()->persist($documentPDF);

            $documentPDF
                ->setVersion(1)
                ->setDateUpdoad(new \DateTime())
                ->setFileName($renameOriginalPDF)
                ->setPath($renamedPDF)
                ->setLocation(\Oscar\Entity\ContractDocument::LOCATION_LOCAL_FILE)
                ->setFileTypeMime("application/pdf")
                ->setFileSize($fileSizePDF)
                //->setPerson($sender)
                ->setTabDocument($tabDocument)
                ->setTypeDocument($typeDocument)
                ->setGrant($newActivity);
                //->setInformation($description)
                //->setDateDeposit($dateDeposit)
                //->setDateSend($dateSend);

        }
        

        $this->getEntityManager()->flush();