forked from Stirling-Tools/Stirling-PDF
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Stirling-Tools#548 from sbplat/main
Add remove annotations
- Loading branch information
Showing
8 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html th:lang="${#locale.toString()}" th:lang-direction="#{language.direction}" xmlns:th="http://www.thymeleaf.org"> | ||
<th:block th:insert="~{fragments/common :: head(title=#{removeAnnotations.title})}"></th:block> | ||
|
||
<body> | ||
<div id="page-container"> | ||
<div id="content-wrap"> | ||
<div th:insert="~{fragments/navbar.html :: navbar}"></div> | ||
<br> <br> | ||
<div class="container"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-6"> | ||
<h2 th:text="#{removeAnnotations.header}"></h2> | ||
<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="#{removeAnnotations.submit}"></button> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div th:insert="~{fragments/footer.html :: footer}"></div> | ||
</div> | ||
<script src="js/local-pdf-input-download.js"></script> | ||
<script> | ||
document.getElementById('pdfForm').addEventListener('submit', async (e) => { | ||
e.preventDefault(); | ||
|
||
const { PDFDocument } = PDFLib; | ||
|
||
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 }); | ||
|
||
const pages = pdfDoc.getPages(); | ||
|
||
for (let i = 0; i < pages.length; ++i) { | ||
const page = pages[i]; | ||
const annotations = page.node.Annots(); | ||
if (!annotations) continue; | ||
const ctx = annotations.context; | ||
|
||
for (let j = 0; j < annotations.size(); ++j) { | ||
const annotation = annotations.get(j); | ||
ctx.delete(annotation); | ||
} | ||
} | ||
|
||
const pdfBytes = await pdfDoc.save(); | ||
const pdfBlob = new Blob([pdfBytes], { type: 'application/pdf' }); | ||
const fileName = (file.name ? file.name.replace('.pdf', '') : 'pdf') + '_removed_annotations.pdf'; | ||
|
||
return { processedData: pdfBlob, fileName }; | ||
}; | ||
|
||
await downloadFilesWithCallback(processFile); | ||
}); | ||
</script> | ||
</body> | ||
|
||
</html> |