Skip to content

Instantly share code, notes, and snippets.

@jdileonardo
Last active November 21, 2020 00:02
Show Gist options
  • Save jdileonardo/b2489dbad7ed720958ed5b068ce945a9 to your computer and use it in GitHub Desktop.
Save jdileonardo/b2489dbad7ed720958ed5b068ce945a9 to your computer and use it in GitHub Desktop.
Spring Boot Gotenberg WebClient PDF
WebClient webClient = WebClient.builder()
.baseUrl("http://localhost:3000/convert/url")
.build();
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("remoteURL", "https://google.com");
formData.add("marginTop", "0");
formData.add("marginBottom", "0");
formData.add("marginLeft", "0");
formData.add("marginRight", "0");
Flux<DataBuffer> dataBufferFlux = webClient.post()
.contentType(org.springframework.http.MediaType.MULTIPART_FORM_DATA)
.body(BodyInserters.fromMultipartData(formData))
.accept()
.retrieve()
.bodyToFlux(DataBuffer.class);
Path path = FileSystems.getDefault().getPath("target/report.pdf");
DataBufferUtils.write(dataBufferFlux, path, CREATE).block();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment