Last active
February 24, 2023 11:14
-
-
Save rlataguerra/f04e872d4204c8622291521c098040dc to your computer and use it in GitHub Desktop.
Doppio example - node.js/nest.js/TypeScript (doppio.sh π)
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
async generatePdf(link: string, token: string): Promise<string> { | |
const doppioApiUrl = this.configService.get<string>('DOPPIO_API_URL'); | |
const doppioApiKey = this.configService.get<string>('DOPPIO_API_KEY'); | |
const data = { | |
page: { | |
pdf: { | |
printBackground: true, | |
}, | |
goto: { | |
url: link, | |
options: { | |
waitUntil: ['load', 'networkidle0'], | |
}, | |
}, | |
setLocalStorageItems: [{ key: 'TOKEN', value: token }], | |
}, | |
}; | |
const config = { | |
headers: { | |
Authorization: `Bearer ${doppioApiKey}`, | |
}, | |
}; | |
try { | |
const responseAsObserver = this.httpService.post( | |
`${doppioApiUrl}/v1/render/pdf/sync`, | |
data, | |
config, | |
); | |
const pdf = await responseAsObserver.toPromise(); | |
return pdf.data.documentUrl as string; | |
} catch (error) { | |
this.logger.error(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment