1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-09-29 16:10:11 +02:00
This commit is contained in:
Anthony Stirling 2023-08-12 19:53:14 +01:00
parent 6f325b5fdb
commit ad5f057733

View File

@ -52,13 +52,13 @@ public class PasswordController {
@RequestPart(required = true, value = "fileInput") @RequestPart(required = true, value = "fileInput")
@Parameter(description = "The input PDF file to which the password should be added", required = true) @Parameter(description = "The input PDF file to which the password should be added", required = true)
MultipartFile fileInput, MultipartFile fileInput,
@RequestParam(value = "", name = "ownerPassword") @RequestParam(value = "", name = "ownerPassword", required = false, defaultValue = "")
@Parameter(description = "The owner password to be added to the PDF file (Restricts what can be done with the document once it is opened)") @Parameter(description = "The owner password to be added to the PDF file (Restricts what can be done with the document once it is opened)")
String ownerPassword, String ownerPassword,
@RequestParam( name = "password", required = false) @RequestParam( name = "password", required = false, defaultValue = "")
@Parameter(description = "The password to be added to the PDF file (Restricts the opening of the document itself.)") @Parameter(description = "The password to be added to the PDF file (Restricts the opening of the document itself.)")
String password, String password,
@RequestParam( name = "keyLength", required = false) @RequestParam( name = "keyLength", required = false, defaultValue = "256")
@Parameter(description = "The length of the encryption key", schema = @Schema(allowableValues = {"40", "128", "256"})) @Parameter(description = "The length of the encryption key", schema = @Schema(allowableValues = {"40", "128", "256"}))
int keyLength, int keyLength,
@RequestParam( name = "canAssembleDocument", required = false) @RequestParam( name = "canAssembleDocument", required = false)
@ -98,15 +98,15 @@ public class PasswordController {
ap.setCanPrint(!canPrint); ap.setCanPrint(!canPrint);
ap.setCanPrintFaithful(!canPrintFaithful); ap.setCanPrintFaithful(!canPrintFaithful);
StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword, password, ap); StandardProtectionPolicy spp = new StandardProtectionPolicy(ownerPassword, password, ap);
spp.setEncryptionKeyLength(keyLength);
if(!"".equals(ownerPassword) || !"".equals(password)) {
spp.setEncryptionKeyLength(keyLength);
}
spp.setPermissions(ap); spp.setPermissions(ap);
document.protect(spp); document.protect(spp);
if("".equals(ownerPassword) && "".equals(password))
return WebResponseUtils.pdfDocToWebResponse(document, fileInput.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_permissions.pdf");
return WebResponseUtils.pdfDocToWebResponse(document, fileInput.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_passworded.pdf"); return WebResponseUtils.pdfDocToWebResponse(document, fileInput.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_passworded.pdf");
} }