Skip to content

Instantly share code, notes, and snippets.

@rlataguerra
Last active February 24, 2023 11:14
Show Gist options
  • Save rlataguerra/f04e872d4204c8622291521c098040dc to your computer and use it in GitHub Desktop.
Save rlataguerra/f04e872d4204c8622291521c098040dc to your computer and use it in GitHub Desktop.
Doppio example - node.js/nest.js/TypeScript (doppio.sh πŸ‘‹)
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