b1c3952d09
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #271 | Créer une nouvelle expédition (étape 1) | ## Description de la PR ## Modification du .env ## Check list [x ] Pas de régression TU/TI/TF rédigée [x ] TU/TI/TF OK [x ] CHANGELOG modifié Co-authored-by: kevin <kevin@yuno.malio.fr> Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/12 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
30 lines
842 B
TypeScript
30 lines
842 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
|
|
export const usePdfPrinter = () => {
|
|
const api = useApi()
|
|
|
|
const printPdf = async (url: string, filename = 'document.pdf'): Promise<void> => {
|
|
const blob = await api.getBlob(url)
|
|
|
|
const pdfBlob = blob.type === 'application/pdf'
|
|
? blob
|
|
: new Blob([blob], { type: 'application/pdf' })
|
|
|
|
const blobUrl = URL.createObjectURL(pdfBlob)
|
|
|
|
const a = document.createElement('a')
|
|
a.href = blobUrl
|
|
a.download = filename
|
|
a.style.display = 'none'
|
|
document.body.appendChild(a)
|
|
a.click()
|
|
a.remove()
|
|
// L'ouverture dans un nouvel onglet déclenche un 2e PDF sans le nom personnalisé.
|
|
setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000)
|
|
}
|
|
|
|
return {
|
|
printPdf
|
|
}
|
|
}
|