File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33namespace Petecoop \ODT \Converters ;
44
55use Gotenberg \Gotenberg ;
6+ use Gotenberg \Stream as GotenbergStream ;
7+ use GuzzleHttp \Psr7 \Stream ;
68use Petecoop \ODT \Files \OdtFile ;
79use Petecoop \ODT \Files \PdfFile ;
810
@@ -25,10 +27,24 @@ public function url(): string
2527
2628 public function convert (OdtFile $ file ): PdfFile
2729 {
28- //
29-
30- Gotenberg::libreOffice ($ this ->url );
31-
32- return new PdfFile ($ pdfPath , $ tmp );
30+ $ handle = fopen ('php://temp ' , 'r+b ' );
31+ try {
32+ $ file ->toStream ($ handle );
33+ $ stream = new Stream ($ handle );
34+ $ request = Gotenberg::libreOffice ($ this ->url )->convert (new GotenbergStream ($ file ->getName (), $ stream ));
35+ $ response = Gotenberg::send ($ request );
36+ } finally {
37+ fclose ($ handle );
38+ }
39+
40+ $ stream = fopen ('php://temp ' , 'r+b ' );
41+ $ response ->getBody ()->rewind ();
42+ while (!$ response ->getBody ()->eof ()) {
43+ fwrite ($ stream , $ response ->getBody ()->read (1024 ));
44+ }
45+
46+ $ pdf = new PdfFile ();
47+ $ pdf ->name (basename ($ file ->getName (), '.odt ' ));
48+ return $ pdf ->fromStream ($ stream );
3349 }
3450}
Original file line number Diff line number Diff line change 44
55use Illuminate \Support \Facades \Facade ;
66
7-
87/**
98 * @method static \Petecoop\ODT\Files\OdtFile open(string $path)
109 * @method static \Petecoop\ODT\ODT officeBinary(string $binaryPath)
10+ * @method static \Petecoop\ODT\ODT gotenberg(string $url)
1111 * @method static \Petecoop\ODT\Compiler compiler()
12- * @method static \Petecoop\ODT\OfficeConverter converter()
12+ * @method static \Petecoop\ODT\Converters`Coverter converter()
1313 */
1414class ODT extends Facade
1515{
You can’t perform that action at this time.
0 commit comments