{"id":489,"date":"2024-08-09T18:37:50","date_gmt":"2024-08-09T16:37:50","guid":{"rendered":"https:\/\/honadi.com\/outils\/?page_id=489"},"modified":"2024-09-26T18:56:01","modified_gmt":"2024-09-26T16:56:01","slug":"fusionneur-de-pdf","status":"publish","type":"page","link":"https:\/\/honadi.com\/outils\/fusionneur-de-pdf\/","title":{"rendered":"Fusionneur de PDF"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"489\" class=\"elementor elementor-489\" data-elementor-post-type=\"page\">\n\t\t\t\t<div class=\"elementor-element elementor-element-a6b75e2 e-flex e-con-boxed wpr-particle-no wpr-jarallax-no wpr-parallax-no wpr-sticky-section-no wpr-equal-height-no e-con e-parent\" data-id=\"a6b75e2\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-61b4c4f elementor-widget elementor-widget-html\" data-id=\"61b4c4f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"max-w-4xl mx-auto bg-white shadow-2xl rounded-lg overflow-hidden\">\n    <div class=\"p-8\">\n        <div id=\"dropZone\" class=\"border-2 border-dashed border-gray-300 p-8 mb-6 text-center cursor-pointer rounded-lg bg-gray-50 transition-all duration-300 hover:border-[#F9B200]\">\n            <p class=\"text-lg mb-4\">Glissez-d\u00e9posez des fichiers PDF ici<\/p>\n            <p class=\"text-sm text-gray-500 mb-4\">ou<\/p>\n            <label for=\"fileInput\" class=\"custom-file-upload\">\n                S\u00e9lectionner des fichiers\n            <\/label>\n            <input type=\"file\" id=\"fileInput\" multiple accept=\".pdf\" class=\"hidden\">\n        <\/div>\n\n        <ul id=\"fileList\" class=\"mb-6 space-y-2 max-h-60 overflow-y-auto\"><\/ul>\n        \n        <button id=\"mergeButton\" class=\"w-full bg-[#030E41] text-white px-6 py-3 rounded-lg text-lg font-bold disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-300 hover:bg-opacity-90\" disabled>Fusionner les PDF<\/button>\n    <\/div>\n<\/div>\n\n<script src=\"https:\/\/cdn.tailwindcss.com\"><\/script>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/pdf-lib@1.17.1\/dist\/pdf-lib.min.js\"><\/script>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/sortablejs@1.14.0\/Sortable.min.js\"><\/script>\n<script src=\"https:\/\/cdn.jsdelivr.net\/npm\/sweetalert2@11\"><\/script>\n\n<style>\n    .custom-file-upload {\n        display: inline-block;\n        padding: 6px 12px;\n        cursor: pointer;\n        background-color: #F9B200;\n        color: #030E41;\n        border-radius: 4px;\n        transition: all 0.3s;\n    }\n    .custom-file-upload:hover {\n        background-color: #e6a500;\n    }\n<\/style>\n\n<script>\n    const dropZone = document.getElementById('dropZone');\n    const fileInput = document.getElementById('fileInput');\n    const fileList = document.getElementById('fileList');\n    const mergeButton = document.getElementById('mergeButton');\n    let pdfFiles = [];\n\n    dropZone.addEventListener('click', () => fileInput.click());\n    dropZone.addEventListener('dragover', (e) => {\n        e.preventDefault();\n        dropZone.classList.add('border-[#F9B200]', 'bg-[#F9B200]', 'bg-opacity-10');\n    });\n    dropZone.addEventListener('dragleave', () => {\n        dropZone.classList.remove('border-[#F9B200]', 'bg-[#F9B200]', 'bg-opacity-10');\n    });\n    dropZone.addEventListener('drop', (e) => {\n        e.preventDefault();\n        dropZone.classList.remove('border-[#F9B200]', 'bg-[#F9B200]', 'bg-opacity-10');\n        handleFileDrop(e);\n    });\n    fileInput.addEventListener('change', handleFileSelect);\n    mergeButton.addEventListener('click', mergePDFs);\n\n    new Sortable(fileList, {\n        animation: 150,\n        ghostClass: 'bg-[#F9B200] bg-opacity-50',\n        onEnd: updateFileOrder\n    });\n\n    function handleFileDrop(e) {\n        addFiles(e.dataTransfer.files);\n    }\n\n    function handleFileSelect(e) {\n        addFiles(e.target.files);\n    }\n\n    function addFiles(files) {\n        for (let file of files) {\n            if (file.type === 'application\/pdf' && !pdfFiles.some(f => f.name === file.name)) {\n                pdfFiles.push(file);\n                addFileToList(file);\n            }\n        }\n        updateMergeButton();\n    }\n\n    function addFileToList(file) {\n        const li = document.createElement('li');\n        li.className = 'bg-gray-100 p-3 rounded-lg flex justify-between items-center transition-all duration-300 hover:bg-gray-200';\n        li.innerHTML = `\n            <span class=\"font-medium truncate\">${file.name}<\/span>\n            <button class=\"text-red-500 hover:text-red-700 transition-colors duration-300\" onclick=\"removeFile('${file.name}')\">\u00d7<\/button>\n        `;\n        fileList.appendChild(li);\n    }\n\n    function removeFile(fileName) {\n        pdfFiles = pdfFiles.filter(file => file.name !== fileName);\n        fileList.innerHTML = '';\n        pdfFiles.forEach(addFileToList);\n        updateMergeButton();\n    }\n\n    function updateFileOrder() {\n        const newOrder = Array.from(fileList.children).map(li => li.firstChild.textContent);\n        pdfFiles = newOrder.map(name => pdfFiles.find(file => file.name === name));\n    }\n\n    function updateMergeButton() {\n        mergeButton.disabled = pdfFiles.length < 2;\n    }\n\n    async function mergePDFs() {\n        try {\n            Swal.fire({\n                title: 'Fusion en cours...',\n                html: 'Veuillez patienter pendant la fusion de vos fichiers PDF.',\n                allowOutsideClick: false,\n                didOpen: () => {\n                    Swal.showLoading();\n                },\n                background: '#FFFFFF',\n                confirmButtonColor: '#030E41',\n            });\n\n            const mergedPdf = await PDFLib.PDFDocument.create();\n            \n            for (const file of pdfFiles) {\n                const pdfBytes = await file.arrayBuffer();\n                const pdf = await PDFLib.PDFDocument.load(pdfBytes);\n                const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());\n                copiedPages.forEach((page) => mergedPdf.addPage(page));\n            }\n\n            const pdfBytes = await mergedPdf.save();\n            const blob = new Blob([pdfBytes], { type: 'application\/pdf' });\n            const url = URL.createObjectURL(blob);\n\n            const downloadLink = document.createElement('a');\n            downloadLink.href = url;\n            downloadLink.download = 'document_fusionne.pdf';\n            document.body.appendChild(downloadLink);\n            downloadLink.click();\n            document.body.removeChild(downloadLink);\n\n            Swal.fire({\n                title: 'Fusion termin\u00e9e !',\n                text: 'Vos fichiers PDF ont \u00e9t\u00e9 fusionn\u00e9s avec succ\u00e8s. Le t\u00e9l\u00e9chargement a commenc\u00e9 automatiquement.',\n                icon: 'success',\n                background: '#FFFFFF',\n                confirmButtonColor: '#030E41',\n            });\n        } catch (error) {\n            Swal.fire({\n                title: 'Erreur',\n                text: 'Une erreur est survenue lors de la fusion des PDF.',\n                icon: 'error',\n                background: '#FFFFFF',\n                confirmButtonColor: '#030E41',\n            });\n            console.error('Erreur lors de la fusion des PDF:', error);\n        }\n    }\n<\/script>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Glissez-d\u00e9posez des fichiers PDF ici ou S\u00e9lectionner des fichiers Fusionner les PDF<\/p>\n","protected":false},"author":1,"featured_media":2773,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"no-sidebar","site-content-layout":"","ast-site-content-layout":"full-width-container","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"disabled","ast-breadcrumbs-content":"","ast-featured-img":"disabled","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"class_list":["post-489","page","type-page","status-publish","has-post-thumbnail","hentry"],"_links":{"self":[{"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/pages\/489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/comments?post=489"}],"version-history":[{"count":7,"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/pages\/489\/revisions"}],"predecessor-version":[{"id":499,"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/pages\/489\/revisions\/499"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/media\/2773"}],"wp:attachment":[{"href":"https:\/\/honadi.com\/outils\/wp-json\/wp\/v2\/media?parent=489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}