2023-05-04 23:19:05 +01:00
|
|
|
<!DOCTYPE html>
|
2024-03-21 21:58:01 +01:00
|
|
|
<html th:lang="${#locale.language}" th:dir="#{language.direction}" th:data-language="${#locale.toString()}" xmlns:th="http://www.thymeleaf.org">
|
2024-02-16 22:49:06 +01:00
|
|
|
<head>
|
|
|
|
<th:block th:insert="~{fragments/common :: head(title=#{flatten.title}, header=#{flatten.header})}"></th:block>
|
|
|
|
</head>
|
2023-05-04 23:19:05 +01:00
|
|
|
|
2024-02-16 22:49:06 +01:00
|
|
|
<body>
|
|
|
|
<div id="page-container">
|
|
|
|
<div id="content-wrap">
|
|
|
|
<th:block th:insert="~{fragments/navbar.html :: navbar}"></th:block>
|
2024-03-21 21:58:01 +01:00
|
|
|
<br><br>
|
2024-02-16 22:49:06 +01:00
|
|
|
<div class="container">
|
|
|
|
<div class="row justify-content-center">
|
2024-05-05 15:19:53 +04:00
|
|
|
<div class="col-md-6" id="bg-card">
|
|
|
|
<div class="tool-header">
|
|
|
|
<span class="material-symbols-rounded tool-header-icon other">layers_clear</span>
|
|
|
|
<span class="tool-header-text" th:text="#{flatten.header}"></span>
|
|
|
|
</div>
|
2024-02-16 22:49:06 +01:00
|
|
|
<form id="pdfForm" class="mb-3">
|
|
|
|
<div class="custom-file">
|
|
|
|
<div th:replace="~{fragments/common :: fileSelector(name='fileInput', multiple=false, accept='application/pdf', remoteCall='false')}"></div>
|
|
|
|
</div>
|
|
|
|
<button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{flatten.submit}"></button>
|
|
|
|
<script src="js/local-pdf-input-download.js"></script>
|
|
|
|
<script>
|
|
|
|
document.getElementById('pdfForm').addEventListener('submit', async (e) => {
|
2024-02-18 08:40:30 +01:00
|
|
|
e.preventDefault();
|
2023-05-04 23:19:05 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
const { PDFDocument } = PDFLib;
|
2023-05-04 23:19:05 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
const processFile = async (file) => {
|
|
|
|
const origFileUrl = URL.createObjectURL(file);
|
|
|
|
const formPdfBytes = await fetch(origFileUrl).then(res => res.arrayBuffer());
|
|
|
|
const pdfDoc = await PDFDocument.load(formPdfBytes, { ignoreEncryption: true });
|
2023-05-04 23:19:05 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
const form = pdfDoc.getForm();
|
|
|
|
form.flatten();
|
2024-02-16 22:49:06 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
const pdfBytes = await pdfDoc.save();
|
|
|
|
const pdfBlob = new Blob([pdfBytes], { type: 'application/pdf' });
|
|
|
|
const fileName = (file.name ? file.name.replace('.pdf', '') : 'pdf') + '_flattened.pdf';
|
2024-02-16 22:49:06 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
return { processedData: pdfBlob, fileName };
|
|
|
|
};
|
2024-02-16 22:49:06 +01:00
|
|
|
|
2024-02-18 08:40:30 +01:00
|
|
|
await downloadFilesWithCallback(processFile);
|
2024-02-16 22:49:06 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</form>
|
2023-05-04 23:19:05 +01:00
|
|
|
</div>
|
2024-02-16 22:49:06 +01:00
|
|
|
</div>
|
2023-05-04 23:19:05 +01:00
|
|
|
</div>
|
2024-02-16 22:49:06 +01:00
|
|
|
</div>
|
|
|
|
<th:block th:insert="~{fragments/footer.html :: footer}"></th:block>
|
2023-05-04 23:19:05 +01:00
|
|
|
</div>
|
2024-02-16 22:49:06 +01:00
|
|
|
</body>
|
2023-05-04 23:19:05 +01:00
|
|
|
</html>
|