pdf-web-toolkit/templates/index.html

46 lines
1.3 KiB
HTML
Raw Normal View History

2023-10-11 17:51:35 +00:00
<!DOCTYPE html>
<html>
<head>
<title>PDF Splitter</title>
<link rel="shortcut icon" href="/static/icons/filetype-pdf.svg" type="image/x-icon">
</head>
<body>
<h1>PDF Splitter</h1>
<input type="file" id="pdfFile" accept=".pdf"><br>
<button onclick="uploadPDF()">Split PDF into individual pages</button>
<div id="output"></div>
<script>
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
function uploadPDF() {
const fileInput = document.getElementById('pdfFile');
const file = fileInput.files[0];
const formData = new FormData();
formData.append('pdf', file);
const backendURL = '/split';
fetch(backendURL, {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
console.debug("data from Backend: ", data)
downloadURI(data["url"], data["name"]);
})
.catch(error => console.error(error));
}
</script>
</body>
</html>