Compare commits

..

7 Commits

Author SHA1 Message Date
stirlingbot[bot]
8780bf1e17
Update 3rd Party Licenses
Signed-off-by: stirlingbot[bot] <1113334+stirlingbot[bot]@users.noreply.github.com>
2025-05-19 13:13:09 +00:00
Anthony Stirling
21832729d2
JUnits JUnits JUnits, so many JUnits (#3537)
# Description of Changes

Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
2025-05-19 14:12:06 +01:00
Anthony Stirling
f94b8c3b22
Floating keys for pro users (#3535)
# Description of Changes

Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-05-19 10:00:58 +01:00
NeilJared
b26ecbc3b7
Update messages_es_ES.properties (#3527)
Updated es_ES translation and made minor improvements.
2025-05-16 12:23:55 +01:00
Dr.XYZ
3b2b14609d
Update zh_TW Traditional Chinese locale (#3524)
# Description of Changes

Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [x] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-05-16 12:23:37 +01:00
Ludy
52f09f1840
Improve Type Safety and OpenAPI Schema for PDF API Controllers and Models (#3470)
# Description of Changes

- **What was changed**  
- Updated controller methods to use strongly‐typed primitives (`int`,
`long`, `boolean`) instead of `String` for numeric and boolean
parameters, eliminating calls to `Integer.parseInt`/`Long.parseLong` and
improving null‐safety (`Boolean.TRUE.equals(...)`).
- Enhanced all API request model classes with richer Swagger/OpenAPI
annotations: added `requiredMode`, `defaultValue`, `allowableValues`,
`format`, `pattern`, and tightened schema descriptions for all fields.
- Refactored HTML form templates for “Remove Blank Pages” to include
`min`, `max`, and `step` attributes on numeric inputs, matching the
updated validation rules.

- **Why the change was made**  
- **Type safety & robustness**: Shifting from `String` to native types
prevents runtime parsing errors, simplifies controller logic, and makes
default values explicit.
- **Better API documentation & validation**: Enriching the Swagger
annotations ensures generated docs accurately reflect required fields,
default values, and permitted ranges, which improves client code
generation and developer experience.
- **Consistency across codebase**: Aligning all request models and
controllers enforces a uniform coding style and reduces bugs.

#3406

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-05-16 12:23:01 +01:00
Ludy
c660ad80ce
Update legal URLs and improve OpenAPI metadata configuration (#3522)
# Description of Changes

Please provide a summary of the changes, including:

- Updated default Terms & Conditions URL from `/terms-and-conditions` to
`/terms` in:
  - `InitialSetup.java`
  - `settings.yml.template`
  - `allEndpointsRemovedSettings.yml`
- Improved OpenAPI metadata in `OpenApiConfig.java`:
  - Added contact information (`name`, `url`, `email`)
  - Added license section with MIT license
  - Included terms of service link
- Changed string comparison in `MetricsConfig.java` to use
`"constant".equals(...)` format
- Cleaned up and unified YAML formatting and comments
- Merged and restructured `enterpriseEdition` settings under
`premium.proFeatures`

### Why the change was made

- Ensure legal links are consistent and up-to-date
- Improve clarity and completeness of the OpenAPI specification for
external consumers
- Follow best practices for code readability and configuration structure
- Prevent misconfiguration from outdated or redundant YAML sections

---

## Checklist

### General

- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md)
(if applicable)
- [x] I have performed a self-review of my own code
- [x] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing)
for more details.
2025-05-13 23:06:14 +01:00
131 changed files with 5497 additions and 493 deletions

View File

@ -1,5 +1,6 @@
plugins {
id "java"
id 'jacoco'
id "org.springframework.boot" version "3.4.5"
id "io.spring.dependency-management" version "1.1.7"
id "org.springdoc.openapi-gradle-plugin" version "1.9.0"
@ -29,7 +30,7 @@ ext {
}
group = "stirling.software"
version = "0.46.1"
version = "0.46.2"
java {
// 17 is lowest but we support and recommend 21
@ -542,6 +543,10 @@ dependencies {
compileOnly "org.projectlombok:lombok:$lombokVersion"
annotationProcessor "org.projectlombok:lombok:$lombokVersion"
// Mockito (core)
testImplementation 'org.mockito:mockito-core:5.11.0'
testRuntimeOnly 'org.mockito:mockito-inline:5.2.0'
}

View File

@ -61,6 +61,7 @@ public class EEAppConfig {
}
// TODO: Remove post migration
@SuppressWarnings("deprecation")
public void migrateEnterpriseSettingsToPremium(ApplicationProperties applicationProperties) {
EnterpriseEdition enterpriseEdition = applicationProperties.getEnterpriseEdition();
Premium premium = applicationProperties.getPremium();

View File

@ -47,31 +47,47 @@ public class KeygenLicenseVerifier {
private static final ObjectMapper objectMapper = new ObjectMapper();
private final ApplicationProperties applicationProperties;
// Shared HTTP client for connection pooling
private static final HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.connectTimeout(java.time.Duration.ofSeconds(10))
.build();
// License metadata context class to avoid shared mutable state
private static class LicenseContext {
private boolean isFloatingLicense = false;
private int maxMachines = 1; // Default to 1 if not specified
private boolean isEnterpriseLicense = false;
public LicenseContext() {}
}
public License verifyLicense(String licenseKeyOrCert) {
License license;
LicenseContext context = new LicenseContext();
if (isCertificateLicense(licenseKeyOrCert)) {
log.info("Detected certificate-based license. Processing...");
boolean isValid = verifyCertificateLicense(licenseKeyOrCert);
boolean isValid = verifyCertificateLicense(licenseKeyOrCert, context);
if (isValid) {
license = isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
license = context.isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
} else {
license = License.NORMAL;
}
} else if (isJWTLicense(licenseKeyOrCert)) {
log.info("Detected JWT-style license key. Processing...");
boolean isValid = verifyJWTLicense(licenseKeyOrCert);
boolean isValid = verifyJWTLicense(licenseKeyOrCert, context);
if (isValid) {
license = isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
license = context.isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
} else {
license = License.NORMAL;
}
} else {
log.info("Detected standard license key. Processing...");
boolean isValid = verifyStandardLicense(licenseKeyOrCert);
boolean isValid = verifyStandardLicense(licenseKeyOrCert, context);
if (isValid) {
license = isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
license = context.isEnterpriseLicense ? License.ENTERPRISE : License.PRO;
} else {
license = License.NORMAL;
}
@ -79,7 +95,7 @@ public class KeygenLicenseVerifier {
return license;
}
private boolean isEnterpriseLicense = false;
// Removed instance field for isEnterpriseLicense, now using LicenseContext
private boolean isCertificateLicense(String license) {
return license != null && license.trim().startsWith(CERT_PREFIX);
@ -89,7 +105,7 @@ public class KeygenLicenseVerifier {
return license != null && license.trim().startsWith(JWT_PREFIX);
}
private boolean verifyCertificateLicense(String licenseFile) {
private boolean verifyCertificateLicense(String licenseFile, LicenseContext context) {
try {
String encodedPayload = licenseFile;
// Remove the header
@ -144,7 +160,7 @@ public class KeygenLicenseVerifier {
}
// Process the certificate data
boolean isValid = processCertificateData(decodedData);
boolean isValid = processCertificateData(decodedData, context);
return isValid;
} catch (Exception e) {
@ -187,7 +203,7 @@ public class KeygenLicenseVerifier {
}
}
private boolean processCertificateData(String certData) {
private boolean processCertificateData(String certData, LicenseContext context) {
try {
JSONObject licenseData = new JSONObject(certData);
JSONObject metaObj = licenseData.optJSONObject("meta");
@ -229,15 +245,17 @@ public class KeygenLicenseVerifier {
if (attributesObj != null) {
log.info("Found attributes in certificate data");
// Check for floating license
context.isFloatingLicense = attributesObj.optBoolean("floating", false);
context.maxMachines = attributesObj.optInt("maxMachines", 1);
// Extract metadata
JSONObject metadataObj = attributesObj.optJSONObject("metadata");
if (metadataObj != null) {
int users = metadataObj.optInt("users", 0);
if (users > 0) {
applicationProperties.getPremium().setMaxUsers(users);
log.info("License allows for {} users", users);
}
isEnterpriseLicense = metadataObj.optBoolean("isEnterprise", false);
int users = metadataObj.optInt("users", 1);
applicationProperties.getPremium().setMaxUsers(users);
log.info("License allows for {} users", users);
context.isEnterpriseLicense = metadataObj.optBoolean("isEnterprise", false);
}
// Check license status if available
@ -257,7 +275,7 @@ public class KeygenLicenseVerifier {
}
}
private boolean verifyJWTLicense(String licenseKey) {
private boolean verifyJWTLicense(String licenseKey, LicenseContext context) {
try {
log.info("Verifying ED25519_SIGN format license key");
@ -291,7 +309,7 @@ public class KeygenLicenseVerifier {
String payload = new String(payloadBytes);
// Process the license payload
boolean isValid = processJWTLicensePayload(payload);
boolean isValid = processJWTLicensePayload(payload, context);
return isValid;
} catch (Exception e) {
@ -327,7 +345,7 @@ public class KeygenLicenseVerifier {
}
}
private boolean processJWTLicensePayload(String payload) {
private boolean processJWTLicensePayload(String payload, LicenseContext context) {
try {
log.info("Processing license payload: {}", payload);
@ -348,6 +366,13 @@ public class KeygenLicenseVerifier {
String licenseId = licenseObj.optString("id", "unknown");
log.info("Processing license with ID: {}", licenseId);
// Check for floating license in license object
context.isFloatingLicense = licenseObj.optBoolean("floating", false);
context.maxMachines = licenseObj.optInt("maxMachines", 1);
if (context.isFloatingLicense) {
log.info("Detected floating license with max machines: {}", context.maxMachines);
}
// Check expiry date
String expiryStr = licenseObj.optString("expiry", null);
if (expiryStr != null && !"null".equals(expiryStr)) {
@ -383,9 +408,20 @@ public class KeygenLicenseVerifier {
String policyId = policyObj.optString("id", "unknown");
log.info("License uses policy: {}", policyId);
// Check for floating license in policy
boolean policyFloating = policyObj.optBoolean("floating", false);
int policyMaxMachines = policyObj.optInt("maxMachines", 1);
// Policy settings take precedence
if (policyFloating) {
context.isFloatingLicense = true;
context.maxMachines = policyMaxMachines;
log.info("Policy defines floating license with max machines: {}", context.maxMachines);
}
// Extract max users and isEnterprise from policy or metadata
int users = policyObj.optInt("users", 0);
isEnterpriseLicense = policyObj.optBoolean("isEnterprise", false);
int users = policyObj.optInt("users", 1);
context.isEnterpriseLicense = policyObj.optBoolean("isEnterprise", false);
if (users > 0) {
applicationProperties.getPremium().setMaxUsers(users);
@ -399,7 +435,7 @@ public class KeygenLicenseVerifier {
log.info("License allows for {} users (from metadata)", users);
// Check for isEnterprise flag in metadata
isEnterpriseLicense = metadata.optBoolean("isEnterprise", false);
context.isEnterpriseLicense = metadata.optBoolean("isEnterprise", false);
} else {
// Default value
applicationProperties.getPremium().setMaxUsers(1);
@ -415,13 +451,13 @@ public class KeygenLicenseVerifier {
}
}
private boolean verifyStandardLicense(String licenseKey) {
private boolean verifyStandardLicense(String licenseKey, LicenseContext context) {
try {
log.info("Checking standard license key");
String machineFingerprint = generateMachineFingerprint();
// First, try to validate the license
JsonNode validationResponse = validateLicense(licenseKey, machineFingerprint);
JsonNode validationResponse = validateLicense(licenseKey, machineFingerprint, context);
if (validationResponse != null) {
boolean isValid = validationResponse.path("meta").path("valid").asBoolean();
String licenseId = validationResponse.path("data").path("id").asText();
@ -435,10 +471,10 @@ public class KeygenLicenseVerifier {
"License not activated for this machine. Attempting to"
+ " activate...");
boolean activated =
activateMachine(licenseKey, licenseId, machineFingerprint);
activateMachine(licenseKey, licenseId, machineFingerprint, context);
if (activated) {
// Revalidate after activation
validationResponse = validateLicense(licenseKey, machineFingerprint);
validationResponse = validateLicense(licenseKey, machineFingerprint, context);
isValid =
validationResponse != null
&& validationResponse
@ -458,9 +494,8 @@ public class KeygenLicenseVerifier {
}
}
private JsonNode validateLicense(String licenseKey, String machineFingerprint)
private JsonNode validateLicense(String licenseKey, String machineFingerprint, LicenseContext context)
throws Exception {
HttpClient client = HttpClient.newHttpClient();
String requestBody =
String.format(
"{\"meta\":{\"key\":\"%s\",\"scope\":{\"fingerprint\":\"%s\"}}}",
@ -479,7 +514,7 @@ public class KeygenLicenseVerifier {
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
log.info("ValidateLicenseResponse body: {}", response.body());
JsonNode jsonResponse = objectMapper.readTree(response.body());
if (response.statusCode() == 200) {
@ -492,19 +527,57 @@ public class KeygenLicenseVerifier {
log.info("License validity: " + isValid);
log.info("Validation detail: " + detail);
log.info("Validation code: " + code);
// Check if the license itself has floating attribute
JsonNode licenseAttrs = jsonResponse.path("data").path("attributes");
if (!licenseAttrs.isMissingNode()) {
context.isFloatingLicense = licenseAttrs.path("floating").asBoolean(false);
context.maxMachines = licenseAttrs.path("maxMachines").asInt(1);
log.info("License floating (from license): {}, maxMachines: {}",
context.isFloatingLicense, context.maxMachines);
}
// Also check the policy for floating license support if included
JsonNode includedNode = jsonResponse.path("included");
JsonNode policyNode = null;
if (includedNode.isArray()) {
for (JsonNode node : includedNode) {
if ("policies".equals(node.path("type").asText())) {
policyNode = node;
break;
}
}
}
if (policyNode != null) {
// Check if this is a floating license from policy
boolean policyFloating = policyNode.path("attributes").path("floating").asBoolean(false);
int policyMaxMachines = policyNode.path("attributes").path("maxMachines").asInt(1);
// Policy takes precedence over license attributes
if (policyFloating) {
context.isFloatingLicense = true;
context.maxMachines = policyMaxMachines;
}
log.info("License floating (from policy): {}, maxMachines: {}",
context.isFloatingLicense, context.maxMachines);
}
// Extract user count
// Extract user count, default to 1 if not specified
int users =
jsonResponse
.path("data")
.path("attributes")
.path("metadata")
.path("users")
.asInt(0);
.asInt(1);
applicationProperties.getPremium().setMaxUsers(users);
// Extract isEnterprise flag
isEnterpriseLicense =
context.isEnterpriseLicense =
jsonResponse
.path("data")
.path("attributes")
@ -520,10 +593,87 @@ public class KeygenLicenseVerifier {
return jsonResponse;
}
private boolean activateMachine(String licenseKey, String licenseId, String machineFingerprint)
throws Exception {
HttpClient client = HttpClient.newHttpClient();
private boolean activateMachine(String licenseKey, String licenseId, String machineFingerprint,
LicenseContext context) throws Exception {
// For floating licenses, we first need to check if we need to deregister any machines
if (context.isFloatingLicense) {
log.info("Processing floating license activation. Max machines allowed: {}", context.maxMachines);
// Get the current machines for this license
JsonNode machinesResponse = fetchMachinesForLicense(licenseKey, licenseId);
if (machinesResponse != null) {
JsonNode machines = machinesResponse.path("data");
int currentMachines = machines.size();
log.info("Current machine count: {}, Max allowed: {}", currentMachines, context.maxMachines);
// Check if the current fingerprint is already activated
boolean isCurrentMachineActivated = false;
String currentMachineId = null;
for (JsonNode machine : machines) {
if (machineFingerprint.equals(machine.path("attributes").path("fingerprint").asText())) {
isCurrentMachineActivated = true;
currentMachineId = machine.path("id").asText();
log.info("Current machine is already activated with ID: {}", currentMachineId);
break;
}
}
// If the current machine is already activated, there's no need to do anything
if (isCurrentMachineActivated) {
log.info("Machine already activated. No action needed.");
return true;
}
// If we've reached the max machines limit, we need to deregister the oldest machine
if (currentMachines >= context.maxMachines) {
log.info("Max machines reached. Deregistering oldest machine to make room for the new machine.");
// Find the oldest machine based on creation timestamp
if (machines.size() > 0) {
// Find the machine with the oldest creation date
String oldestMachineId = null;
java.time.Instant oldestTime = null;
for (JsonNode machine : machines) {
String createdStr = machine.path("attributes").path("created").asText(null);
if (createdStr != null && !createdStr.isEmpty()) {
try {
java.time.Instant createdTime = java.time.Instant.parse(createdStr);
if (oldestTime == null || createdTime.isBefore(oldestTime)) {
oldestTime = createdTime;
oldestMachineId = machine.path("id").asText();
}
} catch (Exception e) {
log.warn("Could not parse creation time for machine: {}", e.getMessage());
}
}
}
// If we couldn't determine the oldest by timestamp, use the first one
if (oldestMachineId == null) {
log.warn("Could not determine oldest machine by timestamp, using first machine in list");
oldestMachineId = machines.path(0).path("id").asText();
}
log.info("Deregistering machine with ID: {}", oldestMachineId);
boolean deregistered = deregisterMachine(licenseKey, oldestMachineId);
if (!deregistered) {
log.error("Failed to deregister machine. Cannot proceed with activation.");
return false;
}
log.info("Machine deregistered successfully. Proceeding with activation of new machine.");
} else {
log.error("License has reached machine limit but no machines were found to deregister. This is unexpected.");
// We'll still try to activate, but it might fail
}
}
}
}
// Proceed with machine activation
String hostname;
try {
hostname = java.net.InetAddress.getLocalHost().getHostName();
@ -570,7 +720,7 @@ public class KeygenLicenseVerifier {
.POST(HttpRequest.BodyPublishers.ofString(body.toString()))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
log.info("activateMachine Response body: " + response.body());
if (response.statusCode() == 201) {
log.info("Machine activated successfully");
@ -588,4 +738,66 @@ public class KeygenLicenseVerifier {
private String generateMachineFingerprint() {
return GeneralUtils.generateMachineFingerprint();
}
/**
* Fetches all machines associated with a specific license
*
* @param licenseKey The license key to check
* @param licenseId The license ID
* @return JsonNode containing the list of machines, or null if an error occurs
* @throws Exception if an error occurs during the HTTP request
*/
private JsonNode fetchMachinesForLicense(String licenseKey, String licenseId) throws Exception {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/" + ACCOUNT_ID + "/licenses/" + licenseId + "/machines"))
.header("Content-Type", "application/vnd.api+json")
.header("Accept", "application/vnd.api+json")
.header("Authorization", "License " + licenseKey)
.GET()
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
log.info("fetchMachinesForLicense Response body: {}", response.body());
if (response.statusCode() == 200) {
return objectMapper.readTree(response.body());
} else {
log.error("Error fetching machines for license. Status code: {}, error: {}",
response.statusCode(), response.body());
return null;
}
}
/**
* Deregisters a machine from a license
*
* @param licenseKey The license key
* @param machineId The ID of the machine to deregister
* @return true if deregistration was successful, false otherwise
*/
private boolean deregisterMachine(String licenseKey, String machineId) {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URL + "/" + ACCOUNT_ID + "/machines/" + machineId))
.header("Content-Type", "application/vnd.api+json")
.header("Accept", "application/vnd.api+json")
.header("Authorization", "License " + licenseKey)
.DELETE()
.build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 204) {
log.info("Machine {} successfully deregistered", machineId);
return true;
} else {
log.error("Error deregistering machine. Status code: {}, error: {}",
response.statusCode(), response.body());
return false;
}
} catch (Exception e) {
log.error("Exception during machine deregistration: {}", e.getMessage(), e);
return false;
}
}
}

View File

@ -73,7 +73,7 @@ public class InitialSetup {
// Initialize Terms and Conditions
String termsUrl = applicationProperties.getLegal().getTermsAndConditions();
if (StringUtils.isEmpty(termsUrl)) {
String defaultTermsUrl = "https://www.stirlingpdf.com/terms-and-conditions";
String defaultTermsUrl = "https://www.stirlingpdf.com/terms";
GeneralUtils.saveKeyToSettings("legal.termsAndConditions", defaultTermsUrl);
applicationProperties.getLegal().setTermsAndConditions(defaultTermsUrl);
}

View File

@ -15,7 +15,7 @@ public class MetricsConfig {
return new MeterFilter() {
@Override
public MeterFilterReply accept(Meter.Id id) {
if (id.getName().equals("http.requests")) {
if ("http.requests".equals(id.getName())) {
return MeterFilterReply.NEUTRAL;
}
return MeterFilterReply.DENY;

View File

@ -5,7 +5,9 @@ import org.springframework.context.annotation.Configuration;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
@ -31,14 +33,25 @@ public class OpenApiConfig {
// default version if all else fails
version = "1.0.0";
}
Info info =
new Info()
.title(DEFAULT_TITLE)
.version(version)
.license(
new License()
.name("MIT")
.url(
"https://raw.githubusercontent.com/Stirling-Tools/Stirling-PDF/refs/heads/main/LICENSE")
.identifier("MIT"))
.termsOfService("https://www.stirlingpdf.com/terms")
.contact(
new Contact()
.name("Stirling Software")
.url("https://www.stirlingpdf.com")
.email("contact@stirlingpdf.com"))
.description(DEFAULT_DESCRIPTION);
if (!applicationProperties.getSecurity().getEnableLogin()) {
return new OpenAPI()
.components(new Components())
.info(
new Info()
.title(DEFAULT_TITLE)
.version(version)
.description(DEFAULT_DESCRIPTION));
return new OpenAPI().components(new Components()).info(info);
} else {
SecurityScheme apiKeyScheme =
new SecurityScheme()
@ -47,11 +60,7 @@ public class OpenApiConfig {
.name("X-API-KEY");
return new OpenAPI()
.components(new Components().addSecuritySchemes("apiKey", apiKeyScheme))
.info(
new Info()
.title(DEFAULT_TITLE)
.version(version)
.description(DEFAULT_DESCRIPTION))
.info(info)
.addSecurityItem(new SecurityRequirement().addList("apiKey"));
}
}

View File

@ -59,7 +59,8 @@ public class AnalysisController {
description = "Returns title, author, subject, etc. Input:PDF Output:JSON Type:SISO")
public Map<String, String> getDocumentProperties(@ModelAttribute PDFFile file)
throws IOException {
// Load the document in read-only mode to prevent modifications and ensure the integrity of the original file.
// Load the document in read-only mode to prevent modifications and ensure the integrity of
// the original file.
try (PDDocument document = pdfDocumentFactory.load(file.getFileInput(), true)) {
PDDocumentInformation info = document.getDocumentInformation();
Map<String, String> properties = new HashMap<>();
@ -180,7 +181,8 @@ public class AnalysisController {
// Get permissions
Map<String, Boolean> permissions = new HashMap<>();
permissions.put("preventPrinting", !document.getCurrentAccessPermission().canPrint());
permissions.put(
"preventPrinting", !document.getCurrentAccessPermission().canPrint());
permissions.put(
"preventModify", !document.getCurrentAccessPermission().canModify());
permissions.put(

View File

@ -39,8 +39,8 @@ public class CropController {
description =
"This operation takes an input PDF file and crops it according to the given"
+ " coordinates. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> cropPdf(@ModelAttribute CropPdfForm form) throws IOException {
PDDocument sourceDocument = pdfDocumentFactory.load(form);
public ResponseEntity<byte[]> cropPdf(@ModelAttribute CropPdfForm request) throws IOException {
PDDocument sourceDocument = pdfDocumentFactory.load(request);
PDDocument newDocument =
pdfDocumentFactory.createNewDocumentBasedOnOldDocument(sourceDocument);
@ -64,7 +64,8 @@ public class CropController {
contentStream.saveGraphicsState();
// Define the crop area
contentStream.addRect(form.getX(), form.getY(), form.getWidth(), form.getHeight());
contentStream.addRect(
request.getX(), request.getY(), request.getWidth(), request.getHeight());
contentStream.clip();
// Draw the entire formXObject
@ -76,7 +77,11 @@ public class CropController {
// Now, set the new page's media box to the cropped size
newPage.setMediaBox(
new PDRectangle(form.getX(), form.getY(), form.getWidth(), form.getHeight()));
new PDRectangle(
request.getX(),
request.getY(),
request.getWidth(),
request.getHeight()));
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@ -87,7 +92,7 @@ public class CropController {
byte[] pdfContent = baos.toByteArray();
return WebResponseUtils.bytesToWebResponse(
pdfContent,
form.getFileInput().getOriginalFilename().replaceFirst("[.][^.]+$", "")
request.getFileInput().getOriginalFilename().replaceFirst("[.][^.]+$", "")
+ "_cropped.pdf");
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.mail.MessagingException;
@ -41,7 +42,13 @@ public class EmailController {
* @return ResponseEntity with success or error message.
*/
@PostMapping(consumes = "multipart/form-data", value = "/send-email")
@Operation(
summary = "Send an email with an attachment",
description =
"This endpoint sends an email with an attachment. Input:PDF"
+ " Output:Success/Failure Type:MISO")
public ResponseEntity<String> sendEmailWithAttachment(@Valid @ModelAttribute Email email) {
log.info("Sending email to: {}", email.toString());
try {
// Calls the service to send the email with attachment
emailService.sendEmailWithAttachment(email);

View File

@ -117,20 +117,20 @@ public class MergeController {
"This endpoint merges multiple PDF files into a single PDF file. The merged"
+ " file will contain all pages from the input files in the order they were"
+ " provided. Input:PDF Output:PDF Type:MISO")
public ResponseEntity<byte[]> mergePdfs(@ModelAttribute MergePdfsRequest form)
public ResponseEntity<byte[]> mergePdfs(@ModelAttribute MergePdfsRequest request)
throws IOException {
List<File> filesToDelete = new ArrayList<>(); // List of temporary files to delete
File mergedTempFile = null;
PDDocument mergedDocument = null;
boolean removeCertSign = form.isRemoveCertSign();
boolean removeCertSign = Boolean.TRUE.equals(request.getRemoveCertSign());
try {
MultipartFile[] files = form.getFileInput();
MultipartFile[] files = request.getFileInput();
Arrays.sort(
files,
getSortComparator(
form.getSortType())); // Sort files based on the given sort type
request.getSortType())); // Sort files based on the given sort type
PDFMergerUtility mergerUtility = new PDFMergerUtility();
long totalSize = 0;

View File

@ -47,7 +47,7 @@ public class MultiPageLayoutController {
int pagesPerSheet = request.getPagesPerSheet();
MultipartFile file = request.getFileInput();
boolean addBorder = request.isAddBorder();
boolean addBorder = Boolean.TRUE.equals(request.getAddBorder());
if (pagesPerSheet != 2
&& pagesPerSheet != 3

View File

@ -127,7 +127,7 @@ public class SplitPdfByChaptersController {
Path zipFile = null;
try {
boolean includeMetadata = request.getIncludeMetadata();
boolean includeMetadata = Boolean.TRUE.equals(request.getIncludeMetadata());
Integer bookmarkLevel =
request.getBookmarkLevel(); // levels start from 0 (top most bookmarks)
if (bookmarkLevel < 0) {
@ -161,7 +161,7 @@ public class SplitPdfByChaptersController {
.body("Unable to extract outline items".getBytes());
}
boolean allowDuplicates = request.getAllowDuplicates();
boolean allowDuplicates = Boolean.TRUE.equals(request.getAllowDuplicates());
if (!allowDuplicates) {
/*
duplicates are generated when multiple bookmarks correspond to the same page,

View File

@ -60,7 +60,7 @@ public class SplitPdfBySectionsController {
// Process the PDF based on split parameters
int horiz = request.getHorizontalDivisions() + 1;
int verti = request.getVerticalDivisions() + 1;
boolean merge = request.isMerge();
boolean merge = Boolean.TRUE.equals(request.getMerge());
List<PDDocument> splitDocuments = splitPdfPages(sourceDocument, verti, horiz);
String filename =

View File

@ -58,7 +58,7 @@ public class ConvertImgPDFController {
String imageFormat = request.getImageFormat();
String singleOrMultiple = request.getSingleOrMultiple();
String colorType = request.getColorType();
String dpi = request.getDpi();
int dpi = request.getDpi();
String pageNumbers = request.getPageNumbers();
Path tempFile = null;
Path tempOutputDir = null;
@ -94,7 +94,7 @@ public class ConvertImgPDFController {
: imageFormat.toUpperCase(),
colorTypeResult,
singleImage,
Integer.valueOf(dpi),
dpi,
filename);
if (result == null || result.length == 0) {
log.error("resultant bytes for {} is null, error converting ", filename);
@ -132,7 +132,7 @@ public class ConvertImgPDFController {
command.add(tempOutputDir.toString());
}
command.add("--dpi");
command.add(dpi);
command.add(String.valueOf(dpi));
ProcessExecutorResult resultProcess =
ProcessExecutor.getInstance(ProcessExecutor.Processes.PYTHON_OPENCV)
.runCommandWithOutputHandling(command);
@ -213,7 +213,7 @@ public class ConvertImgPDFController {
MultipartFile[] file = request.getFileInput();
String fitOption = request.getFitOption();
String colorType = request.getColorType();
boolean autoRotate = request.isAutoRotate();
boolean autoRotate = Boolean.TRUE.equals(request.getAutoRotate());
// Handle Null entries for formdata
if (colorType == null || colorType.isBlank()) {
colorType = "color";

View File

@ -47,9 +47,9 @@ public class ConvertMarkdownToPdf {
description =
"This endpoint takes a Markdown file input, converts it to HTML, and then to"
+ " PDF format. Input:MARKDOWN Output:PDF Type:SISO")
public ResponseEntity<byte[]> markdownToPdf(@ModelAttribute GeneralFile request)
public ResponseEntity<byte[]> markdownToPdf(@ModelAttribute GeneralFile generalFile)
throws Exception {
MultipartFile fileInput = request.getFileInput();
MultipartFile fileInput = generalFile.getFileInput();
if (fileInput == null) {
throw new IllegalArgumentException("Please provide a Markdown file for conversion.");

View File

@ -90,9 +90,9 @@ public class ConvertOfficeController {
description =
"This endpoint converts a given file to a PDF using LibreOffice API Input:ANY"
+ " Output:PDF Type:SISO")
public ResponseEntity<byte[]> processFileToPDF(@ModelAttribute GeneralFile request)
public ResponseEntity<byte[]> processFileToPDF(@ModelAttribute GeneralFile generalFile)
throws Exception {
MultipartFile inputFile = request.getFileInput();
MultipartFile inputFile = generalFile.getFileInput();
// unused but can start server instance if startup time is to long
// LibreOfficeListener.getInstance().start();
File file = null;

View File

@ -23,9 +23,8 @@ public class ConvertPDFToHtml {
summary = "Convert PDF to HTML",
description =
"This endpoint converts a PDF file to HTML format. Input:PDF Output:HTML Type:SISO")
public ResponseEntity<byte[]> processPdfToHTML(@ModelAttribute PDFFile request)
throws Exception {
MultipartFile inputFile = request.getFileInput();
public ResponseEntity<byte[]> processPdfToHTML(@ModelAttribute PDFFile file) throws Exception {
MultipartFile inputFile = file.getFileInput();
PDFToFile pdfToFile = new PDFToFile();
return pdfToFile.processPdfToHtml(inputFile);
}

View File

@ -97,9 +97,8 @@ public class ConvertPDFToOffice {
description =
"This endpoint converts a PDF file to an XML file. Input:PDF Output:XML"
+ " Type:SISO")
public ResponseEntity<byte[]> processPdfToXML(@ModelAttribute PDFFile request)
throws Exception {
MultipartFile inputFile = request.getFileInput();
public ResponseEntity<byte[]> processPdfToXML(@ModelAttribute PDFFile file) throws Exception {
MultipartFile inputFile = file.getFileInput();
PDFToFile pdfToFile = new PDFToFile();
return pdfToFile.processPdfToOfficeFormat(inputFile, "xml", "writer_pdf_import");

View File

@ -52,12 +52,12 @@ public class ExtractCSVController {
description =
"This operation takes an input PDF file and returns CSV file of whole page."
+ " Input:PDF Output:CSV Type:SISO")
public ResponseEntity<?> pdfToCsv(@ModelAttribute PDFWithPageNums form) throws Exception {
String baseName = getBaseName(form.getFileInput().getOriginalFilename());
public ResponseEntity<?> pdfToCsv(@ModelAttribute PDFWithPageNums request) throws Exception {
String baseName = getBaseName(request.getFileInput().getOriginalFilename());
List<CsvEntry> csvEntries = new ArrayList<>();
try (PDDocument document = pdfDocumentFactory.load(form)) {
List<Integer> pages = form.getPageNumbersList(document, true);
try (PDDocument document = pdfDocumentFactory.load(request)) {
List<Integer> pages = request.getPageNumbersList(document, true);
SpreadsheetExtractionAlgorithm sea = new SpreadsheetExtractionAlgorithm();
CSVFormat format =
CSVFormat.EXCEL.builder().setEscape('"').setQuoteMode(QuoteMode.ALL).build();

View File

@ -77,7 +77,7 @@ public class FilterController {
public ResponseEntity<byte[]> pageCount(@ModelAttribute PDFComparisonAndCount request)
throws IOException, InterruptedException {
MultipartFile inputFile = request.getFileInput();
String pageCount = request.getPageCount();
int pageCount = request.getPageCount();
String comparator = request.getComparator();
// Load the PDF
PDDocument document = pdfDocumentFactory.load(inputFile);
@ -87,13 +87,13 @@ public class FilterController {
// Perform the comparison
switch (comparator) {
case "Greater":
valid = actualPageCount > Integer.parseInt(pageCount);
valid = actualPageCount > pageCount;
break;
case "Equal":
valid = actualPageCount == Integer.parseInt(pageCount);
valid = actualPageCount == pageCount;
break;
case "Less":
valid = actualPageCount < Integer.parseInt(pageCount);
valid = actualPageCount < pageCount;
break;
default:
throw new IllegalArgumentException("Invalid comparator: " + comparator);
@ -153,7 +153,7 @@ public class FilterController {
public ResponseEntity<byte[]> fileSize(@ModelAttribute FileSizeRequest request)
throws IOException, InterruptedException {
MultipartFile inputFile = request.getFileInput();
String fileSize = request.getFileSize();
long fileSize = request.getFileSize();
String comparator = request.getComparator();
// Get the file size
@ -163,13 +163,13 @@ public class FilterController {
// Perform the comparison
switch (comparator) {
case "Greater":
valid = actualFileSize > Long.parseLong(fileSize);
valid = actualFileSize > fileSize;
break;
case "Equal":
valid = actualFileSize == Long.parseLong(fileSize);
valid = actualFileSize == fileSize;
break;
case "Less":
valid = actualFileSize < Long.parseLong(fileSize);
valid = actualFileSize < fileSize;
break;
default:
throw new IllegalArgumentException("Invalid comparator: " + comparator);

View File

@ -47,7 +47,7 @@ public class AutoRenameController {
public ResponseEntity<byte[]> extractHeader(@ModelAttribute ExtractHeaderRequest request)
throws Exception {
MultipartFile file = request.getFileInput();
Boolean useFirstTextAsFallback = request.isUseFirstTextAsFallback();
boolean useFirstTextAsFallback = Boolean.TRUE.equals(request.getUseFirstTextAsFallback());
PDDocument document = pdfDocumentFactory.load(file);
PDFTextStripper reader =

View File

@ -113,7 +113,7 @@ public class AutoSplitPdfController {
public ResponseEntity<byte[]> autoSplitPdf(@ModelAttribute AutoSplitPdfRequest request)
throws IOException {
MultipartFile file = request.getFileInput();
boolean duplexMode = request.isDuplexMode();
boolean duplexMode = Boolean.TRUE.equals(request.getDuplexMode());
PDDocument document = null;
List<PDDocument> splitDocuments = new ArrayList<>();

View File

@ -626,32 +626,32 @@ public class CompressController {
// Scale factors for different optimization levels
private double getScaleFactorForLevel(int optimizeLevel) {
return switch (optimizeLevel) {
case 3 -> 0.85;
case 4 -> 0.75;
case 5 -> 0.65;
case 6 -> 0.55;
case 7 -> 0.45;
case 8 -> 0.35;
case 9 -> 0.25;
case 10 -> 0.15;
default -> 1.0;
};
return switch (optimizeLevel) {
case 3 -> 0.85;
case 4 -> 0.75;
case 5 -> 0.65;
case 6 -> 0.55;
case 7 -> 0.45;
case 8 -> 0.35;
case 9 -> 0.25;
case 10 -> 0.15;
default -> 1.0;
};
}
// JPEG quality for different optimization levels
private float getJpegQualityForLevel(int optimizeLevel) {
return switch (optimizeLevel) {
case 3 -> 0.85f;
case 4 -> 0.80f;
case 5 -> 0.75f;
case 6 -> 0.70f;
case 7 -> 0.60f;
case 8 -> 0.50f;
case 9 -> 0.35f;
case 10 -> 0.2f;
default -> 0.7f;
};
return switch (optimizeLevel) {
case 3 -> 0.85f;
case 4 -> 0.80f;
case 5 -> 0.75f;
case 6 -> 0.70f;
case 7 -> 0.60f;
case 8 -> 0.50f;
case 9 -> 0.35f;
case 10 -> 0.2f;
default -> 0.7f;
};
}
@PostMapping(consumes = "multipart/form-data", value = "/compress-pdf")

View File

@ -18,14 +18,13 @@ import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
@ -58,24 +57,11 @@ public class ExtractImageScansController {
+ " minimum contour area, and border size. Input:PDF Output:IMAGE/ZIP"
+ " Type:SIMO")
public ResponseEntity<byte[]> extractImageScans(
@RequestBody(
description = "Form data containing file and extraction parameters",
required = true,
content =
@Content(
mediaType = "multipart/form-data",
schema =
@Schema(
implementation =
ExtractImageScansRequest
.class) // This should
// represent
// your form's
// structure
))
ExtractImageScansRequest form)
@ModelAttribute ExtractImageScansRequest request)
throws IOException, InterruptedException {
String fileName = form.getFileInput().getOriginalFilename();
MultipartFile inputFile = request.getFileInput();
String fileName = inputFile.getOriginalFilename();
String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
List<String> images = new ArrayList<>();
@ -94,7 +80,7 @@ public class ExtractImageScansController {
// Check if input file is a PDF
if ("pdf".equalsIgnoreCase(extension)) {
// Load PDF document
try (PDDocument document = pdfDocumentFactory.load(form.getFileInput())) {
try (PDDocument document = pdfDocumentFactory.load(inputFile)) {
PDFRenderer pdfRenderer = new PDFRenderer(document);
pdfRenderer.setSubsamplingAllowed(true);
int pageCount = document.getNumberOfPages();
@ -116,7 +102,7 @@ public class ExtractImageScansController {
}
} else {
tempInputFile = Files.createTempFile("input_", "." + extension);
form.getFileInput().transferTo(tempInputFile);
inputFile.transferTo(tempInputFile);
// Add input file path to images list
images.add(tempInputFile.toString());
}
@ -136,15 +122,15 @@ public class ExtractImageScansController {
images.get(i),
tempDir.toString(),
"--angle_threshold",
String.valueOf(form.getAngleThreshold()),
String.valueOf(request.getAngleThreshold()),
"--tolerance",
String.valueOf(form.getTolerance()),
String.valueOf(request.getTolerance()),
"--min_area",
String.valueOf(form.getMinArea()),
String.valueOf(request.getMinArea()),
"--min_contour_area",
String.valueOf(form.getMinContourArea()),
String.valueOf(request.getMinContourArea()),
"--border_size",
String.valueOf(form.getBorderSize())));
String.valueOf(request.getBorderSize())));
// Run CLI command
ProcessExecutorResult returnCode =

View File

@ -64,7 +64,7 @@ public class ExtractImagesController {
throws IOException, InterruptedException, ExecutionException {
MultipartFile file = request.getFileInput();
String format = request.getFormat();
boolean allowDuplicates = request.isAllowDuplicates();
boolean allowDuplicates = Boolean.TRUE.equals(request.getAllowDuplicates());
PDDocument document = pdfDocumentFactory.load(file);
// Determine if multithreading should be used based on PDF size or number of pages

View File

@ -65,7 +65,7 @@ public class MetadataController {
MultipartFile pdfFile = request.getFileInput();
// Extract metadata information
Boolean deleteAll = request.isDeleteAll();
boolean deleteAll = Boolean.TRUE.equals(request.getDeleteAll());
String author = request.getAuthor();
String creationDate = request.getCreationDate();
String creator = request.getCreator();

View File

@ -43,7 +43,7 @@ public class OverlayImageController {
MultipartFile imageFile = request.getImageFile();
float x = request.getX();
float y = request.getY();
boolean everyPage = request.isEveryPage();
boolean everyPage = Boolean.TRUE.equals(request.getEveryPage());
try {
byte[] pdfBytes = pdfFile.getBytes();
byte[] imageBytes = imageFile.getBytes();

View File

@ -49,33 +49,30 @@ public class PageNumbersController {
MultipartFile file = request.getFileInput();
String customMargin = request.getCustomMargin();
int position = request.getPosition();
int startingNumber = request.getStartingNumber();
int pageNumber = request.getStartingNumber();
String pagesToNumber = request.getPagesToNumber();
String customText = request.getCustomText();
int pageNumber = startingNumber;
float fontSize = request.getFontSize();
String fontType = request.getFontType();
PDDocument document = pdfDocumentFactory.load(file);
float font_size = request.getFontSize();
String font_type = request.getFontType();
float marginFactor;
switch (customMargin.toLowerCase()) {
case "small":
marginFactor = 0.02f;
break;
case "medium":
marginFactor = 0.035f;
break;
case "large":
marginFactor = 0.05f;
break;
case "x-large":
marginFactor = 0.075f;
break;
case "medium":
default:
marginFactor = 0.035f;
break;
}
float fontSize = font_size;
if (pagesToNumber == null || pagesToNumber.isEmpty()) {
pagesToNumber = "all";
}
@ -99,7 +96,7 @@ public class PageNumbersController {
.replaceFirst("[.][^.]+$", ""));
PDType1Font currentFont =
switch (font_type.toLowerCase()) {
switch (fontType.toLowerCase()) {
case "courier" -> new PDType1Font(Standard14Fonts.FontName.COURIER);
case "times" -> new PDType1Font(Standard14Fonts.FontName.TIMES_ROMAN);
default -> new PDType1Font(Standard14Fonts.FontName.HELVETICA);

View File

@ -40,9 +40,9 @@ public class RepairController {
"This endpoint repairs a given PDF file by running qpdf command. The PDF is"
+ " first saved to a temporary location, repaired, read back, and then"
+ " returned as a response. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> repairPdf(@ModelAttribute PDFFile request)
public ResponseEntity<byte[]> repairPdf(@ModelAttribute PDFFile file)
throws IOException, InterruptedException {
MultipartFile inputFile = request.getFileInput();
MultipartFile inputFile = file.getFileInput();
// Save the uploaded file to a temporary location
Path tempInputFile = Files.createTempFile("input_", ".pdf");
byte[] pdfBytes = null;

View File

@ -31,18 +31,18 @@ public class ReplaceAndInvertColorController {
@Operation(
summary = "Replace-Invert Color PDF",
description =
"This endpoint accepts a PDF file and option of invert all colors or replace text and background colors. Input:PDF Output:PDF Type:SISO")
"This endpoint accepts a PDF file and option of invert all colors or replace"
+ " text and background colors. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<InputStreamResource> replaceAndInvertColor(
@ModelAttribute ReplaceAndInvertColorRequest replaceAndInvertColorRequest)
throws IOException {
@ModelAttribute ReplaceAndInvertColorRequest request) throws IOException {
InputStreamResource resource =
replaceAndInvertColorService.replaceAndInvertColor(
replaceAndInvertColorRequest.getFileInput(),
replaceAndInvertColorRequest.getReplaceAndInvertOption(),
replaceAndInvertColorRequest.getHighContrastColorCombination(),
replaceAndInvertColorRequest.getBackGroundColor(),
replaceAndInvertColorRequest.getTextColor());
request.getFileInput(),
request.getReplaceAndInvertOption(),
request.getHighContrastColorCombination(),
request.getBackGroundColor(),
request.getTextColor());
// Return the modified PDF as a downloadable file
return ResponseEntity.ok()

View File

@ -36,8 +36,8 @@ public class ShowJavascript {
@Operation(
summary = "Grabs all JS from a PDF and returns a single JS file with all code",
description = "desc. Input:PDF Output:JS Type:SISO")
public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile request) throws Exception {
MultipartFile inputFile = request.getFileInput();
public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile file) throws Exception {
MultipartFile inputFile = file.getFileInput();
String script = "";
try (PDDocument document = pdfDocumentFactory.load(inputFile)) {

View File

@ -146,8 +146,8 @@ public class CertSignController {
summary = "Sign PDF with a Digital Certificate",
description =
"This endpoint accepts a PDF file, a digital certificate and related"
+ " information to sign the PDF. It then returns the digitally signed PDF"
+ " file. Input:PDF Output:PDF Type:SISO")
+ " information to sign the PDF. It then returns the digitally signed PDF"
+ " file. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> signPDFWithCert(@ModelAttribute SignPDFWithCertRequest request)
throws Exception {
MultipartFile pdf = request.getFileInput();

View File

@ -622,8 +622,8 @@ public class GetInfoOnPDF {
permissionsNode.put("Document Assembly", getPermissionState(ap.canAssembleDocument()));
permissionsNode.put("Extracting Content", getPermissionState(ap.canExtractContent()));
permissionsNode.put(
"Extracting for accessibility",
getPermissionState(ap.canExtractForAccessibility()));
"Extracting for accessibility",
getPermissionState(ap.canExtractForAccessibility()));
permissionsNode.put("Form Filling", getPermissionState(ap.canFillInForm()));
permissionsNode.put("Modifying", getPermissionState(ap.canModify()));
permissionsNode.put("Modifying annotations", getPermissionState(ap.canModifyAnnotations()));

View File

@ -63,14 +63,16 @@ public class PasswordController {
String ownerPassword = request.getOwnerPassword();
String password = request.getPassword();
int keyLength = request.getKeyLength();
boolean preventAssembly = request.isPreventAssembly();
boolean preventExtractContent = request.isPreventExtractContent();
boolean preventExtractForAccessibility = request.isPreventExtractForAccessibility();
boolean preventFillInForm = request.isPreventFillInForm();
boolean preventModify = request.isPreventModify();
boolean preventModifyAnnotations = request.isPreventModifyAnnotations();
boolean preventPrinting = request.isPreventPrinting();
boolean preventPrintingFaithful = request.isPreventPrintingFaithful();
boolean preventAssembly = Boolean.TRUE.equals(request.getPreventAssembly());
boolean preventExtractContent = Boolean.TRUE.equals(request.getPreventExtractContent());
boolean preventExtractForAccessibility =
Boolean.TRUE.equals(request.getPreventExtractForAccessibility());
boolean preventFillInForm = Boolean.TRUE.equals(request.getPreventFillInForm());
boolean preventModify = Boolean.TRUE.equals(request.getPreventModify());
boolean preventModifyAnnotations =
Boolean.TRUE.equals(request.getPreventModifyAnnotations());
boolean preventPrinting = Boolean.TRUE.equals(request.getPreventPrinting());
boolean preventPrintingFaithful = Boolean.TRUE.equals(request.getPreventPrintingFaithful());
PDDocument document = pdfDocumentFactory.load(fileInput);
AccessPermission ap = new AccessPermission();

View File

@ -75,7 +75,7 @@ public class RedactController {
redactPages(request, document, allPages);
redactAreas(redactionAreas, document, allPages);
if (request.isConvertPDFToImage()) {
if (Boolean.TRUE.equals(request.getConvertPDFToImage())) {
PDDocument convertedPdf = PdfUtils.convertPdfToPdfImage(document);
document.close();
document = convertedPdf;
@ -180,7 +180,6 @@ public class RedactController {
}
}
private List<Integer> getPageNumbers(ManualRedactPdfRequest request, int pagesCount) {
String pageNumbersInput = request.getPageNumbers();
String[] parsedPageNumbers =
@ -201,11 +200,11 @@ public class RedactController {
throws Exception {
MultipartFile file = request.getFileInput();
String listOfTextString = request.getListOfText();
boolean useRegex = request.isUseRegex();
boolean wholeWordSearchBool = request.isWholeWordSearch();
boolean useRegex = Boolean.TRUE.equals(request.getUseRegex());
boolean wholeWordSearchBool = Boolean.TRUE.equals(request.getWholeWordSearch());
String colorString = request.getRedactColor();
float customPadding = request.getCustomPadding();
boolean convertPDFToImage = request.isConvertPDFToImage();
boolean convertPDFToImage = Boolean.TRUE.equals(request.getConvertPDFToImage());
String[] listOfText = listOfTextString.split("\n");
PDDocument document = pdfDocumentFactory.load(file);

View File

@ -46,12 +46,12 @@ public class SanitizeController {
public ResponseEntity<byte[]> sanitizePDF(@ModelAttribute SanitizePdfRequest request)
throws IOException {
MultipartFile inputFile = request.getFileInput();
boolean removeJavaScript = request.isRemoveJavaScript();
boolean removeEmbeddedFiles = request.isRemoveEmbeddedFiles();
boolean removeXMPMetadata = request.isRemoveXMPMetadata();
boolean removeMetadata = request.isRemoveMetadata();
boolean removeLinks = request.isRemoveLinks();
boolean removeFonts = request.isRemoveFonts();
boolean removeJavaScript = Boolean.TRUE.equals(request.getRemoveJavaScript());
boolean removeEmbeddedFiles = Boolean.TRUE.equals(request.getRemoveEmbeddedFiles());
boolean removeXMPMetadata = Boolean.TRUE.equals(request.getRemoveXMPMetadata());
boolean removeMetadata = Boolean.TRUE.equals(request.getRemoveMetadata());
boolean removeLinks = Boolean.TRUE.equals(request.getRemoveLinks());
boolean removeFonts = Boolean.TRUE.equals(request.getRemoveFonts());
PDDocument document = pdfDocumentFactory.load(inputFile, true);
if (removeJavaScript) {

View File

@ -1,5 +1,6 @@
package stirling.software.SPDF.controller.api.security;
import java.beans.PropertyEditorSupport;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.cert.CertificateException;
@ -23,6 +24,8 @@ import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
import org.bouncycastle.util.Store;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -48,6 +51,18 @@ public class ValidateSignatureController {
private final CustomPDFDocumentFactory pdfDocumentFactory;
private final CertificateValidationService certValidationService;
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(
MultipartFile.class,
new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(null);
}
});
}
@Operation(
summary = "Validate PDF Digital Signature",
description =
@ -58,12 +73,12 @@ public class ValidateSignatureController {
@ModelAttribute SignatureValidationRequest request) throws IOException {
List<SignatureValidationResult> results = new ArrayList<>();
MultipartFile file = request.getFileInput();
MultipartFile certFile = request.getCertFile();
// Load custom certificate if provided
X509Certificate customCert = null;
if (request.getCertFile() != null && !request.getCertFile().isEmpty()) {
try (ByteArrayInputStream certStream =
new ByteArrayInputStream(request.getCertFile().getBytes())) {
if (certFile != null && !certFile.isEmpty()) {
try (ByteArrayInputStream certStream = new ByteArrayInputStream(certFile.getBytes())) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
customCert = (X509Certificate) cf.generateCertificate(certStream);
} catch (CertificateException e) {

View File

@ -2,6 +2,7 @@ package stirling.software.SPDF.controller.api.security;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.beans.PropertyEditorSupport;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -24,6 +25,8 @@ import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
import org.apache.pdfbox.util.Matrix;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -49,6 +52,18 @@ public class WatermarkController {
private final CustomPDFDocumentFactory pdfDocumentFactory;
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.registerCustomEditor(
MultipartFile.class,
new PropertyEditorSupport() {
@Override
public void setAsText(String text) throws IllegalArgumentException {
setValue(null);
}
});
}
@PostMapping(consumes = "multipart/form-data", value = "/add-watermark")
@Operation(
summary = "Add watermark to a PDF file",
@ -69,7 +84,7 @@ public class WatermarkController {
int widthSpacer = request.getWidthSpacer();
int heightSpacer = request.getHeightSpacer();
String customColor = request.getCustomColor();
boolean convertPdfToImage = request.isConvertPDFToImage();
boolean convertPdfToImage = Boolean.TRUE.equals(request.getConvertPDFToImage());
// Load the input PDF
PDDocument document = pdfDocumentFactory.load(pdfFile);

View File

@ -4,7 +4,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

View File

@ -11,6 +11,9 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class GeneralFile {
@Schema(description = "The input file")
@Schema(
description = "The input file",
requiredMode = Schema.RequiredMode.REQUIRED,
format = "binary")
private MultipartFile fileInput;
}

View File

@ -11,9 +11,12 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class HandleDataRequest {
@Schema(description = "The input files")
@Schema(description = "The input files", requiredMode = Schema.RequiredMode.REQUIRED)
private MultipartFile[] fileInput;
@Schema(description = "JSON String")
@Schema(
description = "JSON String",
defaultValue = "{}",
requiredMode = Schema.RequiredMode.REQUIRED)
private String json;
}

View File

@ -10,6 +10,9 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
public class ImageFile {
@Schema(description = "The input image file")
@Schema(
description = "The input image file",
requiredMode = Schema.RequiredMode.REQUIRED,
format = "binary")
private MultipartFile fileInput;
}

View File

@ -10,6 +10,6 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
public class MultiplePDFFiles {
@Schema(description = "The input PDF files", type = "array", format = "binary")
@Schema(description = "The input PDF files", requiredMode = Schema.RequiredMode.REQUIRED)
private MultipartFile[] fileInput;
}

View File

@ -11,6 +11,7 @@ public class PDFComparison extends PDFFile {
@Schema(
description = "The comparison type, accepts Greater, Equal, Less than",
allowableValues = {"Greater", "Equal", "Less"})
allowableValues = {"Greater", "Equal", "Less"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String comparator;
}

View File

@ -8,6 +8,6 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class PDFComparisonAndCount extends PDFComparison {
@Schema(description = "Count")
private String pageCount;
@Schema(description = "Count", requiredMode = Schema.RequiredMode.REQUIRED, defaultValue = "0")
private int pageCount;
}

View File

@ -11,6 +11,8 @@ public class PDFExtractImagesRequest extends PDFWithImageFormatRequest {
@Schema(
description =
"Boolean to enable/disable the saving of duplicate images, true to enable duplicates")
private boolean allowDuplicates;
"Boolean to enable/disable the saving of duplicate images, true to enable"
+ " duplicates",
defaultValue = "false")
private Boolean allowDuplicates;
}

View File

@ -12,6 +12,10 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@EqualsAndHashCode
public class PDFFile {
@Schema(description = "The input PDF file", format = "binary")
@Schema(
description = "The input PDF file",
requiredMode = Schema.RequiredMode.REQUIRED,
contentMediaType = "application/pdf",
format = "binary")
private MultipartFile fileInput;
}

View File

@ -11,6 +11,8 @@ public class PDFWithImageFormatRequest extends PDFFile {
@Schema(
description = "The output image format e.g., 'png', 'jpeg', or 'gif'",
allowableValues = {"png", "jpeg", "gif"})
allowableValues = {"png", "jpeg", "gif"},
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "png")
private String format;
}

View File

@ -21,9 +21,9 @@ public class PDFWithPageNums extends PDFFile {
description =
"The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the"
+ " format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a"
+ " constant (e.g., '2n+1', '3n', '6n-5')\"",
+ " constant (e.g., '2n+1', '3n', '6n-5')",
defaultValue = "all",
requiredMode = RequiredMode.NOT_REQUIRED)
requiredMode = RequiredMode.REQUIRED)
private String pageNumbers;
@Hidden

View File

@ -11,7 +11,9 @@ public class PDFWithPageSize extends PDFFile {
@Schema(
description =
"The scale of pages in the output PDF. Acceptable values are A0-A6, LETTER, LEGAL, KEEP.",
"The scale of pages in the output PDF. Acceptable values are A0-A6, LETTER,"
+ " LEGAL, KEEP.",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"A0", "A1", "A2", "A3", "A4", "A5", "A6", "LETTER", "LEGAL", "KEEP"})
private String pageSize;
}

View File

@ -8,12 +8,22 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = false)
public class SplitPdfByChaptersRequest extends PDFFile {
@Schema(description = "Whether to include Metadata or not", example = "true")
@Schema(
description = "Whether to include Metadata or not",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean includeMetadata;
@Schema(description = "Whether to allow duplicates or not", example = "true")
@Schema(
description = "Whether to allow duplicates or not",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean allowDuplicates;
@Schema(description = "Maximum bookmark level required", example = "2")
@Schema(
description = "Maximum bookmark level required",
minimum = "0",
defaultValue = "2",
requiredMode = Schema.RequiredMode.REQUIRED)
private Integer bookmarkLevel;
}

View File

@ -8,12 +8,23 @@ import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class SplitPdfBySectionsRequest extends PDFFile {
@Schema(description = "Number of horizontal divisions for each PDF page", example = "2")
@Schema(
description = "Number of horizontal divisions for each PDF page",
defaultValue = "0",
minimum = "0",
requiredMode = Schema.RequiredMode.REQUIRED)
private int horizontalDivisions;
@Schema(description = "Number of vertical divisions for each PDF page", example = "2")
@Schema(
description = "Number of vertical divisions for each PDF page",
defaultValue = "1",
minimum = "0",
requiredMode = Schema.RequiredMode.REQUIRED)
private int verticalDivisions;
@Schema(description = "Merge the split documents into a single PDF", example = "true")
private boolean merge;
@Schema(
description = "Merge the split documents into a single PDF",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean merge;
}

View File

@ -23,9 +23,9 @@ public class ConvertPDFToMarkdown {
summary = "Convert PDF to Markdown",
description =
"This endpoint converts a PDF file to Markdown format. Input:PDF Output:Markdown Type:SISO")
public ResponseEntity<byte[]> processPdfToMarkdown(@ModelAttribute PDFFile request)
public ResponseEntity<byte[]> processPdfToMarkdown(@ModelAttribute PDFFile file)
throws Exception {
MultipartFile inputFile = request.getFileInput();
MultipartFile inputFile = file.getFileInput();
PDFToFile pdfToFile = new PDFToFile();
return pdfToFile.processPdfToMarkdown(inputFile);
}

View File

@ -5,33 +5,38 @@ import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import stirling.software.SPDF.model.api.PDFFile;
import stirling.software.SPDF.model.api.PDFWithPageNums;
@Data
@EqualsAndHashCode(callSuper = true)
public class ConvertToImageRequest extends PDFFile {
public class ConvertToImageRequest extends PDFWithPageNums {
@Schema(
description = "The output image format",
allowableValues = {"png", "jpeg", "jpg", "gif", "webp"})
defaultValue = "png",
allowableValues = {"png", "jpeg", "jpg", "gif", "webp"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String imageFormat;
@Schema(
description =
"Choose between a single image containing all pages or separate images for each page",
allowableValues = {"single", "multiple"})
"Choose between a single image containing all pages or separate images for each"
+ " page",
defaultValue = "multiple",
allowableValues = {"single", "multiple"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String singleOrMultiple;
@Schema(
description =
"The pages to select, Supports ranges (e.g., '1,3,5-9'), or 'all' or functions in the format 'an+b' where 'a' is the multiplier of the page number 'n', and 'b' is a constant (e.g., '2n+1', '3n', '6n-5')\"")
private String pageNumbers;
@Schema(
description = "The color type of the output image(s)",
allowableValues = {"color", "greyscale", "blackwhite"})
defaultValue = "color",
allowableValues = {"color", "greyscale", "blackwhite"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String colorType;
@Schema(description = "The DPI (dots per inch) for the output image(s)")
private String dpi;
@Schema(
description = "The DPI (dots per inch) for the output image(s)",
defaultValue = "300",
requiredMode = Schema.RequiredMode.REQUIRED)
private Integer dpi;
}

View File

@ -11,21 +11,28 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class ConvertToPdfRequest {
@Schema(description = "The input images to be converted to a PDF file")
@Schema(
description = "The input images to be converted to a PDF file",
requiredMode = Schema.RequiredMode.REQUIRED)
private MultipartFile[] fileInput;
@Schema(
description = "Option to determine how the image will fit onto the page",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "fillPage",
allowableValues = {"fillPage", "fitDocumentToImage", "maintainAspectRatio"})
private String fitOption;
@Schema(
description = "The color type of the output image(s)",
defaultValue = "color",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"color", "greyscale", "blackwhite"})
private String colorType;
@Schema(
description = "Whether to automatically rotate the images to better fit the PDF page",
example = "true")
private boolean autoRotate;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean autoRotate;
}

View File

@ -13,6 +13,7 @@ public class HTMLToPdfRequest extends PDFFile {
@Schema(
description = "Zoom level for displaying the website. Default is '1'.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "1")
private float zoom;
}

View File

@ -13,6 +13,7 @@ public class PdfToBookRequest extends PDFFile {
@Schema(
description = "The output Ebook format",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {
"epub", "mobi", "azw3", "docx", "rtf", "txt", "html", "lit", "fb2", "pdb", "lrf"
})

View File

@ -13,6 +13,7 @@ public class PdfToPdfARequest extends PDFFile {
@Schema(
description = "The output PDF/A type",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"pdfa", "pdfa-1"})
private String outputFormat;
}

View File

@ -13,6 +13,7 @@ public class PdfToPresentationRequest extends PDFFile {
@Schema(
description = "The output Presentation format",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"ppt", "pptx", "odp"})
private String outputFormat;
}

View File

@ -13,6 +13,7 @@ public class PdfToTextOrRTFRequest extends PDFFile {
@Schema(
description = "The output Text or RTF format",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"rtf", "txt"})
private String outputFormat;
}

View File

@ -13,6 +13,7 @@ public class PdfToWordRequest extends PDFFile {
@Schema(
description = "The output Word document format",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"doc", "docx", "odt"})
private String outputFormat;
}

View File

@ -11,6 +11,9 @@ import stirling.software.SPDF.model.api.PDFWithPageNums;
@EqualsAndHashCode(callSuper = true)
public class ContainsTextRequest extends PDFWithPageNums {
@Schema(description = "The text to check for", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(
description = "The text to check for",
defaultValue = "text",
requiredMode = Schema.RequiredMode.REQUIRED)
private String text;
}

View File

@ -11,6 +11,9 @@ import stirling.software.SPDF.model.api.PDFComparison;
@EqualsAndHashCode(callSuper = true)
public class FileSizeRequest extends PDFComparison {
@Schema(description = "File Size", requiredMode = Schema.RequiredMode.REQUIRED)
private String fileSize;
@Schema(
description = "Size of the file in bytes",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "0")
private long fileSize;
}

View File

@ -11,6 +11,9 @@ import stirling.software.SPDF.model.api.PDFComparison;
@EqualsAndHashCode(callSuper = true)
public class PageRotationRequest extends PDFComparison {
@Schema(description = "Rotation in degrees", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(
description = "Rotation in degrees",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "0")
private int rotation;
}

View File

@ -11,6 +11,10 @@ import stirling.software.SPDF.model.api.PDFComparison;
@EqualsAndHashCode(callSuper = true)
public class PageSizeRequest extends PDFComparison {
@Schema(description = "Standard Page Size", requiredMode = Schema.RequiredMode.REQUIRED)
@Schema(
description = "Standard Page Size",
allowableValues = {"A0", "A1", "A2", "A3", "A4", "A5", "A6", "LETTER", "LEGAL"},
defaultValue = "A4",
requiredMode = Schema.RequiredMode.REQUIRED)
private String standardPageSize;
}

View File

@ -13,10 +13,12 @@ public class MergeMultiplePagesRequest extends PDFFile {
@Schema(
description = "The number of pages to fit onto a single sheet in the output PDF.",
type = "integer",
type = "number",
defaultValue = "2",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"2", "3", "4", "9", "16"})
private int pagesPerSheet;
@Schema(description = "Boolean for if you wish to add border around the pages")
private boolean addBorder;
private Boolean addBorder;
}

View File

@ -20,12 +20,16 @@ public class MergePdfsRequest extends MultiplePDFFiles {
"byDateCreated",
"byPDFTitle"
},
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "orderProvided")
private String sortType = "orderProvided";
@Schema(
description =
"Flag indicating whether to remove certification signatures from the merged PDF. If true, all certification signatures will be removed from the final merged document.",
example = "true")
private boolean isRemoveCertSign;
"Flag indicating whether to remove certification signatures from the merged"
+ " PDF. If true, all certification signatures will be removed from the"
+ " final merged document.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "true")
private Boolean removeCertSign;
}

View File

@ -15,21 +15,32 @@ public class OverlayPdfsRequest extends PDFFile {
@Schema(
description =
"An array of PDF files to be used as overlays on the base PDF. The order in these files is applied based on the selected mode.")
"An array of PDF files to be used as overlays on the base PDF. The order in"
+ " these files is applied based on the selected mode.",
requiredMode = Schema.RequiredMode.REQUIRED)
private MultipartFile[] overlayFiles;
@Schema(
description =
"The mode of overlaying: 'SequentialOverlay' for sequential application, 'InterleavedOverlay' for round-robin application, 'FixedRepeatOverlay' for fixed repetition based on provided counts",
"The mode of overlaying: 'SequentialOverlay' for sequential application,"
+ " 'InterleavedOverlay' for round-robin application, 'FixedRepeatOverlay'"
+ " for fixed repetition based on provided counts",
allowableValues = {"SequentialOverlay", "InterleavedOverlay", "FixedRepeatOverlay"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String overlayMode;
@Schema(
description =
"An array of integers specifying the number of times each corresponding overlay file should be applied in the 'FixedRepeatOverlay' mode. This should match the length of the overlayFiles array.",
"An array of integers specifying the number of times each corresponding overlay"
+ " file should be applied in the 'FixedRepeatOverlay' mode. This should"
+ " match the length of the overlayFiles array.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private int[] counts;
@Schema(description = "Overlay position 0 is Foregound, 1 is Background")
@Schema(
description = "Overlay position 0 is Foregound, 1 is Background",
allowableValues = {"0", "1"},
requiredMode = Schema.RequiredMode.REQUIRED,
type = "number")
private int overlayPosition;
}

View File

@ -14,6 +14,8 @@ public class RotatePDFRequest extends PDFFile {
@Schema(
description =
"The angle by which to rotate the PDF file. This should be a multiple of 90.",
example = "90")
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"0", "90", "180", "270"},
defaultValue = "90")
private Integer angle;
}

View File

@ -12,7 +12,11 @@ import stirling.software.SPDF.model.api.PDFWithPageSize;
public class ScalePagesRequest extends PDFWithPageSize {
@Schema(
minimum = "0",
defaultValue = "1",
requiredMode = Schema.RequiredMode.REQUIRED,
description =
"The scale of the content on the pages of the output PDF. Acceptable values are floats.")
"The scale of the content on the pages of the output PDF. Acceptable values are"
+ " floats.")
private float scaleFactor;
}

View File

@ -22,6 +22,7 @@ public class AddPageNumbersRequest extends PDFWithPageNums {
@Schema(
description = "Font size for page numbers",
minimum = "1",
defaultValue = "12",
requiredMode = RequiredMode.REQUIRED)
private float fontSize;
@ -33,15 +34,18 @@ public class AddPageNumbersRequest extends PDFWithPageNums {
@Schema(
description =
"Position: 1-9 representing positions on the page (1=top-left, 5=center, 9=bottom-right)",
minimum = "1",
maximum = "9",
"Position: 1-9 representing positions on the page (1=top-left, 2=top-center,"
+ " 3=top-right, 4=middle-left, 5=middle-center, 6=middle-right,"
+ " 7=bottom-left, 8=bottom-center, 9=bottom-right)",
allowableValues = {"1", "2", "3", "4", "5", "6", "7", "8", "9"},
defaultValue = "8",
requiredMode = RequiredMode.REQUIRED)
private int position;
@Schema(
description = "Starting number for page numbering",
minimum = "1",
defaultValue = "1",
requiredMode = RequiredMode.REQUIRED)
private int startingNumber;
@ -53,7 +57,8 @@ public class AddPageNumbersRequest extends PDFWithPageNums {
@Schema(
description =
"Custom text pattern. Available variables: {n}=current page number, {total}=total pages, {filename}=original filename",
"Custom text pattern. Available variables: {n}=current page number,"
+ " {total}=total pages, {filename}=original filename",
example = "Page {n} of {total}",
defaultValue = "{n}",
requiredMode = RequiredMode.NOT_REQUIRED)

View File

@ -19,51 +19,69 @@ public class AddStampRequest extends PDFWithPageNums {
requiredMode = Schema.RequiredMode.REQUIRED)
private String stampType;
@Schema(description = "The stamp text")
@Schema(description = "The stamp text", defaultValue = "Stirling Software")
private String stampText;
@Schema(description = "The stamp image")
private MultipartFile stampImage;
@Schema(
description = "The selected alphabet",
description = "The selected alphabet of the stamp text",
allowableValues = {"roman", "arabic", "japanese", "korean", "chinese"},
defaultValue = "roman")
private String alphabet = "roman";
@Schema(description = "The font size of the stamp text", example = "30")
private float fontSize = 30;
@Schema(
description = "The font size of the stamp text and image",
defaultValue = "30",
requiredMode = Schema.RequiredMode.REQUIRED)
private float fontSize;
@Schema(description = "The rotation of the stamp in degrees", example = "0")
private float rotation = 0;
@Schema(
description = "The rotation of the stamp in degrees",
defaultValue = "0",
requiredMode = Schema.RequiredMode.REQUIRED)
private float rotation;
@Schema(description = "The opacity of the stamp (0.0 - 1.0)", example = "0.5")
@Schema(
description = "The opacity of the stamp (0.0 - 1.0)",
defaultValue = "0.5",
requiredMode = Schema.RequiredMode.REQUIRED)
private float opacity;
@Schema(
description =
"Position for stamp placement based on a 1-9 grid (1: bottom-left, 2: bottom-center, ..., 9: top-right)",
example = "1")
"Position for stamp placement based on a 1-9 grid (1: bottom-left, 2: bottom-center,"
+ " 3: bottom-right, 4: middle-left, 5: middle-center, 6: middle-right,"
+ " 7: top-left, 8: top-center, 9: top-right)",
allowableValues = {"1", "2", "3", "4", "5", "6", "7", "8", "9"},
defaultValue = "5",
requiredMode = Schema.RequiredMode.REQUIRED)
private int position;
@Schema(
description =
"Override X coordinate for stamp placement. If set, it will override the position-based calculation. Negative value means no override.",
example = "-1")
private float overrideX = -1; // Default to -1 indicating no override
"Override X coordinate for stamp placement. If set, it will override the"
+ " position-based calculation. Negative value means no override.",
defaultValue = "-1",
requiredMode = Schema.RequiredMode.REQUIRED)
private float overrideX; // Default to -1 indicating no override
@Schema(
description =
"Override Y coordinate for stamp placement. If set, it will override the position-based calculation. Negative value means no override.",
example = "-1")
private float overrideY = -1; // Default to -1 indicating no override
"Override Y coordinate for stamp placement. If set, it will override the"
+ " position-based calculation. Negative value means no override.",
defaultValue = "-1",
requiredMode = Schema.RequiredMode.REQUIRED)
private float overrideY; // Default to -1 indicating no override
@Schema(
description = "Specifies the margin size for the stamp.",
allowableValues = {"small", "medium", "large", "x-large"},
defaultValue = "medium")
private String customMargin = "medium";
defaultValue = "medium",
requiredMode = Schema.RequiredMode.REQUIRED)
private String customMargin;
@Schema(description = "The color for stamp", defaultValue = "#d3d3d3")
private String customColor = "#d3d3d3";
@Schema(description = "The color of the stamp text", defaultValue = "#d3d3d3")
private String customColor;
}

View File

@ -16,5 +16,5 @@ public class AutoSplitPdfRequest extends PDFFile {
"Flag indicating if the duplex mode is active, where the page after the divider also gets removed.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED,
defaultValue = "false")
private boolean duplexMode;
private Boolean duplexMode;
}

View File

@ -16,5 +16,5 @@ public class ExtractHeaderRequest extends PDFFile {
"Flag indicating whether to use the first text as a fallback if no suitable title is found. Defaults to false.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED,
defaultValue = "false")
private boolean useFirstTextAsFallback;
private Boolean useFirstTextAsFallback;
}

View File

@ -12,36 +12,37 @@ import lombok.EqualsAndHashCode;
public class ExtractImageScansRequest {
@Schema(
description = "The input file containing image scans",
requiredMode = Schema.RequiredMode.REQUIRED)
requiredMode = Schema.RequiredMode.REQUIRED,
format = "binary")
private MultipartFile fileInput;
@Schema(
description = "The angle threshold for the image scan extraction",
defaultValue = "5",
example = "5")
private int angleThreshold = 5;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "5")
private int angleThreshold;
@Schema(
description = "The tolerance for the image scan extraction",
defaultValue = "20",
example = "20")
private int tolerance = 20;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "20")
private int tolerance;
@Schema(
description = "The minimum area for the image scan extraction",
defaultValue = "8000",
example = "8000")
private int minArea = 8000;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "8000")
private int minArea;
@Schema(
description = "The minimum contour area for the image scan extraction",
defaultValue = "500",
example = "500")
private int minContourArea = 500;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "500")
private int minContourArea;
@Schema(
description = "The border size for the image scan extraction",
defaultValue = "1",
example = "1")
private int borderSize = 1;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "1")
private int borderSize;
}

View File

@ -13,6 +13,9 @@ public class FlattenRequest extends PDFFile {
@Schema(
description =
"True to flatten only the forms, false to flatten full PDF (Convert page to image)")
"True to flatten only the forms, false to flatten full PDF (Convert page to"
+ " image)",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean flattenOnlyForms;
}

View File

@ -13,38 +13,72 @@ import stirling.software.SPDF.model.api.PDFFile;
@EqualsAndHashCode(callSuper = true)
public class MetadataRequest extends PDFFile {
@Schema(description = "Delete all metadata if set to true")
private boolean deleteAll;
@Schema(
description = "Delete all metadata if set to true",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean deleteAll;
@Schema(description = "The author of the document")
@Schema(
description = "The author of the document",
defaultValue = "author",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String author;
@Schema(description = "The creation date of the document (format: yyyy/MM/dd HH:mm:ss)")
@Schema(
description = "The creation date of the document (format: yyyy/MM/dd HH:mm:ss)",
pattern = "yyyy/MM/dd HH:mm:ss",
defaultValue = "2023/10/01 12:00:00",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String creationDate;
@Schema(description = "The creator of the document")
@Schema(
description = "The creator of the document",
defaultValue = "creator",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String creator;
@Schema(description = "The keywords for the document")
@Schema(
description = "The keywords for the document",
defaultValue = "keywords",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String keywords;
@Schema(description = "The modification date of the document (format: yyyy/MM/dd HH:mm:ss)")
@Schema(
description = "The modification date of the document (format: yyyy/MM/dd HH:mm:ss)",
pattern = "yyyy/MM/dd HH:mm:ss",
defaultValue = "2023/10/01 12:00:00",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String modificationDate;
@Schema(description = "The producer of the document")
@Schema(
description = "The producer of the document",
defaultValue = "producer",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String producer;
@Schema(description = "The subject of the document")
@Schema(
description = "The subject of the document",
defaultValue = "subject",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String subject;
@Schema(description = "The title of the document")
@Schema(
description = "The title of the document",
defaultValue = "title",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String title;
@Schema(description = "The trapped status of the document")
@Schema(
description = "The trapped status of the document",
defaultValue = "False",
allowableValues = {"True", "False", "Unknown"},
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String trapped;
@Schema(
description =
"Map list of key and value of custom parameters. Note these must start with customKey and customValue if they are non-standard")
"Map list of key and value of custom parameters. Note these must start with"
+ " customKey and customValue if they are non-standard")
private Map<String, String> allRequestParams;
}

View File

@ -13,30 +13,36 @@ public class OptimizePdfRequest extends PDFFile {
@Schema(
description =
"The level of optimization to apply to the PDF file. Higher values indicate greater compression but may reduce quality.",
"The level of optimization to apply to the PDF file. Higher values indicate"
+ " greater compression but may reduce quality.",
defaultValue = "5",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"1", "2", "3", "4", "5", "6", "7", "8", "9"})
private Integer optimizeLevel;
@Schema(description = "The expected output size, e.g. '100MB', '25KB', etc.")
@Schema(
description = "The expected output size, e.g. '100MB', '25KB', etc.",
defaultValue = "25KB",
requiredMode = Schema.RequiredMode.REQUIRED)
private String expectedOutputSize;
@Schema(
description = "Whether to linearize the PDF for faster web viewing. Default is false.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean linearize = false;
@Schema(
description =
"Whether to normalize the PDF content for better compatibility. Default is false.",
"Whether to normalize the PDF content for better compatibility. Default is"
+ " false.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean normalize = false;
@Schema(
description = "Whether to convert the PDF to grayscale. Default is false.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean grayscale = false;
public Boolean getGrayscale() {
return grayscale;
}
}

View File

@ -13,21 +13,27 @@ import stirling.software.SPDF.model.api.PDFFile;
@EqualsAndHashCode(callSuper = true)
public class OverlayImageRequest extends PDFFile {
@Schema(description = "The image file to be overlaid onto the PDF.")
@Schema(
description = "The image file to be overlaid onto the PDF.",
requiredMode = Schema.RequiredMode.REQUIRED,
format = "binary")
private MultipartFile imageFile;
@Schema(
description = "The x-coordinate at which to place the top-left corner of the image.",
example = "0")
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "0")
private float x;
@Schema(
description = "The y-coordinate at which to place the top-left corner of the image.",
example = "0")
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "0")
private float y;
@Schema(
description = "Whether to overlay the image onto every page of the PDF.",
example = "false")
private boolean everyPage;
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "false")
private Boolean everyPage;
}

View File

@ -13,16 +13,21 @@ import stirling.software.SPDF.model.api.PDFFile;
@EqualsAndHashCode(callSuper = true)
public class ProcessPdfWithOcrRequest extends PDFFile {
@Schema(description = "List of languages to use in OCR processing")
@Schema(
description = "List of languages to use in OCR processing, e.g., 'eng', 'deu'",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "[\"eng\"]")
private List<String> languages;
@Schema(
description = "Specify the OCR type, e.g., 'skip-text', 'force-ocr', or 'Normal'",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"skip-text", "force-ocr", "Normal"})
private String ocrType;
@Schema(
description = "Specify the OCR render type, either 'hocr' or 'sandwich'",
requiredMode = Schema.RequiredMode.REQUIRED,
allowableValues = {"hocr", "sandwich"},
defaultValue = "hocr")
private String ocrRenderType = "hocr";

View File

@ -13,13 +13,17 @@ public class RemoveBlankPagesRequest extends PDFFile {
@Schema(
description = "The threshold value to determine blank pages",
example = "10",
requiredMode = Schema.RequiredMode.REQUIRED,
minimum = "0",
maximum = "255",
defaultValue = "10")
private int threshold = 10;
private int threshold;
@Schema(
description = "The percentage of white color on a page to consider it as blank",
example = "99.9",
requiredMode = Schema.RequiredMode.REQUIRED,
minimum = "0.1",
maximum = "100",
defaultValue = "99.9")
private float whitePercent = 99.9f;
private float whitePercent;
}

View File

@ -13,12 +13,16 @@ public class ReplaceAndInvertColorRequest extends PDFFile {
@Schema(
description = "Replace and Invert color options of a pdf.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "HIGH_CONTRAST_COLOR",
allowableValues = {"HIGH_CONTRAST_COLOR", "CUSTOM_COLOR", "FULL_INVERSION"})
private ReplaceAndInvert replaceAndInvertOption;
@Schema(
description =
"If HIGH_CONTRAST_COLOR option selected, then pick the default color option for text and background.",
requiredMode = Schema.RequiredMode.REQUIRED,
defaultValue = "WHITE_TEXT_ON_BLACK",
allowableValues = {
"WHITE_TEXT_ON_BLACK",
"BLACK_TEXT_ON_WHITE",

View File

@ -13,45 +13,50 @@ public class AddPasswordRequest extends PDFFile {
@Schema(
description =
"The owner password to be added to the PDF file (Restricts what can be done with the document once it is opened)",
defaultValue = "")
"The owner password to be added to the PDF file (Restricts what can be done"
+ " with the document once it is opened)",
format = "password")
private String ownerPassword;
@Schema(
description =
"The password to be added to the PDF file (Restricts the opening of the document itself.)",
defaultValue = "")
"The password to be added to the PDF file (Restricts the opening of the"
+ " document itself.)",
format = "password")
private String password;
@Schema(
description = "The length of the encryption key",
allowableValues = {"40", "128", "256"},
defaultValue = "256")
defaultValue = "256",
requiredMode = Schema.RequiredMode.REQUIRED)
private int keyLength = 256;
@Schema(description = "Whether document assembly is prevented", example = "false")
private boolean preventAssembly;
@Schema(description = "Whether document assembly is prevented", defaultValue = "false")
private Boolean preventAssembly;
@Schema(description = "Whether content extraction is prevented", example = "false")
private boolean preventExtractContent;
@Schema(description = "Whether content extraction is prevented", defaultValue = "false")
private Boolean preventExtractContent;
@Schema(
description = "Whether content extraction for accessibility is prevented",
example = "false")
private boolean preventExtractForAccessibility;
defaultValue = "false")
private Boolean preventExtractForAccessibility;
@Schema(description = "Whether form filling is prevented", example = "false")
private boolean preventFillInForm;
@Schema(description = "Whether form filling is prevented", defaultValue = "false")
private Boolean preventFillInForm;
@Schema(description = "Whether document modification is prevented", example = "false")
private boolean preventModify;
@Schema(description = "Whether document modification is prevented", defaultValue = "false")
private Boolean preventModify;
@Schema(description = "Whether modification of annotations is prevented", example = "false")
private boolean preventModifyAnnotations;
@Schema(
description = "Whether modification of annotations is prevented",
defaultValue = "false")
private Boolean preventModifyAnnotations;
@Schema(description = "Whether printing of the document is prevented", example = "false")
private boolean preventPrinting;
@Schema(description = "Whether printing of the document is prevented", defaultValue = "false")
private Boolean preventPrinting;
@Schema(description = "Whether faithful printing is prevented", example = "false")
private boolean preventPrintingFaithful;
@Schema(description = "Whether faithful printing is prevented", defaultValue = "false")
private Boolean preventPrintingFaithful;
}

View File

@ -19,7 +19,7 @@ public class AddWatermarkRequest extends PDFFile {
requiredMode = Schema.RequiredMode.REQUIRED)
private String watermarkType;
@Schema(description = "The watermark text")
@Schema(description = "The watermark text", defaultValue = "Stirling Software")
private String watermarkText;
@Schema(description = "The watermark image")
@ -29,26 +29,29 @@ public class AddWatermarkRequest extends PDFFile {
description = "The selected alphabet",
allowableValues = {"roman", "arabic", "japanese", "korean", "chinese"},
defaultValue = "roman")
private String alphabet = "roman";
private String alphabet;
@Schema(description = "The font size of the watermark text", example = "30")
private float fontSize = 30;
@Schema(description = "The font size of the watermark text", defaultValue = "30")
private float fontSize;
@Schema(description = "The rotation of the watermark in degrees", example = "0")
private float rotation = 0;
@Schema(description = "The rotation of the watermark in degrees", defaultValue = "0")
private float rotation;
@Schema(description = "The opacity of the watermark (0.0 - 1.0)", example = "0.5")
@Schema(description = "The opacity of the watermark (0.0 - 1.0)", defaultValue = "0.5")
private float opacity;
@Schema(description = "The width spacer between watermark elements", example = "50")
@Schema(description = "The width spacer between watermark elements", defaultValue = "50")
private int widthSpacer;
@Schema(description = "The height spacer between watermark elements", example = "50")
@Schema(description = "The height spacer between watermark elements", defaultValue = "50")
private int heightSpacer;
@Schema(description = "The color for watermark", defaultValue = "#d3d3d3")
private String customColor = "#d3d3d3";
private String customColor;
@Schema(description = "Convert the redacted PDF to an image", defaultValue = "false")
private boolean convertPDFToImage;
@Schema(
description = "Convert the redacted PDF to an image",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean convertPDFToImage;
}

View File

@ -12,12 +12,20 @@ import stirling.software.SPDF.model.api.PDFWithPageNums;
@Data
@EqualsAndHashCode(callSuper = true)
public class ManualRedactPdfRequest extends PDFWithPageNums {
@Schema(description = "A list of areas that should be redacted")
@Schema(
description = "A list of areas that should be redacted",
requiredMode = Schema.RequiredMode.REQUIRED)
private List<RedactionArea> redactions;
@Schema(description = "Convert the redacted PDF to an image", defaultValue = "false")
private boolean convertPDFToImage;
@Schema(
description = "Convert the redacted PDF to an image",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean convertPDFToImage;
@Schema(description = "The color used to fully redact certain pages")
@Schema(
description = "The color used to fully redact certain pages",
defaultValue = "#000000",
requiredMode = Schema.RequiredMode.REQUIRED)
private String pageRedactionColor;
}

View File

@ -13,6 +13,7 @@ public class PDFPasswordRequest extends PDFFile {
@Schema(
description = "The password of the PDF file",
requiredMode = Schema.RequiredMode.REQUIRED)
format = "password",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String password;
}

View File

@ -13,22 +13,37 @@ public class RedactPdfRequest extends PDFFile {
@Schema(
description = "List of text to redact from the PDF",
type = "string",
defaultValue = "text,text2",
requiredMode = Schema.RequiredMode.REQUIRED)
private String listOfText;
@Schema(description = "Whether to use regex for the listOfText", defaultValue = "false")
private boolean useRegex;
@Schema(
description = "Whether to use regex for the listOfText",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean useRegex;
@Schema(description = "Whether to use whole word search", defaultValue = "false")
private boolean wholeWordSearch;
@Schema(
description = "Whether to use whole word search",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean wholeWordSearch;
@Schema(description = "Hexadecimal color code for redaction, e.g. #FF0000 or 000000", defaultValue = "#000000")
private String redactColor = "#000000";
@Schema(
description = "The color for redaction",
defaultValue = "#000000",
requiredMode = Schema.RequiredMode.REQUIRED)
private String redactColor;
@Schema(description = "Custom padding for redaction", type = "number")
@Schema(
description = "Custom padding for redaction",
type = "number",
requiredMode = Schema.RequiredMode.REQUIRED)
private float customPadding;
@Schema(description = "Convert the redacted PDF to an image", defaultValue = "false")
private boolean convertPDFToImage;
@Schema(
description = "Convert the redacted PDF to an image",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean convertPDFToImage;
}

View File

@ -3,8 +3,10 @@ package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode
public class RedactionArea {
@Schema(description = "The left edge point of the area to be redacted.")
private Double x;

View File

@ -11,21 +11,39 @@ import stirling.software.SPDF.model.api.PDFFile;
@EqualsAndHashCode(callSuper = true)
public class SanitizePdfRequest extends PDFFile {
@Schema(description = "Remove JavaScript actions from the PDF", defaultValue = "false")
private boolean removeJavaScript;
@Schema(
description = "Remove JavaScript actions from the PDF",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeJavaScript;
@Schema(description = "Remove embedded files from the PDF", defaultValue = "false")
private boolean removeEmbeddedFiles;
@Schema(
description = "Remove embedded files from the PDF",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeEmbeddedFiles;
@Schema(description = "Remove XMP metadata from the PDF", defaultValue = "false")
private boolean removeXMPMetadata;
@Schema(
description = "Remove XMP metadata from the PDF",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeXMPMetadata;
@Schema(description = "Remove document info metadata from the PDF", defaultValue = "false")
private boolean removeMetadata;
@Schema(
description = "Remove document info metadata from the PDF",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeMetadata;
@Schema(description = "Remove links from the PDF", defaultValue = "false")
private boolean removeLinks;
@Schema(
description = "Remove links from the PDF",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeLinks;
@Schema(description = "Remove fonts from the PDF", defaultValue = "false")
private boolean removeFonts;
@Schema(
description = "Remove fonts from the PDF",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean removeFonts;
}

View File

@ -15,7 +15,8 @@ public class SignPDFWithCertRequest extends PDFFile {
@Schema(
description = "The type of the digital certificate",
allowableValues = {"PEM", "PKCS12", "JKS"})
allowableValues = {"PEM", "PKCS12", "JKS"},
requiredMode = Schema.RequiredMode.REQUIRED)
private String certType;
@Schema(
@ -36,24 +37,31 @@ public class SignPDFWithCertRequest extends PDFFile {
@Schema(description = "The password for the keystore or the private key", format = "password")
private String password;
@Schema(description = "Whether to visually show the signature in the PDF file")
@Schema(
description = "Whether to visually show the signature in the PDF file",
defaultValue = "false",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean showSignature;
@Schema(description = "The reason for signing the PDF")
@Schema(description = "The reason for signing the PDF", defaultValue = "Signed by SPDF")
private String reason;
@Schema(description = "The location where the PDF is signed")
@Schema(description = "The location where the PDF is signed", defaultValue = "SPDF")
private String location;
@Schema(description = "The name of the signer")
@Schema(description = "The name of the signer", defaultValue = "SPDF")
private String name;
@Schema(
description =
"The page number where the signature should be visible. This is required if"
+ " showSignature is set to true")
+ " showSignature is set to true",
defaultValue = "1")
private Integer pageNumber;
@Schema(description = "Whether to visually show a signature logo along with the signature")
@Schema(
description = "Whether to visually show a signature logo along with the signature",
defaultValue = "true",
requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean showLogo;
}

View File

@ -13,6 +13,8 @@ import stirling.software.SPDF.model.api.PDFFile;
@EqualsAndHashCode(callSuper = true)
public class SignatureValidationRequest extends PDFFile {
@Schema(description = "(Optional) file to compare PDF cert signatures against x.509 format")
@Schema(
description = "(Optional) file to compare PDF cert signatures against x.509 format",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private MultipartFile certFile;
}

View File

@ -9,6 +9,9 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public class UpdateUserDetails extends UpdateUserUsername {
@Schema(description = "new password for user")
@Schema(
description = "new password for user",
format = "password",
requiredMode = Schema.RequiredMode.REQUIRED)
private String newPassword;
}

View File

@ -9,6 +9,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public class UpdateUserUsername extends UsernameAndPass {
@Schema(description = "new password for user")
@Schema(description = "new username for user")
private String newUsername;
}

View File

@ -9,6 +9,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode
public class Username {
@Schema(description = "username of user")
@Schema(description = "username of user", requiredMode = Schema.RequiredMode.REQUIRED)
private String username;
}

View File

@ -9,6 +9,6 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
public class UsernameAndPass extends Username {
@Schema(description = "password of user")
@Schema(description = "password of user", format = "password")
private String password;
}

View File

@ -28,8 +28,7 @@ public class LanguageService {
public Set<String> getSupportedLanguages() {
try {
Resource[] resources =
resourcePatternResolver.getResources("classpath*:messages_*.properties");
Resource[] resources = getResourcesFromPattern("classpath*:messages_*.properties");
return Arrays.stream(resources)
.map(Resource::getFilename)
@ -54,4 +53,9 @@ public class LanguageService {
return new HashSet<>();
}
}
// Protected method to allow overriding in tests
protected Resource[] getResourcesFromPattern(String pattern) throws IOException {
return resourcePatternResolver.getResources(pattern);
}
}

View File

@ -25,11 +25,13 @@ import com.vladsch.flexmark.util.data.MutableDataSet;
import io.github.pixee.security.Filenames;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
@Slf4j
@NoArgsConstructor
public class PDFToFile {
public ResponseEntity<byte[]> processPdfToMarkdown(MultipartFile inputFile)

View File

@ -124,7 +124,7 @@ pipelineOptions.validateButton=Validar
# ENTERPRISE EDITION #
########################
enterpriseEdition.button=Actualiza a Pro
enterpriseEdition.warning=Esta característica está únicamente disponible para usuarios Pro.
enterpriseEdition.warning=Esta característica está disponible solamente para usuarios Pro.
enterpriseEdition.yamlAdvert=Stirling PDF Pro soporta configuración de ficheros YAML y otras características SSO.
enterpriseEdition.ssoAdvert=¿Busca más funciones de administración de usuarios? Consulte Stirling PDF Pro
@ -364,9 +364,9 @@ home.compressPdfs.title=Comprimir
home.compressPdfs.desc=Comprimir PDFs para reducir el tamaño del archivo
compressPdfs.tags=aplastar,pequeño,diminuto
home.unlockPDFForms.title=Unlock PDF Forms
home.unlockPDFForms.desc=Remove read-only property of form fields in a PDF document.
unlockPDFForms.tags=remove,delete,form,field,readonly
home.unlockPDFForms.title=Desbloquear formularios PDF
home.unlockPDFForms.desc=Eliminar la propiedad de solo-lectura de los campos de formulario en un documento PDF.
unlockPDFForms.tags=quitar,eliminar,formulario,campo,solo-lectura
home.changeMetadata.title=Cambiar metadatos
home.changeMetadata.desc=Cambiar/Eliminar/Añadir metadatos al documento PDF
@ -609,7 +609,7 @@ login.userIsDisabled=El usuario está desactivado, actualmente el acceso está b
login.alreadyLoggedIn=Ya ha iniciado sesión en
login.alreadyLoggedIn2=dispositivos. Cierre sesión en los dispositivos y vuelva a intentarlo.
login.toManySessions=Tiene demasiadas sesiones activas
login.logoutMessage=You have been logged out.
login.logoutMessage=Se ha cerrado su sesión.
#auto-redact
autoRedact.title=Auto Censurar Texto
@ -1023,7 +1023,7 @@ multiTool.deleteSelected=Borrar selecionado(s)
multiTool.downloadAll=Exportar
multiTool.downloadSelected=Exportar selecionado(s)
multiTool.insertPageBreak=Insertar salto página
multiTool.insertPageBreak=Insertar salto de página
multiTool.addFile=Agregar Archivo
multiTool.rotateLeft=Rotar a la izquierda
multiTool.rotateRight=Rotar a la derecha
@ -1061,10 +1061,10 @@ pageRemover.placeholder=(por ejemplo 1,2,6 o 1-10,15-30)
#rotate
rotate.title=Rotar PDF
rotate.header=Rotar PDF
rotate.selectAngle=Seleccionar ángulo de rotación (en múltiplos de 90 grados):
rotate.submit=Rotar
rotate.title=Girar PDF
rotate.header=Girar PDF
rotate.selectAngle=Seleccionar ángulo de giro (en múltiplos de 90 grados):
rotate.submit=Girar
#split-pdfs
@ -1197,9 +1197,9 @@ changeMetadata.selectText.5=Agregar entrada de metadatos personalizados
changeMetadata.submit=Cambiar
#unlockPDFForms
unlockPDFForms.title=Remove Read-Only from Form Fields
unlockPDFForms.header=Unlock PDF Forms
unlockPDFForms.submit=Remove
unlockPDFForms.title=Eliminar solo-lectura de los campos de formulario
unlockPDFForms.header=Desbloquear los formularios PDF
unlockPDFForms.submit=Eliminar
#pdfToPDFA
pdfToPDFA.title=PDF a PDF/A

View File

@ -364,9 +364,9 @@ home.compressPdfs.title=壓縮
home.compressPdfs.desc=壓縮 PDF 以減少其檔案大小。
compressPdfs.tags=壓縮,小,微小
home.unlockPDFForms.title=Unlock PDF Forms
home.unlockPDFForms.desc=Remove read-only property of form fields in a PDF document.
unlockPDFForms.tags=remove,delete,form,field,readonly
home.unlockPDFForms.title=解鎖 PDF 表單
home.unlockPDFForms.desc=移除 PDF 文件中表單欄位的唯讀屬性
unlockPDFForms.tags=移除,刪除,表格,欄位,唯讀
home.changeMetadata.title=變更中繼資料
home.changeMetadata.desc=從 PDF 檔案中變更/移除/新增中繼資料
@ -1197,9 +1197,9 @@ changeMetadata.selectText.5=新增自訂中繼資料項目
changeMetadata.submit=變更
#unlockPDFForms
unlockPDFForms.title=Remove Read-Only from Form Fields
unlockPDFForms.header=Unlock PDF Forms
unlockPDFForms.submit=Remove
unlockPDFForms.title=移除表單欄位的唯讀限制
unlockPDFForms.header=解鎖 PDF 表單
unlockPDFForms.submit=移除
#pdfToPDFA
pdfToPDFA.title=PDF 轉 PDF/A

View File

@ -77,7 +77,7 @@ premium:
appId: ''
mail:
enabled: true # set to 'true' to enable sending emails
enabled: false # set to 'true' to enable sending emails
host: smtp.example.com # SMTP server hostname
port: 587 # SMTP server port
username: '' # SMTP server username
@ -85,7 +85,7 @@ mail:
from: '' # sender email address
legal:
termsAndConditions: https://www.stirlingpdf.com/terms-and-conditions # URL to the terms and conditions of your application (e.g. https://example.com/terms). Empty string to disable or filename to load from local file in static folder
termsAndConditions: https://www.stirlingpdf.com/terms # URL to the terms and conditions of your application (e.g. https://example.com/terms). Empty string to disable or filename to load from local file in static folder
privacyPolicy: https://www.stirlingpdf.com/privacy-policy # URL to the privacy policy of your application (e.g. https://example.com/privacy). Empty string to disable or filename to load from local file in static folder
accessibilityStatement: '' # URL to the accessibility statement of your application (e.g. https://example.com/accessibility). Empty string to disable or filename to load from local file in static folder
cookiePolicy: '' # URL to the cookie policy of your application (e.g. https://example.com/cookie). Empty string to disable or filename to load from local file in static folder
@ -113,11 +113,11 @@ system:
name: postgres # set the name of your database. Should match the name of the database you create
customPaths:
pipeline:
watchedFoldersDir: '' #Defaults to /pipeline/watchedFolders
finishedFoldersDir: '' #Defaults to /pipeline/finishedFolders
watchedFoldersDir: '' # Defaults to /pipeline/watchedFolders
finishedFoldersDir: '' # Defaults to /pipeline/finishedFolders
operations:
weasyprint: '' #Defaults to /opt/venv/bin/weasyprint
unoconvert: '' #Defaults to /opt/venv/bin/unoconvert
weasyprint: '' # Defaults to /opt/venv/bin/weasyprint
unoconvert: '' # Defaults to /opt/venv/bin/unoconvert
fileUploadLimit: '' # Defaults to "". No limit when string is empty. Set a number, between 0 and 999, followed by one of the following strings to set a limit. "KB", "MB", "GB".
ui:

Some files were not shown because too many files have changed in this diff Show More