import {useApi} from '~/composables/useApi' export const usePdfPrinter = () => { const api = useApi() const printPdf = async (url: string): Promise => { 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 filename = `test.pdf`; 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 } }