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
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<meta name="theme-color" content="#f7f8ff" />
|
| 7 |
+
<meta name="description" content="Merge PDF files quickly and privately in your browser with PDFix." />
|
| 8 |
+
<title>Merge PDF Files Online — PDFix</title>
|
| 9 |
+
<style>
|
| 10 |
+
:root {
|
| 11 |
+
--bg: #f7f8ff; --surface: #fff; --ink: #17182d; --muted: #71738a;
|
| 12 |
+
--line: #e7e8f2; --primary: #635bff; --primary-dark: #4c43e8;
|
| 13 |
+
--soft: #efedff; --green: #119b82; --danger: #d94765;
|
| 14 |
+
--shadow: 0 18px 55px rgba(47,43,112,.09);
|
| 15 |
+
}
|
| 16 |
+
* { box-sizing: border-box; }
|
| 17 |
+
body {
|
| 18 |
+
margin: 0; min-height: 100vh; color: var(--ink);
|
| 19 |
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
| 20 |
+
background: radial-gradient(circle at 85% 5%, rgba(177,171,255,.19), transparent 25rem),
|
| 21 |
+
radial-gradient(circle at 4% 35%, rgba(115,221,211,.12), transparent 22rem), var(--bg);
|
| 22 |
+
line-height: 1.5;
|
| 23 |
+
}
|
| 24 |
+
a { color: inherit; text-decoration: none; }
|
| 25 |
+
button, input { font: inherit; }
|
| 26 |
+
button { cursor: pointer; }
|
| 27 |
+
.container { width: min(1040px, calc(100% - 32px)); margin: 0 auto; }
|
| 28 |
+
header { padding: 20px 0; }
|
| 29 |
+
.nav { display:flex; align-items:center; justify-content:space-between; gap:18px; }
|
| 30 |
+
.brand { display:inline-flex; align-items:center; gap:10px; font-size:1.4rem; font-weight:850; letter-spacing:-1px; }
|
| 31 |
+
.brand-mark { width:39px; height:39px; display:grid; place-items:center; border-radius:13px; color:#fff; background:linear-gradient(145deg,#766dff,#4c43e8); box-shadow:0 8px 20px rgba(99,91,255,.25); }
|
| 32 |
+
.brand-mark svg { width:23px; height:23px; }
|
| 33 |
+
.brand-name span { color:var(--primary); }
|
| 34 |
+
.back-link { color:#65677d; font-weight:650; font-size:.92rem; }
|
| 35 |
+
.back-link:hover { color:var(--primary); }
|
| 36 |
+
main { padding: 42px 0 70px; }
|
| 37 |
+
.intro { text-align:center; max-width:700px; margin:0 auto 28px; }
|
| 38 |
+
.eyebrow { display:inline-flex; gap:8px; align-items:center; padding:7px 12px; border:1px solid #e4e1ff; border-radius:99px; background:rgba(255,255,255,.8); color:#5a52e9; font-size:.82rem; font-weight:750; }
|
| 39 |
+
h1 { margin:18px 0 12px; font-size:clamp(2.4rem,5vw,4rem); line-height:1.06; letter-spacing:-2.7px; }
|
| 40 |
+
h1 span { color:var(--primary); }
|
| 41 |
+
.intro p { margin:0; color:var(--muted); font-size:1.05rem; }
|
| 42 |
+
.workspace { max-width:820px; margin:0 auto; border:1px solid rgba(99,91,255,.14); border-radius:24px; padding:12px; background:rgba(255,255,255,.9); box-shadow:var(--shadow); }
|
| 43 |
+
.dropzone { display:flex; flex-direction:column; align-items:center; justify-content:center; min-height:220px; padding:26px 18px; text-align:center; border:2px dashed #cbc8ff; border-radius:17px; background:linear-gradient(135deg,rgba(238,237,255,.72),rgba(239,253,251,.5)); transition:.2s ease; }
|
| 44 |
+
.dropzone.dragover { border-color:var(--primary); background:#efedff; transform:scale(.995); }
|
| 45 |
+
.upload-icon { width:54px; height:54px; display:grid; place-items:center; margin-bottom:13px; border-radius:17px; color:var(--primary); background:#fff; box-shadow:0 7px 18px rgba(71,64,160,.1); }
|
| 46 |
+
.upload-icon svg { width:28px; height:28px; }
|
| 47 |
+
.dropzone strong { font-size:1.1rem; }
|
| 48 |
+
.dropzone p { margin:5px 0 16px; color:var(--muted); font-size:.9rem; }
|
| 49 |
+
.btn { border:0; display:inline-flex; align-items:center; justify-content:center; gap:9px; padding:12px 18px; border-radius:13px; font-weight:750; transition:.2s ease; }
|
| 50 |
+
.btn-primary { color:#fff; background:var(--primary); box-shadow:0 8px 18px rgba(99,91,255,.22); }
|
| 51 |
+
.btn-primary:hover:not(:disabled) { background:var(--primary-dark); transform:translateY(-1px); }
|
| 52 |
+
.btn-light { color:#4b4d64; background:#fff; border:1px solid var(--line); }
|
| 53 |
+
.btn-light:hover { border-color:#c9c5ff; color:var(--primary); }
|
| 54 |
+
button:disabled { opacity:.5; cursor:not-allowed; box-shadow:none; }
|
| 55 |
+
input[type=file] { display:none; }
|
| 56 |
+
.file-panel { display:none; padding:22px 10px 8px; }
|
| 57 |
+
.file-panel.visible { display:block; }
|
| 58 |
+
.panel-head { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:13px; }
|
| 59 |
+
.panel-head h2 { margin:0; font-size:1.12rem; }
|
| 60 |
+
.count { color:var(--muted); font-size:.86rem; }
|
| 61 |
+
.file-list { display:grid; gap:10px; }
|
| 62 |
+
.file-row { display:grid; grid-template-columns:auto minmax(0,1fr) auto; align-items:center; gap:12px; padding:13px; border:1px solid var(--line); border-radius:14px; background:#fff; }
|
| 63 |
+
.file-icon { width:42px; height:46px; display:grid; place-items:center; border-radius:11px; color:#e6536a; background:#fff0f2; }
|
| 64 |
+
.file-icon svg { width:23px; height:23px; }
|
| 65 |
+
.file-meta { min-width:0; }
|
| 66 |
+
.file-name { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:700; font-size:.92rem; }
|
| 67 |
+
.file-size { color:var(--muted); font-size:.8rem; margin-top:3px; }
|
| 68 |
+
.file-actions { display:flex; align-items:center; gap:5px; }
|
| 69 |
+
.icon-btn { width:34px; height:34px; display:grid; place-items:center; border:1px solid var(--line); border-radius:10px; color:#696b80; background:#fff; }
|
| 70 |
+
.icon-btn:hover:not(:disabled) { color:var(--primary); border-color:#c9c5ff; }
|
| 71 |
+
.icon-btn.remove:hover { color:var(--danger); border-color:#ffc7d1; }
|
| 72 |
+
.icon-btn svg { width:17px; height:17px; }
|
| 73 |
+
.panel-actions { display:flex; justify-content:space-between; align-items:center; gap:12px; flex-wrap:wrap; margin-top:17px; }
|
| 74 |
+
.privacy { display:flex; align-items:center; gap:7px; color:var(--muted); font-size:.82rem; }
|
| 75 |
+
.privacy svg { width:17px; height:17px; color:var(--green); flex-shrink:0; }
|
| 76 |
+
.status { display:none; margin-top:17px; padding:13px 15px; border-radius:12px; font-size:.9rem; }
|
| 77 |
+
.status.show { display:block; }
|
| 78 |
+
.status.info { background:#efedff; color:#4c43c9; }
|
| 79 |
+
.status.success { background:#e6fbf3; color:#087d68; }
|
| 80 |
+
.status.error { background:#fff0f2; color:#b52b49; }
|
| 81 |
+
.tips { display:grid; grid-template-columns:repeat(3,1fr); gap:15px; max-width:820px; margin:24px auto 0; }
|
| 82 |
+
.tip { padding:18px; border:1px solid var(--line); border-radius:17px; background:rgba(255,255,255,.72); }
|
| 83 |
+
.tip b { display:block; margin-bottom:5px; font-size:.92rem; }
|
| 84 |
+
.tip p { margin:0; color:var(--muted); font-size:.84rem; }
|
| 85 |
+
footer { border-top:1px solid var(--line); padding:24px 0; color:var(--muted); font-size:.85rem; }
|
| 86 |
+
.footer-inner { display:flex; justify-content:space-between; align-items:center; gap:14px; flex-wrap:wrap; }
|
| 87 |
+
.toast { position:fixed; left:50%; bottom:22px; transform:translate(-50%,18px); opacity:0; pointer-events:none; padding:12px 17px; border-radius:13px; background:#20213a; color:#fff; box-shadow:var(--shadow); z-index:10; transition:.22s ease; max-width:calc(100% - 28px); text-align:center; font-size:.9rem; }
|
| 88 |
+
.toast.show { opacity:1; transform:translate(-50%,0); }
|
| 89 |
+
@media(max-width:650px) {
|
| 90 |
+
main { padding-top:30px; }
|
| 91 |
+
h1 { letter-spacing:-1.8px; }
|
| 92 |
+
.tips { grid-template-columns:1fr; }
|
| 93 |
+
.file-row { grid-template-columns:auto minmax(0,1fr); }
|
| 94 |
+
.file-actions { grid-column:2; justify-content:flex-start; }
|
| 95 |
+
.panel-head { align-items:flex-start; flex-direction:column; }
|
| 96 |
+
.panel-actions { align-items:stretch; flex-direction:column; }
|
| 97 |
+
.panel-actions .btn { width:100%; }
|
| 98 |
+
}
|
| 99 |
+
</style>
|
| 100 |
+
</head>
|
| 101 |
+
<body>
|
| 102 |
+
<header>
|
| 103 |
+
<div class="container nav">
|
| 104 |
+
<a class="brand" href="index.html" aria-label="PDFix homepage">
|
| 105 |
+
<span class="brand-mark"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M7 3.5h7l4 4V20a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 6 20V5A1.5 1.5 0 0 1 7.5 3.5Z" stroke="currentColor" stroke-width="1.8"/><path d="M14 3.8V8h4M8.5 12h7M8.5 15.5h7" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/></svg></span>
|
| 106 |
+
<span class="brand-name">PDF<span>ix</span></span>
|
| 107 |
+
</a>
|
| 108 |
+
<a class="back-link" href="index.html">← Back to all tools</a>
|
| 109 |
+
</div>
|
| 110 |
+
</header>
|
| 111 |
+
|
| 112 |
+
<main>
|
| 113 |
+
<div class="container">
|
| 114 |
+
<div class="intro">
|
| 115 |
+
<div class="eyebrow">✦ PDFix PDF tools</div>
|
| 116 |
+
<h1>Merge <span>PDF files</span></h1>
|
| 117 |
+
<p>Bring multiple documents together into one PDF. Add your files, arrange their order, and download the merged result.</p>
|
| 118 |
+
</div>
|
| 119 |
+
|
| 120 |
+
<div class="workspace">
|
| 121 |
+
<div class="dropzone" id="dropzone" tabindex="0" role="button" aria-label="Choose or drop PDF files">
|
| 122 |
+
<div class="upload-icon"><svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M12 16V4m0 0L7.5 8.5M12 4l4.5 4.5M5 14.5v4A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5v-4" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg></div>
|
| 123 |
+
<strong>Drop PDF files here</strong>
|
| 124 |
+
<p>Choose two or more PDFs to combine them into one file.</p>
|
| 125 |
+
<button type="button" class="btn btn-primary" id="chooseFiles">Select PDF files <span aria-hidden="true">↑</span></button>
|
| 126 |
+
<input id="fileInput" type="file" accept=".pdf,application/pdf" multiple />
|
| 127 |
+
</div>
|
| 128 |
+
|
| 129 |
+
<div class="file-panel" id="filePanel">
|
| 130 |
+
<div class="panel-head">
|
| 131 |
+
<div><h2>Your PDF files</h2><div class="count" id="fileCount">0 files selected</div></div>
|
| 132 |
+
<button type="button" class="btn btn-light" id="addMore">+ Add more files</button>
|
| 133 |
+
</div>
|
| 134 |
+
<div class="file-list" id="fileList"></div>
|
| 135 |
+
<div class="panel-actions">
|
| 136 |
+
<div class="privacy"><svg viewBox="0 0 24 24" fill="none"><path d="M12 3 19 6v5c0 4.5-2.9 7.7-7 10-4.1-2.3-7-5.5-7-10V6l7-3Z" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round"/><path d="m9 12 2 2 4-4" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg> Files are processed in your browser.</div>
|
| 137 |
+
<button type="button" class="btn btn-primary" id="mergeBtn" disabled>Merge PDFs <span aria-hidden="true">→</span></button>
|
| 138 |
+
</div>
|
| 139 |
+
<div class="status" id="status" role="status" aria-live="polite"></div>
|
| 140 |
+
</div>
|
| 141 |
+
</div>
|
| 142 |
+
|
| 143 |
+
<div class="tips">
|
| 144 |
+
<article class="tip"><b>① Add your files</b><p>Select at least two PDF documents or drag them into the upload area.</p></article>
|
| 145 |
+
<article class="tip"><b>② Arrange the order</b><p>Use the arrows beside each file to choose the order of pages in the final PDF.</p></article>
|
| 146 |
+
<article class="tip"><b>③ Merge and download</b><p>PDFix combines your files locally, then saves the new PDF to your device.</p></article>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
</main>
|
| 150 |
+
|
| 151 |
+
<footer><div class="container footer-inner"><a class="brand" href="index.html"><span class="brand-name">PDF<span>ix</span></span></a><span>© <span id="year"></span> PDFix · Your documents, made simple.</span></div></footer>
|
| 152 |
+
<div class="toast" id="toast" role="status" aria-live="polite"></div>
|
| 153 |
+
|
| 154 |
+
<!-- pdf-lib runs in the browser; no PDF files are sent to a server. -->
|
| 155 |
+
<script src="https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js"></script>
|
| 156 |
+
<script>
|
| 157 |
+
const fileInput = document.getElementById('fileInput');
|
| 158 |
+
const dropzone = document.getElementById('dropzone');
|
| 159 |
+
const filePanel = document.getElementById('filePanel');
|
| 160 |
+
const fileList = document.getElementById('fileList');
|
| 161 |
+
const fileCount = document.getElementById('fileCount');
|
| 162 |
+
const mergeBtn = document.getElementById('mergeBtn');
|
| 163 |
+
const statusBox = document.getElementById('status');
|
| 164 |
+
const toast = document.getElementById('toast');
|
| 165 |
+
let selectedFiles = [];
|
| 166 |
+
let toastTimer;
|
| 167 |
+
|
| 168 |
+
document.getElementById('year').textContent = new Date().getFullYear();
|
| 169 |
+
|
| 170 |
+
function showToast(message) {
|
| 171 |
+
toast.textContent = message;
|
| 172 |
+
toast.classList.add('show');
|
| 173 |
+
clearTimeout(toastTimer);
|
| 174 |
+
toastTimer = setTimeout(() => toast.classList.remove('show'), 3000);
|
| 175 |
+
}
|
| 176 |
+
function setStatus(message, type = 'info') {
|
| 177 |
+
statusBox.textContent = message;
|
| 178 |
+
statusBox.className = `status show ${type}`;
|
| 179 |
+
}
|
| 180 |
+
function clearStatus() {
|
| 181 |
+
statusBox.textContent = '';
|
| 182 |
+
statusBox.className = 'status';
|
| 183 |
+
}
|
| 184 |
+
function formatSize(bytes) {
|
| 185 |
+
if (bytes < 1024 * 1024) return `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
| 186 |
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
| 187 |
+
}
|
| 188 |
+
function pdfIcon() {
|
| 189 |
+
return '<svg viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M6.5 3.5h8l4 4V20a1.5 1.5 0 0 1-1.5 1.5h-10A1.5 1.5 0 0 1 5.5 20V5A1.5 1.5 0 0 1 7 3.5Z" stroke="currentColor" stroke-width="1.7"/><path d="M14.5 3.8V8h4M8 12h8M8 15h6" stroke="currentColor" stroke-width="1.7" stroke-linecap="round"/></svg>';
|
| 190 |
+
}
|
| 191 |
+
function addFiles(fileCollection) {
|
| 192 |
+
const incoming = Array.from(fileCollection || []);
|
| 193 |
+
if (!incoming.length) return;
|
| 194 |
+
const invalid = incoming.filter(file => !file.name.toLowerCase().endsWith('.pdf') && file.type !== 'application/pdf');
|
| 195 |
+
if (invalid.length) {
|
| 196 |
+
showToast('Please select PDF files only. Non-PDF files were skipped.');
|
| 197 |
+
}
|
| 198 |
+
const valid = incoming.filter(file => file.name.toLowerCase().endsWith('.pdf') || file.type === 'application/pdf');
|
| 199 |
+
valid.forEach(file => {
|
| 200 |
+
const duplicate = selectedFiles.some(existing => existing.name === file.name && existing.size === file.size && existing.lastModified === file.lastModified);
|
| 201 |
+
if (!duplicate) selectedFiles.push(file);
|
| 202 |
+
});
|
| 203 |
+
renderFiles();
|
| 204 |
+
fileInput.value = '';
|
| 205 |
+
if (valid.length) clearStatus();
|
| 206 |
+
}
|
| 207 |
+
function renderFiles() {
|
| 208 |
+
fileList.innerHTML = '';
|
| 209 |
+
filePanel.classList.toggle('visible', selectedFiles.length > 0);
|
| 210 |
+
fileCount.textContent = `${selectedFiles.length} ${selectedFiles.length === 1 ? 'file' : 'files'} selected`;
|
| 211 |
+
mergeBtn.disabled = selectedFiles.length < 2;
|
| 212 |
+
selectedFiles.forEach((file, index) => {
|
| 213 |
+
const row = document.createElement('div');
|
| 214 |
+
row.className = 'file-row';
|
| 215 |
+
const icon = document.createElement('div');
|
| 216 |
+
icon.className = 'file-icon';
|
| 217 |
+
icon.innerHTML = pdfIcon();
|
| 218 |
+
const meta = document.createElement('div');
|
| 219 |
+
meta.className = 'file-meta';
|
| 220 |
+
const name = document.createElement('div');
|
| 221 |
+
name.className = 'file-name';
|
| 222 |
+
name.textContent = file.name;
|
| 223 |
+
name.title = file.name;
|
| 224 |
+
const size = document.createElement('div');
|
| 225 |
+
size.className = 'file-size';
|
| 226 |
+
size.textContent = formatSize(file.size);
|
| 227 |
+
meta.append(name, size);
|
| 228 |
+
|
| 229 |
+
const actions = document.createElement('div');
|
| 230 |
+
actions.className = 'file-actions';
|
| 231 |
+
actions.append(
|
| 232 |
+
makeIconButton('↑', 'Move file up', index === 0, () => moveFile(index, -1)),
|
| 233 |
+
makeIconButton('↓', 'Move file down', index === selectedFiles.length - 1, () => moveFile(index, 1)),
|
| 234 |
+
makeIconButton('×', 'Remove file', false, () => removeFile(index), true)
|
| 235 |
+
);
|
| 236 |
+
row.append(icon, meta, actions);
|
| 237 |
+
fileList.append(row);
|
| 238 |
+
});
|
| 239 |
+
}
|
| 240 |
+
function makeIconButton(label, ariaLabel, disabled, action, isRemove = false) {
|
| 241 |
+
const button = document.createElement('button');
|
| 242 |
+
button.type = 'button';
|
| 243 |
+
button.className = `icon-btn${isRemove ? ' remove' : ''}`;
|
| 244 |
+
button.textContent = label;
|
| 245 |
+
button.setAttribute('aria-label', ariaLabel);
|
| 246 |
+
button.title = ariaLabel;
|
| 247 |
+
button.disabled = disabled;
|
| 248 |
+
button.addEventListener('click', action);
|
| 249 |
+
return button;
|
| 250 |
+
}
|
| 251 |
+
function moveFile(index, direction) {
|
| 252 |
+
const target = index + direction;
|
| 253 |
+
if (target < 0 || target >= selectedFiles.length) return;
|
| 254 |
+
[selectedFiles[index], selectedFiles[target]] = [selectedFiles[target], selectedFiles[index]];
|
| 255 |
+
renderFiles();
|
| 256 |
+
clearStatus();
|
| 257 |
+
}
|
| 258 |
+
function removeFile(index) {
|
| 259 |
+
selectedFiles.splice(index, 1);
|
| 260 |
+
renderFiles();
|
| 261 |
+
clearStatus();
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
document.getElementById('chooseFiles').addEventListener('click', event => {
|
| 265 |
+
event.stopPropagation();
|
| 266 |
+
fileInput.click();
|
| 267 |
+
});
|
| 268 |
+
document.getElementById('addMore').addEventListener('click', () => fileInput.click());
|
| 269 |
+
dropzone.addEventListener('click', event => {
|
| 270 |
+
if (event.target.closest('button')) return;
|
| 271 |
+
fileInput.click();
|
| 272 |
+
});
|
| 273 |
+
dropzone.addEventListener('keydown', event => {
|
| 274 |
+
if (event.key === 'Enter' || event.key === ' ') {
|
| 275 |
+
event.preventDefault();
|
| 276 |
+
fileInput.click();
|
| 277 |
+
}
|
| 278 |
+
});
|
| 279 |
+
fileInput.addEventListener('change', () => addFiles(fileInput.files));
|
| 280 |
+
['dragenter', 'dragover'].forEach(type => dropzone.addEventListener(type, event => {
|
| 281 |
+
event.preventDefault();
|
| 282 |
+
dropzone.classList.add('dragover');
|
| 283 |
+
}));
|
| 284 |
+
['dragleave', 'drop'].forEach(type => dropzone.addEventListener(type, event => {
|
| 285 |
+
event.preventDefault();
|
| 286 |
+
dropzone.classList.remove('dragover');
|
| 287 |
+
}));
|
| 288 |
+
dropzone.addEventListener('drop', event => addFiles(event.dataTransfer.files));
|
| 289 |
+
|
| 290 |
+
mergeBtn.addEventListener('click', async () => {
|
| 291 |
+
if (selectedFiles.length < 2) {
|
| 292 |
+
setStatus('Please add at least two PDF files to merge.', 'error');
|
| 293 |
+
return;
|
| 294 |
+
}
|
| 295 |
+
if (!window.PDFLib) {
|
| 296 |
+
setStatus('The PDF library could not load. Check your internet connection and reload this page.', 'error');
|
| 297 |
+
return;
|
| 298 |
+
}
|
| 299 |
+
const originalLabel = mergeBtn.innerHTML;
|
| 300 |
+
mergeBtn.disabled = true;
|
| 301 |
+
mergeBtn.textContent = 'Merging PDFs…';
|
| 302 |
+
setStatus('Merging your files. Please keep this tab open.', 'info');
|
| 303 |
+
try {
|
| 304 |
+
const { PDFDocument } = window.PDFLib;
|
| 305 |
+
const mergedPdf = await PDFDocument.create();
|
| 306 |
+
for (let i = 0; i < selectedFiles.length; i++) {
|
| 307 |
+
const file = selectedFiles[i];
|
| 308 |
+
setStatus(`Reading file ${i + 1} of ${selectedFiles.length}: ${file.name}`, 'info');
|
| 309 |
+
const bytes = await file.arrayBuffer();
|
| 310 |
+
const sourcePdf = await PDFDocument.load(bytes);
|
| 311 |
+
const copiedPages = await mergedPdf.copyPages(sourcePdf, sourcePdf.getPageIndices());
|
| 312 |
+
copiedPages.forEach(page => mergedPdf.addPage(page));
|
| 313 |
+
}
|
| 314 |
+
const outputBytes = await mergedPdf.save();
|
| 315 |
+
const blob = new Blob([outputBytes], { type: 'application/pdf' });
|
| 316 |
+
const url = URL.createObjectURL(blob);
|
| 317 |
+
const link = document.createElement('a');
|
| 318 |
+
link.href = url;
|
| 319 |
+
link.download = 'pdfix-merged.pdf';
|
| 320 |
+
document.body.appendChild(link);
|
| 321 |
+
link.click();
|
| 322 |
+
link.remove();
|
| 323 |
+
setTimeout(() => URL.revokeObjectURL(url), 1500);
|
| 324 |
+
setStatus('Success! Your merged PDF has been downloaded as pdfix-merged.pdf.', 'success');
|
| 325 |
+
} catch (error) {
|
| 326 |
+
console.error(error);
|
| 327 |
+
setStatus('We could not merge one of these files. It may be damaged, password-protected, or use an unsupported PDF feature. Please check the files and try again.', 'error');
|
| 328 |
+
} finally {
|
| 329 |
+
mergeBtn.disabled = selectedFiles.length < 2;
|
| 330 |
+
mergeBtn.innerHTML = originalLabel;
|
| 331 |
+
}
|
| 332 |
+
});
|
| 333 |
+
</script>
|
| 334 |
+
</body>
|
| 335 |
+
</html>
|