import {useApi} from '~/composables/useApi' export const usePdfPrinter = () => { const api = useApi() const receptionStore = useReceptionStore() const currentReception = receptionStore.current const printPdf = async (url: string, previewWindow?: Window | null): 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`; if (previewWindow) { previewWindow.location.replace(blobUrl) } const a = document.createElement('a') a.href = blobUrl a.download = filename a.style.display = 'none' document.body.appendChild(a) a.click() a.remove() setTimeout(() => URL.revokeObjectURL(blobUrl), 60_000); } return { printPdf } }