Skip to content

Commit 8bb6b98

Browse files
committed
Merge branch 'feature/gotenberg'
2 parents d22d434 + 16be07e commit 8bb6b98

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

.env

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ TRUSTED_PROXIES=
7979
# Default time zone (default: Europe/Copenhagen)
8080
# DEFAULT_TIME_ZONE=
8181

82-
# Use environment variables set by symfony (cli) with fallback to docker compose values.
83-
LIBREOFFICE_API_BASE_URL="http://${LIBREOFFICE_API_HOST:-libreoffice-api}:${LIBREOFFICE_API_PORT:-9980}"
82+
GOTENBERG_API_BASE_URL="http://gotenberg:3000"
8483

8584
# Digital post
8685
DIGITAL_POST_SYSTEM_ID=''

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ about writing changes to this log.
1010

1111
## [Unreleased]
1212

13+
## [1.9.0] - 2025-01-22
14+
15+
- Switched to [Gotenberg](https://github.com/gotenberg/gotenberg) for docx
16+
to pdf generation.
17+
1318
## [1.8.0] - 2025-01-14
1419

1520
- Made kle searchable.
@@ -371,7 +376,8 @@ Fixed error in unescaped characters in filename
371376
- [TVIST1-604](https://jira.itkdev.dk/browse/TVIST1-604):
372377
Resolved issue regarding time formats.
373378

374-
[Unreleased]: https://github.com/itk-dev/naevnssekretariatet/compare/1.8.0...HEAD
379+
[Unreleased]: https://github.com/itk-dev/naevnssekretariatet/compare/1.9.0...HEAD
380+
[1.9.0]: https://github.com/itk-dev/naevnssekretariatet/compare/1.8.0...1.9.0
375381
[1.8.0]: https://github.com/itk-dev/naevnssekretariatet/compare/1.7.1...1.8.0
376382
[1.7.1]: https://github.com/itk-dev/naevnssekretariatet/compare/1.7.0...1.7.1
377383
[1.7.0]: https://github.com/itk-dev/naevnssekretariatet/compare/1.6.2...1.7.0

config/services.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ services:
8585
# This value must match vich_uploader.mappings.user_signatures.upload_destination
8686
user_signatures_file_directory: '%kernel.project_dir%/upload/user-signatures'
8787
user_signature_height: '%env(USER_SIGNATURE_HEIGHT)%'
88-
libreoffice_http_client_options:
89-
base_uri: '%env(LIBREOFFICE_API_BASE_URL)%'
88+
gotenberg_http_client_options:
89+
base_uri: '%env(GOTENBERG_API_BASE_URL)%'
9090
verify_peer: false
9191
verify_host: false
9292

docker-compose.override.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ services:
1111
# Allow uploading 9 very large files.
1212
- PHP_POST_MAX_SIZE=700M
1313
depends_on:
14-
- libreoffice-api
14+
- gotenberg
1515

16-
libreoffice-api:
17-
build: ./.docker/libreoffice-api
16+
gotenberg:
17+
image: gotenberg/gotenberg:8
1818
restart: unless-stopped
1919
networks:
2020
- app

docker-compose.server.override.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ services:
77
# Allow uploading 9 very large files.
88
- PHP_POST_MAX_SIZE=700M
99
depends_on:
10-
- libreoffice-api
10+
- gotenberg
1111

1212
nginx:
1313
environment:
1414
# Allow uploading 9 very large files.
1515
NGINX_MAX_BODY_SIZE: 100M
1616

17-
libreoffice-api:
18-
build: ./.docker/libreoffice-api
17+
gotenberg:
18+
image: gotenberg/gotenberg:8
1919
restart: unless-stopped
2020
networks:
2121
- app

src/Service/MailTemplateHelper.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)