2023-01-29 18:06:53 +01:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
|
|
|
|
|
|
|
|
2023-02-05 13:54:48 +01:00
|
|
|
<th:block th:insert="~{fragments/common :: head(title=#{rotate.title})}"></th:block>
|
2023-02-03 21:26:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
<body> <div id="page-container">
|
|
|
|
<div id="content-wrap">
|
|
|
|
<div th:insert="~{fragments/navbar.html :: navbar}"></div>
|
2023-01-29 18:06:53 +01:00
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<div class="container">
|
|
|
|
<div class="row justify-content-center">
|
|
|
|
<div class="col-md-6">
|
2023-02-05 13:54:48 +01:00
|
|
|
<h2 th:text="#{rotate.header}"></h2>
|
2023-01-29 18:06:53 +01:00
|
|
|
|
2023-02-05 00:45:33 +01:00
|
|
|
<form action="#" th:action="@{rotate-pdf}" th:object="${rotateForm}" method="post" enctype="multipart/form-data">
|
|
|
|
<div th:replace="fragments/common :: fileSelector(name='fileInput', multiple=false)"></div>
|
|
|
|
<input type="hidden" id="angleInput" name="angle" value="0">
|
2023-01-29 18:06:53 +01:00
|
|
|
|
2023-02-05 20:04:37 +01:00
|
|
|
<div id="editSection" style="display: none">
|
|
|
|
<div class="previewContainer">
|
|
|
|
<img id="pdf-preview"/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="buttonContainer">
|
|
|
|
<button type="button" class="btn btn-secondary" onclick="rotate(-90)">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-counterclockwise" viewBox="0 0 16 16">
|
|
|
|
<path fill-rule="evenodd" d="M8 3a5 5 0 1 1-4.546 2.914.5.5 0 0 0-.908-.417A6 6 0 1 0 8 2v1z"/>
|
|
|
|
<path d="M8 4.466V.534a.25.25 0 0 0-.41-.192L5.23 2.308a.25.25 0 0 0 0 .384l2.36 1.966A.25.25 0 0 0 8 4.466z"/>
|
|
|
|
</svg>
|
|
|
|
</button>
|
2023-02-05 22:20:25 +01:00
|
|
|
<button type="submit" class="btn btn-primary" th:text="#{rotate.submit}"></button>
|
2023-02-05 20:04:37 +01:00
|
|
|
<button type="button" class="btn btn-secondary" onclick="rotate(90)">
|
|
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-clockwise" viewBox="0 0 16 16">
|
|
|
|
<path fill-rule="evenodd" d="M8 3a5 5 0 1 0 4.546 2.914.5.5 0 0 1 .908-.417A6 6 0 1 1 8 2v1z"/>
|
|
|
|
<path d="M8 4.466V.534a.25.25 0 0 1 .41-.192l2.36 1.966c.12.1.12.284 0 .384L8.41 4.658A.25.25 0 0 1 8 4.466z"/>
|
|
|
|
</svg>
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-02-05 00:45:33 +01:00
|
|
|
</div>
|
2023-01-29 18:06:53 +01:00
|
|
|
</form>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-03 21:26:35 +01:00
|
|
|
</div>
|
|
|
|
<div th:insert="~{fragments/footer.html :: footer}"></div>
|
|
|
|
</div>
|
2023-02-05 00:45:33 +01:00
|
|
|
|
|
|
|
<script>
|
|
|
|
const angleInput = document.getElementById("angleInput");
|
|
|
|
const fileInput = document.getElementById("fileInput-input");
|
|
|
|
const preview = document.getElementById("pdf-preview");
|
|
|
|
fileInput.addEventListener("change", async function() {
|
|
|
|
console.log("loading pdf");
|
|
|
|
|
2023-02-05 20:04:37 +01:00
|
|
|
document.querySelector("#editSection").style.display = "";
|
2023-02-05 00:45:33 +01:00
|
|
|
|
2023-02-05 20:04:37 +01:00
|
|
|
var url = URL.createObjectURL(fileInput.files[0])
|
2023-02-05 00:45:33 +01:00
|
|
|
|
2023-02-05 20:04:37 +01:00
|
|
|
const pdf = await pdfjsLib.getDocument(url).promise;
|
2023-02-05 00:45:33 +01:00
|
|
|
const page = await pdf.getPage(1);
|
|
|
|
|
|
|
|
const canvas = document.createElement("canvas");
|
|
|
|
|
|
|
|
// set the canvas size to the size of the page
|
2023-02-05 16:08:43 +01:00
|
|
|
if (page.rotate == 90 || page.rotate == 270) {
|
|
|
|
canvas.width = page.view[3];
|
|
|
|
canvas.height = page.view[2];
|
|
|
|
} else {
|
|
|
|
canvas.width = page.view[2];
|
|
|
|
canvas.height = page.view[3];
|
|
|
|
}
|
2023-02-05 00:45:33 +01:00
|
|
|
|
|
|
|
// render the page onto the canvas
|
|
|
|
var renderContext = {
|
2023-02-05 20:04:37 +01:00
|
|
|
canvasContext: canvas.getContext("2d"),
|
|
|
|
viewport: page.getViewport({ scale: 1 })
|
2023-02-05 00:45:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
await page.render(renderContext).promise;
|
|
|
|
preview.src = canvas.toDataURL();
|
|
|
|
});
|
|
|
|
|
|
|
|
function rotate(deg) {
|
2023-02-05 16:08:43 +01:00
|
|
|
var lastTransform = preview.style.rotate;
|
2023-02-05 00:45:33 +01:00
|
|
|
if (!lastTransform) {
|
|
|
|
lastTransform = "0";
|
|
|
|
}
|
|
|
|
const lastAngle = parseInt(lastTransform.replace(/[^\d-]/g, ''));
|
|
|
|
const newAngle = lastAngle + deg;
|
|
|
|
|
2023-02-05 16:08:43 +01:00
|
|
|
preview.style.rotate = newAngle + "deg";
|
2023-02-05 00:45:33 +01:00
|
|
|
angleInput.value = newAngle;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style>
|
|
|
|
#pdf-preview {
|
|
|
|
margin: 0 auto;
|
|
|
|
display: block;
|
2023-02-05 16:08:43 +01:00
|
|
|
max-width: calc(100% - 30px);
|
|
|
|
max-height: calc(100% - 30px);
|
2023-02-05 00:45:33 +01:00
|
|
|
box-shadow: 0 0 4px rgba(100,100,100,.25);
|
2023-02-05 16:08:43 +01:00
|
|
|
transition: rotate .3s;
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
translate: -50% -50%;
|
2023-02-05 00:45:33 +01:00
|
|
|
}
|
|
|
|
.previewContainer {
|
|
|
|
aspect-ratio: 1;
|
|
|
|
width: 100%;
|
|
|
|
border: 1px solid rgba(0,0,0,.125);
|
|
|
|
border-radius: 0.25rem;
|
2023-02-05 20:04:37 +01:00
|
|
|
margin: 1rem 0;
|
2023-02-05 00:45:33 +01:00
|
|
|
padding: 15px;
|
2023-02-05 20:04:37 +01:00
|
|
|
display: block;
|
2023-02-05 00:45:33 +01:00
|
|
|
overflow: hidden;
|
2023-02-05 16:08:43 +01:00
|
|
|
position: relative;
|
2023-02-05 00:45:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.buttonContainer {
|
2023-02-05 20:04:37 +01:00
|
|
|
display: flex;
|
2023-02-05 00:45:33 +01:00
|
|
|
justify-content: space-around;
|
|
|
|
}
|
|
|
|
</style>
|
2023-01-29 18:06:53 +01:00
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|