public static function saveDocument($dataObject, $path, $fileName) { if (file_exists($path . $fileName)) { unlink($path . $fileName); } try { /*Document*/ $data = Builder::buildDocument($dataObject); if ($data == null) { throw new Exception("Can't build document based on " . get_class($dataObject)); } if ($data->metadata != null) { /*Property*/ $pageSizeProperty = $data->metadata->getPropertyByName(Property::$PAGE_FORMAT); if ($pageSizeProperty != null) { if ($pageSizeProperty->value == Property::$PAGE_FORMAT_A4) { $data->width = Document::$pageFormats['a4'][0]; $data->height = Document::$pageFormats['a4'][1]; } else { if ($pageSizeProperty->value == Property::$PAGE_FORMAT_A4_ALBUM) { $data->width = Document::$pageFormats['a4'][1]; $data->height = Document::$pageFormats['a4'][0]; } } } } $pdfwr = null; Log::log(LoggingConstants::MYDEBUG, "PDF: create file"); if (!is_numeric($data->width)) { $pdfwr = new PDF("P", "pt", $data->width); } else { $pdfwr = new PDF("P", "pt", array($data->width, $data->height)); } $pdfwr->SetAutoPageBreak(false); //, abs($data->marginBottom)); $data->write($pdfwr); Log::log(LoggingConstants::MYDEBUG, "WRITE FINISHED"); $pdfwr->Output($path . $fileName, "F"); } catch (Exception $exception) { Log::log(LoggingConstants::MYDEBUG, $exception->getMessage() . "\n" . $exception->getTrace()); throw $exception; } // fwrite($fileHandler, $buf); // fclose($fileHandler); }
public function buildOnMethod($value) { return Builder::buildDocument(DataUtils::getValue($value)); }