generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDIT-2353: ✨ Add in gotenberg and start on download (#48)
- Loading branch information
1 parent
446dc71
commit 016b7b8
Showing
21 changed files
with
417 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import superagent from 'superagent' | ||
|
||
export type PdfMargins = { | ||
marginTop?: string | ||
marginBottom?: string | ||
marginLeft?: string | ||
marginRight?: string | ||
} | ||
|
||
export default class GotenbergClient { | ||
private gotenbergHost: string | ||
|
||
constructor(gotenbergHost: string) { | ||
this.gotenbergHost = gotenbergHost | ||
} | ||
|
||
async renderPdfFromHtml( | ||
html: string, | ||
headerHtml: string, | ||
footerHtml: string, | ||
options: PdfMargins = {}, | ||
): Promise<Buffer> { | ||
const { marginBottom, marginLeft, marginRight, marginTop } = options | ||
const request = superagent | ||
.post(`${this.gotenbergHost}/forms/chromium/convert/html`) | ||
.set('Content-Type', 'multi-part/form-data') | ||
.buffer(true) | ||
.attach('files', Buffer.from(html), 'index.html') | ||
.attach('files', Buffer.from(headerHtml), 'header.html') | ||
.attach('files', Buffer.from(footerHtml), 'footer.html') | ||
.responseType('blob') | ||
|
||
// Gotenberg defaults to using A4 format. Page size and margins specified in inches | ||
if (marginTop) request.field('marginTop', marginTop) | ||
if (marginBottom) request.field('marginBottom', marginBottom) | ||
if (marginLeft) request.field('marginLeft', marginLeft) | ||
if (marginRight) request.field('marginRight', marginRight) | ||
|
||
// Execute the POST to the Gotenberg container | ||
const response = await request | ||
return response.body | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.