@@ -245,21 +245,28 @@ public function renderMailTemplate(MailTemplate $mailTemplate, $entity = null, a
245245 return $ processedFileName ;
246246 }
247247
248- $ client = HttpClient::create ($ this ->options ['libreoffice_http_client_options ' ]);
248+ $ client = HttpClient::create ($ this ->options ['gotenberg_http_client_options ' ]);
249+
250+ // Gotenberg requires file extension to work.
251+ $ renamedProcessedFileName = $ processedFileName .'.docx ' ;
252+ $ this ->filesystem ->copy ($ processedFileName , $ renamedProcessedFileName );
253+
249254 $ formFields = [
250- 'data ' => DataPart::fromPath ($ processedFileName ) ,
255+ 'files ' => [ DataPart::fromPath ($ renamedProcessedFileName )] ,
251256 ];
252257 $ formData = new FormDataPart ($ formFields );
253258
254259 try {
255- $ response = $ client ->request ('POST ' , '/convert-to/pdf ' , [
260+ $ response = $ client ->request ('POST ' , '/forms/libreoffice/convert ' , [
256261 'headers ' => $ formData ->getPreparedHeaders ()->toArray (),
257262 'body ' => $ formData ->bodyToIterable (),
258263 ]);
259264 $ content = $ response ->getContent ();
260265 } catch (ClientException |TransportException $ exception ) {
261- $ this ->logger ->critical (sprintf ('Error talking to Libreoffice : %s ' , $ exception ->getMessage ()), ['exception ' => $ exception ]);
266+ $ this ->logger ->critical (sprintf ('Error talking to Gotenberg : %s ' , $ exception ->getMessage ()), ['exception ' => $ exception ]);
262267 throw new MailTemplateException (sprintf ('Error rendering mail template %s ' , $ mailTemplate ->getName ()), $ exception ->getCode (), $ exception );
268+ } finally {
269+ $ this ->filesystem ->remove ($ renamedProcessedFileName );
263270 }
264271
265272 $ fileName = $ this ->filesystem ->tempnam ('/tmp/ ' , 'mail_template ' , '.pdf ' );
@@ -596,7 +603,7 @@ private function configureOptions(OptionsResolver $resolver)
596603 'template_file_directory ' ,
597604 'user_signatures_file_directory ' ,
598605 'user_signature_height ' ,
599- 'libreoffice_http_client_options ' ,
606+ 'gotenberg_http_client_options ' ,
600607 ]);
601608 $ resolver ->setAllowedTypes ('template_types ' , 'array ' );
602609 }
0 commit comments