1
0
mirror of https://github.com/Stirling-Tools/Stirling-PDF.git synced 2024-09-30 00:20:13 +02:00

finishing forms

This commit is contained in:
Anthony Stirling 2023-09-10 01:10:24 +01:00
parent 145e8006f0
commit 1f4aae9249
22 changed files with 403 additions and 179 deletions

View File

@ -18,6 +18,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -28,6 +29,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.misc.ProcessPdfWithOcrRequest;
import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor;
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@ -51,35 +53,16 @@ public class OCRController {
@PostMapping(consumes = "multipart/form-data", value = "/ocr-pdf") @PostMapping(consumes = "multipart/form-data", value = "/ocr-pdf")
@Operation(summary = "Process a PDF file with OCR", @Operation(summary = "Process a PDF file with OCR",
description = "This endpoint processes a PDF file using OCR (Optical Character Recognition). Users can specify languages, sidecar, deskew, clean, cleanFinal, ocrType, ocrRenderType, and removeImagesAfter options. Input:PDF Output:PDF Type:SI-Conditional") description = "This endpoint processes a PDF file using OCR (Optical Character Recognition). Users can specify languages, sidecar, deskew, clean, cleanFinal, ocrType, ocrRenderType, and removeImagesAfter options. Input:PDF Output:PDF Type:SI-Conditional")
public ResponseEntity<byte[]> processPdfWithOCR( public ResponseEntity<byte[]> processPdfWithOCR(@ModelAttribute ProcessPdfWithOcrRequest request) throws IOException, InterruptedException {
@RequestPart(required = true, value = "fileInput") MultipartFile inputFile = request.getFileInput();
@Parameter(description = "The input PDF file to be processed with OCR") List<String> selectedLanguages = request.getSelectedLanguages();
MultipartFile inputFile, Boolean sidecar = request.getSidecar();
@RequestParam("languages") Boolean deskew = request.getDeskew();
@Parameter(description = "List of languages to use in OCR processing") Boolean clean = request.getClean();
List<String> selectedLanguages, Boolean cleanFinal = request.getCleanFinal();
@RequestParam(name = "sidecar", required = false) String ocrType = request.getOcrType();
@Parameter(description = "Include OCR text in a sidecar text file if set to true") String ocrRenderType = request.getOcrRenderType();
Boolean sidecar, Boolean removeImagesAfter = request.getRemoveImagesAfter();
@RequestParam(name = "deskew", required = false)
@Parameter(description = "Deskew the input file if set to true")
Boolean deskew,
@RequestParam(name = "clean", required = false)
@Parameter(description = "Clean the input file if set to true")
Boolean clean,
@RequestParam(name = "clean-final", required = false)
@Parameter(description = "Clean the final output if set to true")
Boolean cleanFinal,
@RequestParam(name = "ocrType", required = false)
@Parameter(description = "Specify the OCR type, e.g., 'skip-text', 'force-ocr', or 'Normal'", schema = @Schema(allowableValues = {"skip-text", "force-ocr", "Normal"}))
String ocrType,
@RequestParam(name = "ocrRenderType", required = false, defaultValue = "hocr")
@Parameter(description = "Specify the OCR render type, either 'hocr' or 'sandwich'", schema = @Schema(allowableValues = {"hocr", "sandwich"}))
String ocrRenderType,
@RequestParam(name = "removeImagesAfter", required = false)
@Parameter(description = "Remove images from the output PDF if set to true")
Boolean removeImagesAfter) throws IOException, InterruptedException {
// --output-type pdfa // --output-type pdfa
if (selectedLanguages == null || selectedLanguages.isEmpty()) { if (selectedLanguages == null || selectedLanguages.isEmpty()) {
throw new IOException("Please select at least one language."); throw new IOException("Please select at least one language.");

View File

@ -6,6 +6,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -15,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.misc.OverlayImageRequest;
import stirling.software.SPDF.utils.PdfUtils; import stirling.software.SPDF.utils.PdfUtils;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@ -29,22 +31,12 @@ public class OverlayImageController {
summary = "Overlay image onto a PDF file", summary = "Overlay image onto a PDF file",
description = "This endpoint overlays an image onto a PDF file at the specified coordinates. The image can be overlaid on every page of the PDF if specified. Input:PDF/IMAGE Output:PDF Type:MF-SISO" description = "This endpoint overlays an image onto a PDF file at the specified coordinates. The image can be overlaid on every page of the PDF if specified. Input:PDF/IMAGE Output:PDF Type:MF-SISO"
) )
public ResponseEntity<byte[]> overlayImage( public ResponseEntity<byte[]> overlayImage(@ModelAttribute OverlayImageRequest request) {
@RequestPart(required = true, value = "fileInput") MultipartFile pdfFile = request.getFileInput();
@Parameter(description = "The input PDF file to overlay the image onto.", required = true) MultipartFile imageFile = request.getImageFile();
MultipartFile pdfFile, float x = request.getX();
@RequestParam("fileInput2") float y = request.getY();
@Parameter(description = "The image file to be overlaid onto the PDF.", required = true) boolean everyPage = request.isEveryPage();
MultipartFile imageFile,
@RequestParam("x")
@Parameter(description = "The x-coordinate at which to place the top-left corner of the image.", example = "0")
float x,
@RequestParam("y")
@Parameter(description = "The y-coordinate at which to place the top-left corner of the image.", example = "0")
float y,
@RequestParam("everyPage")
@Parameter(description = "Whether to overlay the image onto every page of the PDF.", example = "false")
boolean everyPage) {
try { try {
byte[] pdfBytes = pdfFile.getBytes(); byte[] pdfBytes = pdfFile.getBytes();
byte[] imageBytes = imageFile.getBytes(); byte[] imageBytes = imageFile.getBytes();

View File

@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -22,6 +23,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.misc.AddPageNumbersRequest;
import stirling.software.SPDF.utils.GeneralUtils; import stirling.software.SPDF.utils.GeneralUtils;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@ -33,14 +35,13 @@ public class PageNumbersController {
@PostMapping(value = "/add-page-numbers", consumes = "multipart/form-data") @PostMapping(value = "/add-page-numbers", consumes = "multipart/form-data")
@Operation(summary = "Add page numbers to a PDF document", description = "This operation takes an input PDF file and adds page numbers to it. Input:PDF Output:PDF Type:SISO") @Operation(summary = "Add page numbers to a PDF document", description = "This operation takes an input PDF file and adds page numbers to it. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> addPageNumbers( public ResponseEntity<byte[]> addPageNumbers(@ModelAttribute AddPageNumbersRequest request) throws IOException {
@Parameter(description = "The input PDF file", required = true) @RequestParam("fileInput") MultipartFile file, MultipartFile file = request.getFileInput();
@Parameter(description = "Custom margin: small/medium/large", required = true, schema = @Schema(type = "string", allowableValues = {"small", "medium", "large"})) @RequestParam("customMargin") String customMargin, String customMargin = request.getCustomMargin();
@Parameter(description = "Position: 1 of 9 positions", required = true, schema = @Schema(type = "integer", minimum = "1", maximum = "9")) @RequestParam("position") int position, int position = request.getPosition();
@Parameter(description = "Starting number", required = true, schema = @Schema(type = "integer", minimum = "1")) @RequestParam("startingNumber") int startingNumber, int startingNumber = request.getStartingNumber();
@Parameter(description = "Which pages to number, default all", required = false, schema = @Schema(type = "string")) @RequestParam(value = "pagesToNumber", required = false) String pagesToNumber, String pagesToNumber = request.getPagesToNumber();
@Parameter(description = "Custom text: defaults to just number but can have things like \"Page {n} of {p}\"", required = false, schema = @Schema(type = "string")) @RequestParam(value = "customText", required = false) String customText) String customText = request.getCustomText();
throws IOException {
int pageNumber = startingNumber; int pageNumber = startingNumber;
byte[] fileBytes = file.getBytes(); byte[] fileBytes = file.getBytes();
PDDocument document = PDDocument.load(fileBytes); PDDocument document = PDDocument.load(fileBytes);

View File

@ -9,6 +9,7 @@ import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -17,6 +18,8 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.PDFFile;
import stirling.software.SPDF.model.api.misc.AddPageNumbersRequest;
import stirling.software.SPDF.utils.ProcessExecutor; import stirling.software.SPDF.utils.ProcessExecutor;
import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult; import stirling.software.SPDF.utils.ProcessExecutor.ProcessExecutorResult;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@ -32,11 +35,8 @@ public class RepairController {
summary = "Repair a PDF file", summary = "Repair a PDF file",
description = "This endpoint repairs a given PDF file by running Ghostscript 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" description = "This endpoint repairs a given PDF file by running Ghostscript 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( public ResponseEntity<byte[]> repairPdf(@ModelAttribute PDFFile request) throws IOException, InterruptedException {
@RequestPart(required = true, value = "fileInput") MultipartFile inputFile = request.getFileInput();
@Parameter(description = "The input PDF file to be repaired", required = true)
MultipartFile inputFile) throws IOException, InterruptedException {
// Save the uploaded file to a temporary location // Save the uploaded file to a temporary location
Path tempInputFile = Files.createTempFile("input_", ".pdf"); Path tempInputFile = Files.createTempFile("input_", ".pdf");
inputFile.transferTo(tempInputFile.toFile()); inputFile.transferTo(tempInputFile.toFile());

View File

@ -9,12 +9,14 @@ import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.PDFFile;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@Tag(name = "Other", description = "Other APIs") @Tag(name = "Other", description = "Other APIs")
@ -22,9 +24,8 @@ public class ShowJavascript {
private static final Logger logger = LoggerFactory.getLogger(ShowJavascript.class); private static final Logger logger = LoggerFactory.getLogger(ShowJavascript.class);
@PostMapping(consumes = "multipart/form-data", value = "/show-javascript") @PostMapping(consumes = "multipart/form-data", value = "/show-javascript")
public ResponseEntity<byte[]> extractHeader( public ResponseEntity<byte[]> extractHeader(@ModelAttribute PDFFile request) throws Exception {
@RequestPart(value = "fileInput") MultipartFile inputFile) throws Exception { MultipartFile inputFile = request.getFileInput();
String script = ""; String script = "";
try (PDDocument document = PDDocument.load(inputFile.getInputStream())) { try (PDDocument document = PDDocument.load(inputFile.getInputStream())) {

View File

@ -37,6 +37,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -51,6 +52,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.ApplicationProperties; import stirling.software.SPDF.model.ApplicationProperties;
import stirling.software.SPDF.model.PipelineConfig; import stirling.software.SPDF.model.PipelineConfig;
import stirling.software.SPDF.model.PipelineOperation; import stirling.software.SPDF.model.PipelineOperation;
import stirling.software.SPDF.model.api.HandleDataRequest;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -418,8 +420,9 @@ public class PipelineController {
} }
@PostMapping("/handleData") @PostMapping("/handleData")
public ResponseEntity<byte[]> handleData(@RequestPart("fileInput") MultipartFile[] files, public ResponseEntity<byte[]> handleData(@ModelAttribute HandleDataRequest request) {
@RequestParam("json") String jsonString) { MultipartFile[] files = request.getFileInputs();
String jsonString = request.getJsonString();
logger.info("Received POST request to /handleData with {} files", files.length); logger.info("Received POST request to /handleData with {} files", files.length);
try { try {
List<Resource> outputFiles = handleFiles(files, jsonString); List<Resource> outputFiles = handleFiles(files, jsonString);

View File

@ -44,6 +44,7 @@ import org.bouncycastle.util.io.pem.PemReader;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -54,6 +55,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.security.SignPDFWithCertRequest;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -68,30 +70,18 @@ public class CertSignController {
@PostMapping(consumes = "multipart/form-data", value = "/cert-sign") @PostMapping(consumes = "multipart/form-data", value = "/cert-sign")
@Operation(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:MF-SISO") @Operation(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:MF-SISO")
public ResponseEntity<byte[]> signPDF2( public ResponseEntity<byte[]> signPDFWithCert(@ModelAttribute SignPDFWithCertRequest request) throws Exception {
@RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file") MultipartFile pdf, MultipartFile pdf = request.getFileInput();
String certType = request.getCertType();
@RequestParam(value = "certType", required = false) @Parameter(description = "The type of the digital certificate", schema = @Schema(allowableValues = { MultipartFile privateKeyFile = request.getPrivateKeyFile();
"PKCS12", "PEM" })) String certType, MultipartFile certFile = request.getCertFile();
MultipartFile p12File = request.getP12File();
@RequestParam(value = "key", required = false) @Parameter(description = "The private key for the digital certificate (required for PEM type certificates)") MultipartFile privateKeyFile, String password = request.getPassword();
Boolean showSignature = request.getShowSignature();
@RequestParam(value = "cert", required = false) @Parameter(description = "The digital certificate (required for PEM type certificates)") MultipartFile certFile, String reason = request.getReason();
String location = request.getLocation();
@RequestParam(value = "p12", required = false) @Parameter(description = "The PKCS12 keystore file (required for PKCS12 type certificates)") MultipartFile p12File, String name = request.getName();
Integer pageNumber = request.getPageNumber();
@RequestParam(value = "password", required = false) @Parameter(description = "The password for the keystore or the private key") String password,
@RequestParam(value = "showSignature", required = false) @Parameter(description = "Whether to visually show the signature in the PDF file") Boolean showSignature,
@RequestParam(value = "reason", required = false) @Parameter(description = "The reason for signing the PDF") String reason,
@RequestParam(value = "location", required = false) @Parameter(description = "The location where the PDF is signed") String location,
@RequestParam(value = "name", required = false) @Parameter(description = "The name of the signer") String name,
@RequestParam(value = "pageNumber", required = false) @Parameter(description = "The page number where the signature should be visible. This is required if showSignature is set to true") Integer pageNumber)
throws Exception {
PrivateKey privateKey = null; PrivateKey privateKey = null;
X509Certificate cert = null; X509Certificate cert = null;

View File

@ -60,6 +60,7 @@ import org.apache.xmpbox.xml.XmpParsingException;
import org.apache.xmpbox.xml.XmpSerializer; import org.apache.xmpbox.xml.XmpSerializer;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -72,6 +73,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.PDFFile;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@Tag(name = "Security", description = "Security APIs") @Tag(name = "Security", description = "Security APIs")
@ -81,11 +83,9 @@ public class GetInfoOnPDF {
@PostMapping(consumes = "multipart/form-data", value = "/get-info-on-pdf") @PostMapping(consumes = "multipart/form-data", value = "/get-info-on-pdf")
@Operation(summary = "Summary here", description = "desc. Input:PDF Output:JSON Type:SISO") @Operation(summary = "Summary here", description = "desc. Input:PDF Output:JSON Type:SISO")
public ResponseEntity<byte[]> getPdfInfo( public ResponseEntity<byte[]> getPdfInfo(@ModelAttribute PDFFile request)
@RequestPart(required = true, value = "fileInput")
@Parameter(description = "The input PDF file to get info on", required = true) MultipartFile inputFile)
throws IOException { throws IOException {
MultipartFile inputFile = request.getFileInput();
try ( try (
PDDocument pdfBoxDoc = PDDocument.load(inputFile.getInputStream()); PDDocument pdfBoxDoc = PDDocument.load(inputFile.getInputStream());
) { ) {

View File

@ -8,6 +8,7 @@ import org.apache.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -18,6 +19,8 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.security.AddPasswordRequest;
import stirling.software.SPDF.model.api.security.PDFPasswordRequest;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@Tag(name = "Security", description = "Security APIs") @Tag(name = "Security", description = "Security APIs")
@ -31,13 +34,12 @@ public class PasswordController {
summary = "Remove password from a PDF file", summary = "Remove password from a PDF file",
description = "This endpoint removes the password from a protected PDF file. Users need to provide the existing password. Input:PDF Output:PDF Type:SISO" description = "This endpoint removes the password from a protected PDF file. Users need to provide the existing password. Input:PDF Output:PDF Type:SISO"
) )
public ResponseEntity<byte[]> removePassword( public ResponseEntity<byte[]> removePassword(@ModelAttribute PDFPasswordRequest request) throws IOException {
@RequestPart(required = true, value = "fileInput") MultipartFile fileInput = request.getFileInput();
@Parameter(description = "The input PDF file from which the password should be removed", required = true) String password = request.getPassword();
MultipartFile fileInput,
@RequestParam(name = "password")
@Parameter(description = "The password of the PDF file", required = true)
String password) throws IOException {
PDDocument document = PDDocument.load(fileInput.getBytes(), password); PDDocument document = PDDocument.load(fileInput.getBytes(), password);
document.setAllSecurityToBeRemoved(true); document.setAllSecurityToBeRemoved(true);
return WebResponseUtils.pdfDocToWebResponse(document, fileInput.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_password_removed.pdf"); return WebResponseUtils.pdfDocToWebResponse(document, fileInput.getOriginalFilename().replaceFirst("[.][^.]+$", "") + "_password_removed.pdf");
@ -48,44 +50,19 @@ public class PasswordController {
summary = "Add password to a PDF file", summary = "Add password to a PDF file",
description = "This endpoint adds password protection to a PDF file. Users can specify a set of permissions that should be applied to the file. Input:PDF Output:PDF" description = "This endpoint adds password protection to a PDF file. Users can specify a set of permissions that should be applied to the file. Input:PDF Output:PDF"
) )
public ResponseEntity<byte[]> addPassword( public ResponseEntity<byte[]> addPassword(@ModelAttribute AddPasswordRequest request) throws IOException {
@RequestPart(required = true, value = "fileInput") MultipartFile fileInput = request.getFileInput();
@Parameter(description = "The input PDF file to which the password should be added", required = true) String ownerPassword = request.getOwnerPassword();
MultipartFile fileInput, String password = request.getPassword();
@RequestParam(value = "", name = "ownerPassword", required = false, defaultValue = "") int keyLength = request.getKeyLength();
@Parameter(description = "The owner password to be added to the PDF file (Restricts what can be done with the document once it is opened)") boolean canAssembleDocument = request.isCanAssembleDocument();
String ownerPassword, boolean canExtractContent = request.isCanExtractContent();
@RequestParam( name = "password", required = false, defaultValue = "") boolean canExtractForAccessibility = request.isCanExtractForAccessibility();
@Parameter(description = "The password to be added to the PDF file (Restricts the opening of the document itself.)") boolean canFillInForm = request.isCanFillInForm();
String password, boolean canModify = request.isCanModify();
@RequestParam( name = "keyLength", required = false, defaultValue = "256") boolean canModifyAnnotations = request.isCanModifyAnnotations();
@Parameter(description = "The length of the encryption key", schema = @Schema(allowableValues = {"40", "128", "256"})) boolean canPrint = request.isCanPrint();
int keyLength, boolean canPrintFaithful = request.isCanPrintFaithful();
@RequestParam( name = "canAssembleDocument", required = false)
@Parameter(description = "Whether the document assembly is allowed", example = "false")
boolean canAssembleDocument,
@RequestParam( name = "canExtractContent", required = false)
@Parameter(description = "Whether content extraction for accessibility is allowed", example = "false")
boolean canExtractContent,
@RequestParam( name = "canExtractForAccessibility", required = false)
@Parameter(description = "Whether content extraction for accessibility is allowed", example = "false")
boolean canExtractForAccessibility,
@RequestParam( name = "canFillInForm", required = false)
@Parameter(description = "Whether form filling is allowed", example = "false")
boolean canFillInForm,
@RequestParam( name = "canModify", required = false)
@Parameter(description = "Whether the document modification is allowed", example = "false")
boolean canModify,
@RequestParam( name = "canModifyAnnotations", required = false)
@Parameter(description = "Whether modification of annotations is allowed", example = "false")
boolean canModifyAnnotations,
@RequestParam(name = "canPrint", required = false)
@Parameter(description = "Whether printing of the document is allowed", example = "false")
boolean canPrint,
@RequestParam( name = "canPrintFaithful", required = false)
@Parameter(description = "Whether faithful printing is allowed", example = "false")
boolean canPrintFaithful
) throws IOException {
PDDocument document = PDDocument.load(fileInput.getBytes()); PDDocument document = PDDocument.load(fileInput.getBytes());
AccessPermission ap = new AccessPermission(); AccessPermission ap = new AccessPermission();

View File

@ -18,6 +18,7 @@ import org.apache.pdfbox.rendering.PDFRenderer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -28,6 +29,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.PDFText; import stirling.software.SPDF.model.PDFText;
import stirling.software.SPDF.model.api.security.RedactPdfRequest;
import stirling.software.SPDF.pdf.TextFinder; import stirling.software.SPDF.pdf.TextFinder;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -40,14 +42,14 @@ public class RedactController {
@PostMapping(value = "/auto-redact", consumes = "multipart/form-data") @PostMapping(value = "/auto-redact", consumes = "multipart/form-data")
@Operation(summary = "Redacts listOfText in a PDF document", @Operation(summary = "Redacts listOfText in a PDF document",
description = "This operation takes an input PDF file and redacts the provided listOfText. Input:PDF, Output:PDF, Type:SISO") description = "This operation takes an input PDF file and redacts the provided listOfText. Input:PDF, Output:PDF, Type:SISO")
public ResponseEntity<byte[]> redactPdf( public ResponseEntity<byte[]> redactPdf(@ModelAttribute RedactPdfRequest request) throws Exception {
@Parameter(description = "The input PDF file", required = true) @RequestParam("fileInput") MultipartFile file, MultipartFile file = request.getFileInput();
@Parameter(description = "List of listOfText to redact from the PDF", required = true, schema = @Schema(type = "string")) @RequestParam("listOfText") String listOfTextString, String listOfTextString = request.getListOfText();
@RequestParam(value = "useRegex", required = false) boolean useRegex, boolean useRegex = request.isUseRegex();
@RequestParam(value = "wholeWordSearch", required = false) boolean wholeWordSearchBool, boolean wholeWordSearchBool = request.isWholeWordSearch();
@RequestParam(value = "redactColor", required = false, defaultValue = "#000000") String colorString, String colorString = request.getRedactColor();
@RequestParam(value = "customPadding", required = false) float customPadding, float customPadding = request.getCustomPadding();
@RequestParam(value = "convertPDFToImage", required = false) boolean convertPDFToImage) throws Exception { boolean convertPDFToImage = request.isConvertPDFToImage();
System.out.println(listOfTextString); System.out.println(listOfTextString);
String[] listOfText = listOfTextString.split("\n"); String[] listOfText = listOfTextString.split("\n");

View File

@ -20,6 +20,7 @@ import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm; import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField; import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -28,6 +29,7 @@ import org.springframework.web.multipart.MultipartFile;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import stirling.software.SPDF.model.api.security.SanitizePdfRequest;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -36,25 +38,13 @@ public class SanitizeController {
@PostMapping(consumes = "multipart/form-data", value = "/sanitize-pdf") @PostMapping(consumes = "multipart/form-data", value = "/sanitize-pdf")
@Operation(summary = "Sanitize a PDF file", @Operation(summary = "Sanitize a PDF file",
description = "This endpoint processes a PDF file and removes specific elements based on the provided options. Input:PDF Output:PDF Type:SISO") description = "This endpoint processes a PDF file and removes specific elements based on the provided options. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> sanitizePDF( public ResponseEntity<byte[]> sanitizePDF(@ModelAttribute SanitizePdfRequest request) throws IOException {
@RequestPart(required = true, value = "fileInput") MultipartFile inputFile = request.getFileInput();
@Parameter(description = "The input PDF file to be sanitized") Boolean removeJavaScript = request.getRemoveJavaScript();
MultipartFile inputFile, Boolean removeEmbeddedFiles = request.getRemoveEmbeddedFiles();
@RequestParam(name = "removeJavaScript", required = false, defaultValue = "false") Boolean removeMetadata = request.getRemoveMetadata();
@Parameter(description = "Remove JavaScript actions from the PDF if set to true") Boolean removeLinks = request.getRemoveLinks();
Boolean removeJavaScript, Boolean removeFonts = request.getRemoveFonts();
@RequestParam(name = "removeEmbeddedFiles", required = false, defaultValue = "false")
@Parameter(description = "Remove embedded files from the PDF if set to true")
Boolean removeEmbeddedFiles,
@RequestParam(name = "removeMetadata", required = false, defaultValue = "false")
@Parameter(description = "Remove metadata from the PDF if set to true")
Boolean removeMetadata,
@RequestParam(name = "removeLinks", required = false, defaultValue = "false")
@Parameter(description = "Remove links from the PDF if set to true")
Boolean removeLinks,
@RequestParam(name = "removeFonts", required = false, defaultValue = "false")
@Parameter(description = "Remove fonts from the PDF if set to true")
Boolean removeFonts) throws IOException {
try (PDDocument document = PDDocument.load(inputFile.getInputStream())) { try (PDDocument document = PDDocument.load(inputFile.getInputStream())) {
if (removeJavaScript) { if (removeJavaScript) {

View File

@ -22,6 +22,7 @@ import org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState;
import org.apache.pdfbox.util.Matrix; import org.apache.pdfbox.util.Matrix;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
@ -32,6 +33,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import stirling.software.SPDF.model.api.security.AddWatermarkRequest;
import stirling.software.SPDF.utils.WebResponseUtils; import stirling.software.SPDF.utils.WebResponseUtils;
@RestController @RestController
@ -40,22 +42,17 @@ public class WatermarkController {
@PostMapping(consumes = "multipart/form-data", value = "/add-watermark") @PostMapping(consumes = "multipart/form-data", value = "/add-watermark")
@Operation(summary = "Add watermark to a PDF file", description = "This endpoint adds a watermark to a given PDF file. Users can specify the watermark type (text or image), rotation, opacity, width spacer, and height spacer. Input:PDF Output:PDF Type:SISO") @Operation(summary = "Add watermark to a PDF file", description = "This endpoint adds a watermark to a given PDF file. Users can specify the watermark type (text or image), rotation, opacity, width spacer, and height spacer. Input:PDF Output:PDF Type:SISO")
public ResponseEntity<byte[]> addWatermark( public ResponseEntity<byte[]> addWatermark(@ModelAttribute AddWatermarkRequest request) throws IOException, Exception {
@RequestPart(required = true, value = "fileInput") @Parameter(description = "The input PDF file to add a watermark") MultipartFile pdfFile, MultipartFile pdfFile = request.getFileInput();
@RequestParam(required = true) @Parameter(description = "The watermark type (text or image)") String watermarkType, String watermarkType = request.getWatermarkType();
@RequestParam(required = false) @Parameter(description = "The watermark text") String watermarkText, String watermarkText = request.getWatermarkText();
@RequestPart(required = false) @Parameter(description = "The watermark image") MultipartFile watermarkImage, MultipartFile watermarkImage = request.getWatermarkImage();
String alphabet = request.getAlphabet();
@RequestParam(defaultValue = "roman", name = "alphabet") @Parameter(description = "The selected alphabet", float fontSize = request.getFontSize();
schema = @Schema(type = "string", float rotation = request.getRotation();
allowableValues = {"roman","arabic","japanese","korean","chinese"}, float opacity = request.getOpacity();
defaultValue = "roman")) String alphabet, int widthSpacer = request.getWidthSpacer();
@RequestParam(defaultValue = "30", name = "fontSize") @Parameter(description = "The font size of the watermark text", example = "30") float fontSize, int heightSpacer = request.getHeightSpacer();
@RequestParam(defaultValue = "0", name = "rotation") @Parameter(description = "The rotation of the watermark in degrees", example = "0") float rotation,
@RequestParam(defaultValue = "0.5", name = "opacity") @Parameter(description = "The opacity of the watermark (0.0 - 1.0)", example = "0.5") float opacity,
@RequestParam(defaultValue = "50", name = "widthSpacer") @Parameter(description = "The width spacer between watermark elements", example = "50") int widthSpacer,
@RequestParam(defaultValue = "50", name = "heightSpacer") @Parameter(description = "The height spacer between watermark elements", example = "50") int heightSpacer)
throws IOException, Exception {
// Load the input PDF // Load the input PDF
PDDocument document = PDDocument.load(pdfFile.getInputStream()); PDDocument document = PDDocument.load(pdfFile.getInputStream());

View File

@ -0,0 +1,15 @@
package stirling.software.SPDF.model.api;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
@Data
public class HandleDataRequest {
@Schema(description = "The input files")
private MultipartFile[] fileInputs;
@Schema(description = "JSON String")
private String jsonString;
}

View File

@ -0,0 +1,26 @@
package stirling.software.SPDF.model.api.misc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import stirling.software.SPDF.model.api.PDFWithPageNums;
import org.springframework.web.multipart.MultipartFile;
@Data
public class AddPageNumbersRequest extends PDFWithPageNums {
@Schema(description = "Custom margin: small/medium/large", allowableValues = {"small", "medium", "large"})
private String customMargin;
@Schema(description = "Position: 1 of 9 positions", minimum = "1", maximum = "9")
private int position;
@Schema(description = "Starting number", minimum = "1")
private int startingNumber;
@Schema(description = "Which pages to number, default all")
private String pagesToNumber;
@Schema(description = "Custom text: defaults to just number but can have things like \"Page {n} of {p}\"")
private String customText;
}

View File

@ -0,0 +1,23 @@
package stirling.software.SPDF.model.api.misc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import stirling.software.SPDF.model.api.PDFFile;
import org.springframework.web.multipart.MultipartFile;
@Data
public class OverlayImageRequest extends PDFFile {
@Schema(description = "The image file to be overlaid onto the PDF.")
private MultipartFile imageFile;
@Schema(description = "The x-coordinate at which to place the top-left corner of the image.", example = "0")
private float x;
@Schema(description = "The y-coordinate at which to place the top-left corner of the image.", example = "0")
private float y;
@Schema(description = "Whether to overlay the image onto every page of the PDF.", example = "false")
private boolean everyPage;
}

View File

@ -0,0 +1,36 @@
package stirling.software.SPDF.model.api.misc;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
import java.util.List;
@Data
public class ProcessPdfWithOcrRequest extends PDFFile {
@Schema(description = "List of languages to use in OCR processing")
private List<String> selectedLanguages;
@Schema(description = "Include OCR text in a sidecar text file if set to true")
private Boolean sidecar;
@Schema(description = "Deskew the input file if set to true")
private Boolean deskew;
@Schema(description = "Clean the input file if set to true")
private Boolean clean;
@Schema(description = "Clean the final output if set to true")
private Boolean cleanFinal;
@Schema(description = "Specify the OCR type, e.g., 'skip-text', 'force-ocr', or 'Normal'", allowableValues = {"skip-text", "force-ocr", "Normal"})
private String ocrType;
@Schema(description = "Specify the OCR render type, either 'hocr' or 'sandwich'", allowableValues = {"hocr", "sandwich"}, defaultValue = "hocr")
private String ocrRenderType;
@Schema(description = "Remove images from the output PDF if set to true")
private Boolean removeImagesAfter;
}

View File

@ -0,0 +1,43 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
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 = "")
private String ownerPassword;
@Schema(description = "The password to be added to the PDF file (Restricts the opening of the document itself.)", defaultValue = "")
private String password;
@Schema(description = "The length of the encryption key", allowableValues = {"40", "128", "256"}, defaultValue = "256")
private int keyLength;
@Schema(description = "Whether the document assembly is allowed", example = "false")
private boolean canAssembleDocument;
@Schema(description = "Whether content extraction for accessibility is allowed", example = "false")
private boolean canExtractContent;
@Schema(description = "Whether content extraction for accessibility is allowed", example = "false")
private boolean canExtractForAccessibility;
@Schema(description = "Whether form filling is allowed", example = "false")
private boolean canFillInForm;
@Schema(description = "Whether the document modification is allowed", example = "false")
private boolean canModify;
@Schema(description = "Whether modification of annotations is allowed", example = "false")
private boolean canModifyAnnotations;
@Schema(description = "Whether printing of the document is allowed", example = "false")
private boolean canPrint;
@Schema(description = "Whether faithful printing is allowed", example = "false")
private boolean canPrintFaithful;
}

View File

@ -0,0 +1,39 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
public class AddWatermarkRequest extends PDFFile {
@Schema(description = "The watermark type (text or image)", required = true)
private String watermarkType;
@Schema(description = "The watermark text")
private String watermarkText;
@Schema(description = "The watermark image")
private MultipartFile watermarkImage;
@Schema(description = "The selected alphabet",
allowableValues = {"roman", "arabic", "japanese", "korean", "chinese"},
defaultValue = "roman")
private String alphabet;
@Schema(description = "The font size of the watermark text", example = "30")
private float fontSize;
@Schema(description = "The rotation of the watermark in degrees", example = "0")
private float rotation;
@Schema(description = "The opacity of the watermark (0.0 - 1.0)", example = "0.5")
private float opacity;
@Schema(description = "The width spacer between watermark elements", example = "50")
private int widthSpacer;
@Schema(description = "The height spacer between watermark elements", example = "50")
private int heightSpacer;
}

View File

@ -0,0 +1,13 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
public class PDFPasswordRequest extends PDFFile {
@Schema(description = "The password of the PDF file", required = true)
private String password;
}

View File

@ -0,0 +1,28 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
public class RedactPdfRequest extends PDFFile {
@Schema(description = "List of text to redact from the PDF", type = "string", required = true)
private String listOfText;
@Schema(description = "Whether to use regex for the listOfText", defaultValue = "false")
private boolean useRegex;
@Schema(description = "Whether to use whole word search", defaultValue = "false")
private boolean wholeWordSearch;
@Schema(description = "The color for redaction", defaultValue = "#000000")
private String redactColor;
@Schema(description = "Custom padding for redaction", type = "number")
private float customPadding;
@Schema(description = "Convert the redacted PDF to an image", defaultValue = "false")
private boolean convertPDFToImage;
}

View File

@ -0,0 +1,25 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
public class SanitizePdfRequest extends PDFFile {
@Schema(description = "Remove JavaScript actions from the PDF", defaultValue = "false")
private Boolean removeJavaScript;
@Schema(description = "Remove embedded files from the PDF", defaultValue = "false")
private Boolean removeEmbeddedFiles;
@Schema(description = "Remove metadata from the PDF", defaultValue = "false")
private Boolean removeMetadata;
@Schema(description = "Remove links from the PDF", defaultValue = "false")
private Boolean removeLinks;
@Schema(description = "Remove fonts from the PDF", defaultValue = "false")
private Boolean removeFonts;
}

View File

@ -0,0 +1,40 @@
package stirling.software.SPDF.model.api.security;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import stirling.software.SPDF.model.api.PDFFile;
@Data
public class SignPDFWithCertRequest extends PDFFile {
@Schema(description = "The type of the digital certificate", allowableValues = { "PKCS12", "PEM" })
private String certType;
@Schema(description = "The private key for the digital certificate (required for PEM type certificates)")
private MultipartFile privateKeyFile;
@Schema(description = "The digital certificate (required for PEM type certificates)")
private MultipartFile certFile;
@Schema(description = "The PKCS12 keystore file (required for PKCS12 type certificates)")
private MultipartFile p12File;
@Schema(description = "The password for the keystore or the private key")
private String password;
@Schema(description = "Whether to visually show the signature in the PDF file")
private Boolean showSignature;
@Schema(description = "The reason for signing the PDF")
private String reason;
@Schema(description = "The location where the PDF is signed")
private String location;
@Schema(description = "The name of the signer")
private String name;
@Schema(description = "The page number where the signature should be visible. This is required if showSignature is set to true")
private Integer pageNumber;
}