documentation stuff and downloer fix for image to pdf

This commit is contained in:
Anthony Stirling 2023-06-10 00:46:44 +01:00
parent 489b8da713
commit 67448498ea
6 changed files with 117 additions and 51 deletions

View file

@ -8,7 +8,7 @@ COPY build/libs/*.jar app.jar
EXPOSE 8080 EXPOSE 8080
# Set environment variables # Set environment variables
ENV GROUPS_TO_REMOVE=LibreOffice,CLI ENV GROUPS_TO_REMOVE=CLI
# Run the application # Run the application
CMD ["java", "-jar", "/app.jar"] CMD ["java", "-jar", "/app.jar"]

35
Endpoint-groups.md Normal file
View file

@ -0,0 +1,35 @@
| Operation | PageOps | Convert | Security | Other | CLI | Python | OpenCV | LibreOffice | OCRmyPDF | Java | Javascript |
|---------------------|---------|---------|----------|-------|------|--------|--------|-------------|----------|----------|------------|
| merge-pdfs | ✔️ | | | | | | | | | ✔️ | |
| multi-page-layout | ✔️ | | | | | | | | | ✔️ | |
| pdf-organizer | ✔️ | | | | | | | | | ✔️ | ✔️ |
| remove-pages | ✔️ | | | | | | | | | ✔️ | |
| rotate-pdf | ✔️ | | | | | | | | | ✔️ | |
| scale-pages | ✔️ | | | | | | | | | ✔️ | |
| split-pdfs | ✔️ | | | | | | | | | ✔️ | |
| file-to-pdf | | ✔️ | | | ✔️ | | | ✔️ | | | |
| img-to-pdf | | ✔️ | | | | | | | | ✔️ | |
| pdf-to-html | | ✔️ | | | ✔️ | | | ✔️ | | | |
| pdf-to-img | | ✔️ | | | | | | | | ✔️ | |
| pdf-to-pdfa | | ✔️ | | | ✔️ | | | | ✔️ | | |
| pdf-to-presentation | | ✔️ | | | ✔️ | | | ✔️ | | | |
| pdf-to-text | | ✔️ | | | ✔️ | | | ✔️ | | | |
| pdf-to-word | | ✔️ | | | ✔️ | | | ✔️ | | | |
| pdf-to-xml | | ✔️ | | | ✔️ | | | ✔️ | | | |
| xlsx-to-pdf | | ✔️ | | | ✔️ | | | ✔️ | | | |
| add-password | | | ✔️ | | | | | | | ✔️ | |
| add-watermark | | | ✔️ | | | | | | | ✔️ | |
| cert-sign | | | ✔️ | | | | | | | ✔️ | |
| change-permissions | | | ✔️ | | | | | | | ✔️ | |
| remove-password | | | ✔️ | | | | | | | ✔️ | |
| add-image | | | | ✔️ | | | | | | ✔️ | |
| change-metadata | | | | ✔️ | | | | | | ✔️ | |
| compare | | | | ✔️ | | | | | | | ✔️ |
| compress-pdf | | | | ✔️ | ✔️ | | | | ✔️ | | |
| extract-image-scans | | | | ✔️ | ✔️ | ✔️ | ✔️ | | | | |
| extract-images | | | | ✔️ | | | | | | ✔️ | |
| flatten | | | | ✔️ | | | | | | | |
| ocr-pdf | | | | ✔️ | ✔️ | | | | ✔️ | | |
| remove-blanks | | | | ✔️ | ✔️ | ✔️ | ✔️ | | | | |
| repair | | | | ✔️ | ✔️ | | | ✔️ | | | |
| sign | | | | ✔️ | | | | | | | ✔️ |

View file

@ -53,6 +53,7 @@ Hosted instance/demo of the app can be seen [here](https://pdf.adminforge.de/) h
## Technologies used ## Technologies used
- Spring Boot + Thymeleaf - Spring Boot + Thymeleaf
- PDFBox - PDFBox
- IText7
- [LibreOffice](https://www.libreoffice.org/discover/libreoffice/) for advanced conversions - [LibreOffice](https://www.libreoffice.org/discover/libreoffice/) for advanced conversions
- [OcrMyPdf](https://github.com/ocrmypdf/OCRmyPDF) - [OcrMyPdf](https://github.com/ocrmypdf/OCRmyPDF)
- HTML, CSS, JavaScript - HTML, CSS, JavaScript
@ -68,13 +69,20 @@ Please view https://github.com/Frooodle/Stirling-PDF/blob/main/LocalRunGuide.md
### Docker ### Docker
https://hub.docker.com/r/frooodle/s-pdf https://hub.docker.com/r/frooodle/s-pdf
Stirling PDF has 3 different versions, a Full version, Lite and ultra-Lite. Depending on the types of features you use you may want a smaller image to save on space.
To see what the different versions offer please look at our [version mapping](https://github.com/Frooodle/Stirling-PDF/blob/main/Version-groups.md)
For people that dont mind about space optimisation just use latest tag.
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/frooodle/s-pdf/latest?label=Stirling-PDF%20Full)
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/frooodle/s-pdf/latest-lite?label=Stirling-PDF%20Lite)
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/frooodle/s-pdf/latest-ultra-lite?label=Stirling-PDF%20Ultra-Lite)
Docker Run Docker Run
``` ```
docker run -d \ docker run -d \
-p 8080:8080 \ -p 8080:8080 \
-v /location/of/trainingData:/usr/share/tesseract-ocr/4.00/tessdata \ -v /location/of/trainingData:/usr/share/tesseract-ocr/4.00/tessdata \
--name stirling-pdf \ --name stirling-pdf \
frooodle/s-pdf frooodle/s-pdf:latest
Can also add these for customisation but are not required Can also add these for customisation but are not required
@ -90,7 +98,7 @@ Docker Compose
version: '3.3' version: '3.3'
services: services:
stirling-pdf: stirling-pdf:
image: frooodle/s-pdf image: frooodle/s-pdf:latest
ports: ports:
- '8080:8080' - '8080:8080'
volumes: volumes:

48
Version-groups.md Normal file
View file

@ -0,0 +1,48 @@
|Technology | Ultra-Lite | Lite | Full |
|----------------|:----------:|:----:|:----:|
| Java | ✔️ | ✔️ | ✔️ |
| JavaScript | ✔️ | ✔️ | ✔️ |
| Libre | | ✔️ | ✔️ |
| Python | | | ✔️ |
| OpenCV | | | ✔️ |
| OCRmyPDF | | | ✔️ |
Operation | Ultra-Lite | Lite | Full
--------------------|------------|------|-----
add-password | ✔️ | ✔️ | ✔️
add-watermark | ✔️ | ✔️ | ✔️
cert-sign | ✔️ | ✔️ | ✔️
change-metadata | ✔️ | ✔️ | ✔️
change-permissions | ✔️ | ✔️ | ✔️
compare | ✔️ | ✔️ | ✔️
extract-images | ✔️ | ✔️ | ✔️
flatten | ✔️ | ✔️ | ✔️
img-to-pdf | ✔️ | ✔️ | ✔️
merge-pdfs | ✔️ | ✔️ | ✔️
multi-page-layout | ✔️ | ✔️ | ✔️
pdf-organizer | ✔️ | ✔️ | ✔️
pdf-to-img | ✔️ | ✔️ | ✔️
remove-pages | ✔️ | ✔️ | ✔️
remove-password | ✔️ | ✔️ | ✔️
rotate-pdf | ✔️ | ✔️ | ✔️
scale-pages | ✔️ | ✔️ | ✔️
sign | ✔️ | ✔️ | ✔️
split-pdfs | ✔️ | ✔️ | ✔️
add-image | ✔️ | ✔️ | ✔️
file-to-pdf | | ✔️ | ✔️
pdf-to-html | | ✔️ | ✔️
pdf-to-presentation | | ✔️ | ✔️
pdf-to-text | | ✔️ | ✔️
pdf-to-word | | ✔️ | ✔️
pdf-to-xml | | ✔️ | ✔️
repair | | ✔️ | ✔️
xlsx-to-pdf | | ✔️ | ✔️
compress-pdf | | | ✔️
extract-image-scans | | | ✔️
ocr-pdf | | | ✔️
pdf-to-pdfa | | | ✔️
remove-blanks | | | ✔️

View file

@ -1,38 +0,0 @@
Operation | PageOps | Convert | Security | Other | CLI | Python | OpenCV | LibreOffice | OCRmyPDF | Java | Javascript
--------------------|---------|---------|----------|-------|------|--------|--------|-------------|--------- |-------- |-----------
remove-pages | X | | | | | | | | | X |
merge-pdfs | X | | | | | | | | | X |
split-pdfs | X | | | | | | | | | X |
pdf-organizer | X | | | | | | | | | X | X
rotate-pdf | X | | | | | | | | | X |
multi-page-layout | X | | | | | | | | | X |
scale-pages | X | | | | | | | | | X |
pdf-to-img | | X | | | | | | | | X |
img-to-pdf | | X | | | | | | | | X |
pdf-to-pdfa | | X | | | X | | | | X | |
file-to-pdf | | X | | | X | | | X | | |
xlsx-to-pdf | | X | | | X | | | X | | |
pdf-to-word | | X | | | X | | | X | | |
pdf-to-presentation | | X | | | X | | | X | | |
pdf-to-text | | X | | | X | | | X | | |
pdf-to-html | | X | | | X | | | X | | |
pdf-to-xml | | X | | | X | | | X | | |
add-password | | | X | | | | | | | X |
remove-password | | | X | | | | | | | X |
change-permissions | | | X | | | | | | | X |
add-watermark | | | X | | | | | | | X |
cert-sign | | | X | | | | | | | X |
ocr-pdf | | | | X | X | | | | X | |
add-image | | | | X | | | | | | X |
compress-pdf | | | | X | X | | | | X
extract-images | | | | X | | | | | | X |
change-metadata | | | | X | | | | | | X |
extract-image-scans | | | | X | X | X | X | | | |
sign | | | | X | | | | | | | X
flatten | | | | X | | | | | | |
repair | | | | X | X | | | X | | |
remove-blanks | | | | X | X | X | X | | | |
compare | | | | X | | | | | | | X

View file

@ -17,15 +17,20 @@ $(document).ready(function() {
const override = $('#override').val() || ''; const override = $('#override').val() || '';
const originalButtonText = $('#submitBtn').text(); const originalButtonText = $('#submitBtn').text();
$('#submitBtn').text('Processing...'); $('#submitBtn').text('Processing...');
console.log(override);
try { try {
console.log("2");
if(remoteCall === true) { if(remoteCall === true) {
console.log("3");
if (override === 'multi' || (!multiple && files.length > 1) && override !== 'single' ) { if (override === 'multi' || (!multiple && files.length > 1) && override !== 'single' ) {
console.log("3");
await submitMultiPdfForm(url, files); await submitMultiPdfForm(url, files);
} else { } else {
console.log("4");
await handleSingleDownload(url, formData); await handleSingleDownload(url, formData);
} }
} }
console.log("5");
$('#submitBtn').text(originalButtonText); $('#submitBtn').text(originalButtonText);
} catch (error) { } catch (error) {
handleDownloadError(error); handleDownloadError(error);
@ -37,7 +42,7 @@ $(document).ready(function() {
async function handleSingleDownload(url, formData, isMulti = false) { async function handleSingleDownload(url, formData, isMulti = false , isZip = false) {
try { try {
const response = await fetch(url, { method: 'POST', body: formData }); const response = await fetch(url, { method: 'POST', body: formData });
const contentType = response.headers.get('content-type'); const contentType = response.headers.get('content-type');
@ -54,11 +59,10 @@ async function handleSingleDownload(url, formData, isMulti = false) {
let filename = getFilenameFromContentDisposition(contentDisposition); let filename = getFilenameFromContentDisposition(contentDisposition);
const blob = await response.blob(); const blob = await response.blob();
if (contentType.includes('application/pdf') || contentType.includes('image/')) { if (contentType.includes('application/pdf') || contentType.includes('image/')) {
return handleResponse(blob, filename, !isMulti); return handleResponse(blob, filename, !isMulti, isZip);
} else { } else {
return handleResponse(blob, filename); return handleResponse(blob, filename, false, isZip);
} }
} catch (error) { } catch (error) {
console.error('Error in handleSingleDownload:', error); console.error('Error in handleSingleDownload:', error);
@ -95,21 +99,27 @@ async function handleJsonResponse(response) {
} }
async function handleResponse(blob, filename, considerViewOptions = false) { async function handleResponse(blob, filename, considerViewOptions = false, isZip = false) {
if (!blob) return; if (!blob) return;
const downloadOption = localStorage.getItem('downloadOption'); const downloadOption = localStorage.getItem('downloadOption');
console.log("handleResponse 1");
if (considerViewOptions) { if (considerViewOptions) {
if (downloadOption === 'sameWindow') { if (downloadOption === 'sameWindow') {
console.log("handleResponse 2");
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
window.location.href = url; window.location.href = url;
return; return;
} else if (downloadOption === 'newWindow') { } else if (downloadOption === 'newWindow') {
console.log("handleResponse 3");
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
window.open(url, '_blank'); window.open(url, '_blank');
return; return;
} }
} }
if(!isZip){
downloadFile(blob, filename); downloadFile(blob, filename);
}
console.log("handleResponse 5");
return { filename, blob }; return { filename, blob };
} }
@ -126,6 +136,7 @@ function downloadFile(blob, filename) {
return; return;
} }
console.log("downloadFile 1");
const url = URL.createObjectURL(blob); const url = URL.createObjectURL(blob);
const a = document.createElement('a'); const a = document.createElement('a');
a.href = url; a.href = url;
@ -176,12 +187,13 @@ async function submitMultiPdfForm(url, files) {
} }
try { try {
const downloadDetails = await handleSingleDownload(url, fileFormData, true); const downloadDetails = await handleSingleDownload(url, fileFormData, true, zipFiles);
console.log(downloadDetails); console.log(downloadDetails);
if (zipFiles) { if (zipFiles) {
jszip.file(downloadDetails.filename, downloadDetails.blob); jszip.file(downloadDetails.filename, downloadDetails.blob);
} else { } else {
downloadFile(downloadDetails.blob, downloadDetails.filename); console.log("downloadFile 198");
//downloadFile(downloadDetails.blob, downloadDetails.filename);
} }
updateProgressBar(progressBar, Array.from(files).length); updateProgressBar(progressBar, Array.from(files).length);
} catch (error) { } catch (error) {
@ -196,6 +208,7 @@ async function submitMultiPdfForm(url, files) {
if (zipFiles) { if (zipFiles) {
try { try {
const content = await jszip.generateAsync({ type: "blob" }); const content = await jszip.generateAsync({ type: "blob" });
console.log("downloadFile 213");
downloadFile(content, "files.zip"); downloadFile(content, "files.zip");
} catch (error) { } catch (error) {
console.error('Error generating ZIP file: ' + error); console.error('Error generating ZIP file: ' + error);