type = $type; } /** * Convert given document to JSON file which contains the document's data. * * @throws \Exception */ public function execute() { // if ($this->type === 'pdf') { // $this->convertToDocx(); // } if ($this->type !== 'docx') { $this->convertToDocx(); } $json = $this->convertDocxToJson(); $this->storage->put("$this->directoryPath/document.json", json_encode($json)); $this->deleteOriginalDocument(); } protected function convertDocxToJson() { $reader = new DocxReader($this->storage, $this->path); return $reader->execute(); } /** * Convert document to DOCX format in order to extract data. * * @throws \Exception */ protected function convertToDocx() { $office = new Office(); $success = $office->run( 'docx', $this->storage->path($this->path), $this->storage->path($this->directoryPath) ); if (! $success) { throw new \Exception('Failed when converting from ' . $this->type . ' to DOCX for file: ' . $this->path); } $this->deleteOriginalDocument(); $this->setPath(str_replace($this->type, 'docx', $this->path)); $this->type = 'docx'; } }