import {useApi} from '~/composables/useApi' export const usePdfPrinter = () => { const api = useApi() const receptionStore = useReceptionStore() const currentReception = receptionStore.current 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 = `${currentReception.identificationNumber}_${currentReception.supplier.name}_${currentReception.licensePlate}.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 } }