Faire pivoter les pages PDF

Faites pivoter facilement toutes les pages ou des pages spécifiques d'un fichier PDF

Sélectionnez votre fichier PDF

ou glissez-déposez-le ici

Contrôlez chaque page individuellement

Faites pivoter n'importe quelle page en cliquant sur ses flèches de rotation, ou utilisez ces boutons pour faire pivoter toutes les pages à la fois

Traitement…

Traité avec succès

Le résultat final apparaîtra ici une fois le traitement terminé.

document.addEventListener('DOMContentLoaded',function(){ var shell = document.getElementById('toolShell'); function loadScript(src, check){ return new Promise(function(resolve, reject){ if(check && check()) { resolve(); return; } var existing = document.querySelector('script[src="' + src + '"]'); if(existing){ existing.addEventListener('load', function(){ resolve(); }); existing.addEventListener('error', reject); return; } var el = document.createElement('script'); el.src = src; el.async = true; el.onload = function(){ resolve(); }; el.onerror = function(){ reject(new Error('load failed')); }; document.head.appendChild(el); }); } function ensurePdfLib(){ return loadScript('https://cdnjs.cloudflare.com/ajax/libs/pdf-lib/1.17.1/pdf-lib.min.js', function(){ return window.PDFLib; }) .then(function(){ return window.PDFLib; }); } function ensurePdfJs(){ return loadScript('https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js', function(){ return window.pdfjsLib; }) .then(function(){ if(window.pdfjsLib && window.pdfjsLib.GlobalWorkerOptions){ window.pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js'; } return window.pdfjsLib; }); } function fmtSize(b){ if(b<1024) return b+' B'; if(b<1024*1024) return (b/1024).toFixed(1)+' KB'; return (b/(1024*1024)).toFixed(1)+' MB'; } var CHECK_SVG = ''; var ROT_ICO_L = ''; var ROT_ICO_R = ''; var $dz = shell.querySelector('#dz'), $fi = shell.querySelector('#fileInput'), $fl = shell.querySelector('#fileList'), $errB = shell.querySelector('#errBanner'), $errT = $errB.querySelector('span'), $gridWrap = shell.querySelector('#pageGridWrap'), $pageList = shell.querySelector('#pageList'), $rotAllCcw = shell.querySelector('#rotAllCcw'), $rotAllCw = shell.querySelector('#rotAllCw'), $run = shell.querySelector('#runBtn'), $prog = shell.querySelector('#progWrap'), $bar = shell.querySelector('#progBar'), $lbl = shell.querySelector('#progLabel'), $result = shell.querySelector('#resultPanel'); var file = null, pageCount = 0, rotations = []; var thumbCache = {}, pdfJsDoc = null, thumbObserver = null; function showErr(m){ $errT.textContent = m; $errB.classList.add('show'); } function hideErr(){ $errB.classList.remove('show'); } function setProgress(p,l){ $prog.classList.add('show'); $bar.style.width = p + '%'; if(l) $lbl.textContent = l; } function endProgress(cb){ setTimeout(function(){ $prog.classList.remove('show'); cb && cb(); }, 200); } function ensurePdfJsDoc(){ if(pdfJsDoc) return Promise.resolve(pdfJsDoc); if(!file) return Promise.reject(new Error('no-file')); return ensurePdfJs().then(function(pdfjsLib){ return file.arrayBuffer().then(function(bytes){ return pdfjsLib.getDocument({data:bytes}).promise; }); }).then(function(doc){ pdfJsDoc = doc; return doc; }); } function renderThumb(index, wrapEl){ if(thumbCache[index]){ wrapEl.style.backgroundImage = 'url(' + thumbCache[index] + ')'; wrapEl.innerHTML=''; return; } ensurePdfJsDoc().then(function(doc){ return doc.getPage(index+1); }).then(function(page){ var vp0 = page.getViewport({scale:1}); var scale = 170 / vp0.width; var viewport = page.getViewport({scale:scale}); var canvas = document.createElement('canvas'); canvas.width = viewport.width; canvas.height = viewport.height; var ctx = canvas.getContext('2d'); return page.render({canvasContext:ctx, viewport:viewport}).promise.then(function(){ var url = canvas.toDataURL('image/jpeg', 0.72); thumbCache[index] = url; if(wrapEl && wrapEl.isConnected){ wrapEl.style.backgroundImage = 'url(' + url + ')'; wrapEl.innerHTML=''; } }); }).catch(function(){}); } function observeThumb(card){ if(!thumbObserver){ thumbObserver = new IntersectionObserver(function(entries){ entries.forEach(function(entry){ if(!entry.isIntersecting) return; renderThumb(Number(entry.target.getAttribute('data-idx')), entry.target.querySelector('.thumb-canvas-wrap')); thumbObserver.unobserve(entry.target); }); }, {root:$pageList, rootMargin:'250px'}); } thumbObserver.observe(card); } function applyCardRotation(card){ var idx = Number(card.getAttribute('data-idx')); var wrap = card.querySelector('.thumb-canvas-wrap'); if(wrap) wrap.style.transform = 'rotate(' + rotations[idx] + 'deg)'; } function renderGrid(){ if(thumbObserver) thumbObserver.disconnect(); $pageList.innerHTML = ''; var frag = document.createDocumentFragment(); for(var i=0;i' + (i+1) + '' + '
' + '' + '' + '
'; frag.appendChild(card); observeThumb(card); })(i); } $pageList.appendChild(frag); $gridWrap.classList.add('show'); $run.disabled = false; } $pageList.addEventListener('click', function(e){ var btn = e.target.closest('.thumb-rot-btn'); if(!btn) return; var card = btn.closest('.thumb-card'); var idx = Number(card.getAttribute('data-idx')); var delta = Number(btn.getAttribute('data-dir')); rotations[idx] = ((rotations[idx] + delta) % 360 + 360) % 360; applyCardRotation(card); }); $rotAllCw.addEventListener('click', function(){ for(var i=0;i
' + fmtSize(f.size) + ''; setProgress(20, FastolsI18n.t('tool.rotate.reading', 'Lecture du nombre de pages…')); ensurePdfLib().then(function(PDFLib){ return f.arrayBuffer().then(function(bytes){ return PDFLib.PDFDocument.load(bytes, {ignoreEncryption:true}); }); }).then(function(pdf){ pageCount = pdf.getPageCount(); rotations = []; for(var i=0;i

' + FastolsI18n.t('tool.rotate.doneMsg', 'Les pages ont été pivotées avec succès') + '

' + '

' + FastolsI18n.t('tool.rotate.doneMsg', 'Les pages ont été pivotées avec succès') + '.

' + '
' + FastolsI18n.t('tool.rotate.downloadBtn', 'Télécharger le fichier pivoté') + '' + '
'; $result.classList.add('show'); }); }).catch(function(){ $prog.classList.remove('show'); $run.disabled = false; showErr(FastolsI18n.t('tool.pdf.errProcess', 'Impossible de traiter ce fichier. Assurez-vous qu\'il n\'est pas corrompu ou protégé par un mot de passe.')); }); }); });