VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /var/www/html/libs/absol-acomp/demo/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/libs/absol-acomp/demo/pdf_merge.html
<html>
<head>
    <script src="https://unpkg.com/pdf-lib/dist/pdf-lib.js"></script>
    <script>
        function readFileAsync(file) {
            return new Promise((resolve, reject) => {
                let reader = new FileReader();
                reader.onload = () => {
                    resolve(reader.result);
                };
                reader.onerror = reject;
                reader.readAsArrayBuffer(file);
            })
        }
        function download(file, filename, type) {
            const link = document.getElementById('link');
            link.download = filename;
            let binaryData = [];
            binaryData.push(file);
            link.href = URL.createObjectURL(new Blob(binaryData, {type: type}))
        }
        async function merge() {
            let PDFDocument = PDFLib.PDFDocument;

            const in1 = document.getElementById('file1').files[0];
            const in2 = document.getElementById('file2').files[0];
            let bytes1 = await readFileAsync(in1);
            let bytes2 = await readFileAsync(in2);
            const pdf1 = await PDFDocument.load(bytes1);
            const pdf2 = await PDFDocument.load(bytes2);

            const mergedPdf = await PDFDocument.create();
            const copiedPagesA = await mergedPdf.copyPages(pdf1, pdf1.getPageIndices());
            copiedPagesA.forEach((page) => mergedPdf.addPage(page));
            const copiedPagesB = await mergedPdf.copyPages(pdf2, pdf2.getPageIndices());
            copiedPagesB.forEach((page) => mergedPdf.addPage(page));
            const mergedPdfFile = await mergedPdf.save();

            download(mergedPdfFile, 'pdf-lib_page_copying_example.pdf', 'application/pdf')
        }
    </script>
</head>
<body>
<input type="file" id="file1"> <br>
<input type="file" id="file2"> <br>
<button onclick="merge()">Merge</button> <br>
<a id="link">Download</a>
</body>
</html>

VaKeR 2022