You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Per me sarebbe comodo intercettare i tasti in modo che, quando si è su desktop e si visualizza un file PDF, premendo CTRL + S venga scaricato il PDF anziché l'HTML della pagina.
Si può intercettare il CTRL + S così, anche se con un po' di prove ho visto che non funziona all'interno dell'iframe del PDF viewer (quindi il focus dev'essere fuori dall'iframe).
Un modo estremamente crudo è
document.addEventListener('keydown', e => {
if (e.ctrlKey && e.key === 's') {
e.preventDefault();
downloadPdf();
}
});
function downloadPdf() {
const pdfUrl = 'url-al-pdf';
fetch(pdfUrl, { mode: 'cors' }) // esempio con fetch
.then(res => res.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'nome-file.pdf');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
});
}
Non è una cosa importante, giusto un nice to have di bassissima priorità
The text was updated successfully, but these errors were encountered:
Per me sarebbe comodo intercettare i tasti in modo che, quando si è su desktop e si visualizza un file PDF, premendo CTRL + S venga scaricato il PDF anziché l'HTML della pagina.
Si può intercettare il CTRL + S così, anche se con un po' di prove ho visto che non funziona all'interno dell'iframe del PDF viewer (quindi il focus dev'essere fuori dall'iframe).
Un modo estremamente crudo è
Non è una cosa importante, giusto un nice to have di bassissima priorità
The text was updated successfully, but these errors were encountered: