mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-12 17:52:13 +02:00
Formatting and OCR fix
This commit is contained in:
parent
52507433c5
commit
b5e08f79d9
@ -6,6 +6,7 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
|
||||
import stirling.software.SPDF.model.ApplicationProperties;
|
||||
import stirling.software.SPDF.model.ApplicationProperties.EnterpriseEdition;
|
||||
@ -36,7 +37,7 @@ public class EEAppConfig {
|
||||
public boolean runningEnterprise() {
|
||||
return licenseKeyChecker.getPremiumLicenseEnabledResult() == License.ENTERPRISE;
|
||||
}
|
||||
|
||||
|
||||
@Bean(name = "SSOAutoLogin")
|
||||
public boolean ssoAutoLogin() {
|
||||
return applicationProperties.getPremium().getProFeatures().isSsoAutoLogin();
|
||||
|
@ -25,12 +25,13 @@ import stirling.software.SPDF.utils.GeneralUtils;
|
||||
@Service
|
||||
@Slf4j
|
||||
public class KeygenLicenseVerifier {
|
||||
|
||||
|
||||
enum License{
|
||||
NORMAL, PRO, ENTERPRISE
|
||||
|
||||
}
|
||||
|
||||
enum License {
|
||||
NORMAL,
|
||||
PRO,
|
||||
ENTERPRISE
|
||||
}
|
||||
|
||||
// License verification configuration
|
||||
private static final String ACCOUNT_ID = "e5430f69-e834-4ae4-befd-b602aae5f372";
|
||||
private static final String BASE_URL = "https://api.keygen.sh/v1/accounts";
|
||||
@ -57,18 +58,18 @@ public class KeygenLicenseVerifier {
|
||||
return resultToEnum(verifyCertificateLicense(licenseKeyOrCert), License.ENTERPRISE);
|
||||
} else if (isJWTLicense(licenseKeyOrCert)) {
|
||||
log.info("Detected JWT-style license key. Processing...");
|
||||
return resultToEnum( verifyJWTLicense(licenseKeyOrCert), License.ENTERPRISE);
|
||||
return resultToEnum(verifyJWTLicense(licenseKeyOrCert), License.ENTERPRISE);
|
||||
} else {
|
||||
log.info("Detected standard license key. Processing...");
|
||||
return resultToEnum( verifyStandardLicense(licenseKeyOrCert), License.PRO);
|
||||
return resultToEnum(verifyStandardLicense(licenseKeyOrCert), License.PRO);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private License resultToEnum(boolean result, License option) {
|
||||
if(result) {
|
||||
return option;
|
||||
}
|
||||
return License.NORMAL;
|
||||
if (result) {
|
||||
return option;
|
||||
}
|
||||
return License.NORMAL;
|
||||
}
|
||||
|
||||
private boolean isCertificateLicense(String license) {
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import stirling.software.SPDF.EE.KeygenLicenseVerifier.License;
|
||||
import stirling.software.SPDF.model.ApplicationProperties;
|
||||
import stirling.software.SPDF.utils.GeneralUtils;
|
||||
@ -48,8 +49,8 @@ public class LicenseKeyChecker {
|
||||
premiumEnabledResult = licenseService.verifyLicense(licenseKey);
|
||||
if (License.ENTERPRISE == premiumEnabledResult) {
|
||||
log.info("License key is Enterprise.");
|
||||
} else if(License.PRO == premiumEnabledResult){
|
||||
log.info("License key is Pro.");
|
||||
} else if (License.PRO == premiumEnabledResult) {
|
||||
log.info("License key is Pro.");
|
||||
} else {
|
||||
log.info("License key is invalid, defaulting to non pro license.");
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
@ -2,7 +2,6 @@ package stirling.software.SPDF.config.security;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.security.authentication.LockedException;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
|
@ -3,7 +3,6 @@ package stirling.software.SPDF.config.security;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
@ -3,7 +3,6 @@ package stirling.software.SPDF.config.security;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
|
@ -17,7 +17,6 @@ import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.pdfbox.multipdf.PDFMergerUtility;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
|
@ -8,7 +8,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@ -64,9 +63,7 @@ public class PipelineController {
|
||||
log.info("Received POST request to /handleData with {} files", files.length);
|
||||
|
||||
List<String> operationNames =
|
||||
config.getOperations().stream()
|
||||
.map(PipelineOperation::getOperation)
|
||||
.toList();
|
||||
config.getOperations().stream().map(PipelineOperation::getOperation).toList();
|
||||
|
||||
Map<String, Object> properties = new HashMap<>();
|
||||
properties.put("operations", operationNames);
|
||||
|
@ -11,7 +11,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package stirling.software.SPDF.controller.api.security;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
|
||||
|
@ -66,13 +66,13 @@ public class SanitizeController {
|
||||
}
|
||||
|
||||
if (removeXMPMetadata) {
|
||||
sanitizeXMPMetadata(document);
|
||||
sanitizeXMPMetadata(document);
|
||||
}
|
||||
|
||||
if (removeMetadata) {
|
||||
sanitizeDocumentInfoMetadata(document);
|
||||
sanitizeDocumentInfoMetadata(document);
|
||||
}
|
||||
|
||||
|
||||
if (removeLinks) {
|
||||
sanitizeLinks(document);
|
||||
}
|
||||
@ -158,7 +158,7 @@ public class SanitizeController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void sanitizeDocumentInfoMetadata(PDDocument document) {
|
||||
PDDocumentInformation docInfo = document.getDocumentInformation();
|
||||
if (docInfo != null) {
|
||||
@ -167,8 +167,6 @@ public class SanitizeController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sanitizeLinks(PDDocument document) throws IOException {
|
||||
for (PDPage page : document.getPages()) {
|
||||
for (PDAnnotation annotation : page.getAnnotations()) {
|
||||
|
@ -10,7 +10,6 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@ -58,10 +57,12 @@ public class AccountWebController {
|
||||
// Assuming you have a repository for user operations
|
||||
private final UserRepository userRepository;
|
||||
private final boolean runningEE;
|
||||
|
||||
public AccountWebController(
|
||||
ApplicationProperties applicationProperties,
|
||||
SessionPersistentRegistry sessionPersistentRegistry,
|
||||
UserRepository userRepository, @Qualifier("runningEE") boolean runningEE) {
|
||||
UserRepository userRepository,
|
||||
@Qualifier("runningEE") boolean runningEE) {
|
||||
this.applicationProperties = applicationProperties;
|
||||
this.sessionPersistentRegistry = sessionPersistentRegistry;
|
||||
this.userRepository = userRepository;
|
||||
@ -199,9 +200,9 @@ public class AccountWebController {
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@GetMapping("/usage")
|
||||
public String showUsage() {
|
||||
if(!runningEE) {
|
||||
return "error";
|
||||
}
|
||||
if (!runningEE) {
|
||||
return "error";
|
||||
}
|
||||
return "usage";
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -3,7 +3,6 @@ package stirling.software.SPDF.controller.web;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -4,7 +4,6 @@ import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@ -123,7 +122,7 @@ public class OtherWebController {
|
||||
return Arrays.stream(files)
|
||||
.filter(file -> file.getName().endsWith(".traineddata"))
|
||||
.map(file -> file.getName().replace(".traineddata", ""))
|
||||
.filter(lang -> !lang.equalsIgnoreCase("osd"))
|
||||
.filter(lang -> !lang.equalsIgnoreCase("osd")).sorted()
|
||||
.toList();
|
||||
}
|
||||
|
||||
@ -132,7 +131,6 @@ public class OtherWebController {
|
||||
public ModelAndView ocrPdfPage() {
|
||||
ModelAndView modelAndView = new ModelAndView("misc/ocr-pdf");
|
||||
List<String> languages = getAvailableTesseractLanguages();
|
||||
Collections.sort(languages);
|
||||
modelAndView.addObject("languages", languages);
|
||||
modelAndView.addObject("currentPage", "ocr-pdf");
|
||||
return modelAndView;
|
||||
|
@ -22,7 +22,7 @@ public class SanitizePdfRequest extends PDFFile {
|
||||
|
||||
@Schema(description = "Remove document info metadata from the PDF", defaultValue = "false")
|
||||
private boolean removeMetadata;
|
||||
|
||||
|
||||
@Schema(description = "Remove links from the PDF", defaultValue = "false")
|
||||
private boolean removeLinks;
|
||||
|
||||
|
@ -5,7 +5,6 @@ import static stirling.software.SPDF.model.UsernameAttribute.EMAIL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -59,8 +58,7 @@ public class Provider {
|
||||
|
||||
public void setScopes(String scopes) {
|
||||
if (scopes != null && !scopes.isBlank()) {
|
||||
this.scopes =
|
||||
Arrays.stream(scopes.split(",")).map(String::trim).toList();
|
||||
this.scopes = Arrays.stream(scopes.split(",")).map(String::trim).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,17 +68,17 @@ public class CustomPDFDocumentFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point for loading a PDF document from a file. Automatically selects the most
|
||||
* appropriate loading strategy.
|
||||
*/
|
||||
* Main entry point for loading a PDF document from a file. Automatically selects the most
|
||||
* appropriate loading strategy.
|
||||
*/
|
||||
public PDDocument load(File file) throws IOException {
|
||||
return load(file, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point for loading a PDF document from a file with read-only option.
|
||||
* Automatically selects the most appropriate loading strategy.
|
||||
*/
|
||||
* Main entry point for loading a PDF document from a file with read-only option. Automatically
|
||||
* selects the most appropriate loading strategy.
|
||||
*/
|
||||
public PDDocument load(File file, boolean readOnly) throws IOException {
|
||||
if (file == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
@ -95,17 +95,17 @@ public class CustomPDFDocumentFactory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point for loading a PDF document from a Path. Automatically selects the most
|
||||
* appropriate loading strategy.
|
||||
*/
|
||||
* Main entry point for loading a PDF document from a Path. Automatically selects the most
|
||||
* appropriate loading strategy.
|
||||
*/
|
||||
public PDDocument load(Path path) throws IOException {
|
||||
return load(path, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Main entry point for loading a PDF document from a Path with read-only option.
|
||||
* Automatically selects the most appropriate loading strategy.
|
||||
*/
|
||||
* Main entry point for loading a PDF document from a Path with read-only option. Automatically
|
||||
* selects the most appropriate loading strategy.
|
||||
*/
|
||||
public PDDocument load(Path path, boolean readOnly) throws IOException {
|
||||
if (path == null) {
|
||||
throw new IllegalArgumentException("File cannot be null");
|
||||
@ -170,7 +170,8 @@ public class CustomPDFDocumentFactory {
|
||||
}
|
||||
|
||||
/** Load with password from InputStream and read-only option */
|
||||
public PDDocument load(InputStream input, String password, boolean readOnly) throws IOException {
|
||||
public PDDocument load(InputStream input, String password, boolean readOnly)
|
||||
throws IOException {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("InputStream cannot be null");
|
||||
}
|
||||
@ -179,7 +180,8 @@ public class CustomPDFDocumentFactory {
|
||||
Path tempFile = createTempFile("pdf-stream-");
|
||||
|
||||
Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
PDDocument doc = loadAdaptivelyWithPassword(tempFile.toFile(), Files.size(tempFile), password);
|
||||
PDDocument doc =
|
||||
loadAdaptivelyWithPassword(tempFile.toFile(), Files.size(tempFile), password);
|
||||
if (!readOnly) {
|
||||
postProcessDocument(doc);
|
||||
}
|
||||
@ -203,7 +205,7 @@ public class CustomPDFDocumentFactory {
|
||||
|
||||
/** Load from a PDFFile object with read-only option */
|
||||
public PDDocument load(PDFFile pdfFile, boolean readOnly) throws IOException {
|
||||
return load(pdfFile.getFileInput(), readOnly);
|
||||
return load(pdfFile.getFileInput(), readOnly);
|
||||
}
|
||||
|
||||
/** Load from a MultipartFile */
|
||||
@ -213,8 +215,7 @@ public class CustomPDFDocumentFactory {
|
||||
|
||||
/** Load from a MultipartFile with read-only option */
|
||||
public PDDocument load(MultipartFile pdfFile, boolean readOnly) throws IOException {
|
||||
return load(pdfFile.getInputStream(), readOnly);
|
||||
|
||||
return load(pdfFile.getInputStream(), readOnly);
|
||||
}
|
||||
|
||||
/** Load with password from MultipartFile */
|
||||
@ -223,10 +224,11 @@ public class CustomPDFDocumentFactory {
|
||||
}
|
||||
|
||||
/** Load with password from MultipartFile with read-only option */
|
||||
public PDDocument load(MultipartFile fileInput, String password, boolean readOnly) throws IOException {
|
||||
return load(fileInput.getInputStream(), password, readOnly);
|
||||
public PDDocument load(MultipartFile fileInput, String password, boolean readOnly)
|
||||
throws IOException {
|
||||
return load(fileInput.getInputStream(), password, readOnly);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine the appropriate caching strategy based on file size and available memory. This
|
||||
* common method is used by both password and non-password loading paths.
|
||||
@ -471,5 +473,4 @@ public class CustomPDFDocumentFactory {
|
||||
return saveToBytes(document);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
@ -9,7 +9,6 @@ import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
@ -172,9 +171,7 @@ public class FileToPdf {
|
||||
|
||||
// Search for the main HTML file.
|
||||
try (Stream<Path> walk = Files.walk(tempDirectory)) {
|
||||
List<Path> htmlFiles =
|
||||
walk.filter(file -> file.toString().endsWith(".html"))
|
||||
.toList();
|
||||
List<Path> htmlFiles = walk.filter(file -> file.toString().endsWith(".html")).toList();
|
||||
|
||||
if (htmlFiles.isEmpty()) {
|
||||
throw new IOException("No HTML files found in the unzipped directory.");
|
||||
|
Loading…
Reference in New Issue
Block a user