mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-09-12 17:52:13 +02:00
more stuff
This commit is contained in:
parent
c07908d4ed
commit
1426cf8c48
@ -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(
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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 =
|
||||
|
@ -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";
|
||||
|
@ -47,9 +47,8 @@ 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)
|
||||
throws Exception {
|
||||
MultipartFile fileInput = request.getFileInput();
|
||||
public ResponseEntity<byte[]> markdownToPdf(@ModelAttribute GeneralFile generalFile) throws Exception {
|
||||
MultipartFile fileInput = generalFile.getFileInput();
|
||||
|
||||
if (fileInput == null) {
|
||||
throw new IllegalArgumentException("Please provide a Markdown file for conversion.");
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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();
|
||||
|
@ -56,9 +56,10 @@ public class ExtractImageScansController {
|
||||
+ " parameters. Users can specify angle threshold, tolerance, minimum area,"
|
||||
+ " minimum contour area, and border size. Input:PDF Output:IMAGE/ZIP"
|
||||
+ " Type:SIMO")
|
||||
public ResponseEntity<byte[]> extractImageScans(@ModelAttribute ExtractImageScansRequest form)
|
||||
public ResponseEntity<byte[]> extractImageScans(
|
||||
@ModelAttribute ExtractImageScansRequest request)
|
||||
throws IOException, InterruptedException {
|
||||
MultipartFile inputFile = form.getFileInput();
|
||||
MultipartFile inputFile = request.getFileInput();
|
||||
|
||||
String fileName = inputFile.getOriginalFilename();
|
||||
String extension = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
@ -121,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 =
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
@ -84,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);
|
||||
|
@ -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;
|
||||
|
@ -15,6 +15,7 @@ public class PDFFile {
|
||||
@Schema(
|
||||
description = "The input PDF file",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
contentMediaType = "application/pdf",
|
||||
format = "binary")
|
||||
private MultipartFile fileInput;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -13,21 +13,30 @@ 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"})
|
||||
defaultValue = "multiple",
|
||||
allowableValues = {"single", "multiple"},
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String singleOrMultiple;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -18,16 +18,21 @@ public class ConvertToPdfRequest {
|
||||
|
||||
@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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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"
|
||||
})
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -41,6 +41,6 @@ public class OverlayPdfsRequest extends PDFFile {
|
||||
description = "Overlay position 0 is Foregound, 1 is Background",
|
||||
allowableValues = {"0", "1"},
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
type = "integer")
|
||||
type = "number")
|
||||
private int overlayPosition;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class RotatePDFRequest extends PDFFile {
|
||||
description =
|
||||
"The angle by which to rotate the PDF file. This should be a multiple of 90.",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
allowableValues = "0, 90, 180, 270",
|
||||
example = "90")
|
||||
allowableValues = {"0", "90", "180", "270"},
|
||||
defaultValue = "90")
|
||||
private Integer angle;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ public class MetadataRequest extends PDFFile {
|
||||
description = "Delete all metadata if set to true",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean deleteAll;
|
||||
private Boolean deleteAll;
|
||||
|
||||
@Schema(
|
||||
description = "The author of the document",
|
||||
|
@ -35,5 +35,5 @@ public class OverlayImageRequest extends PDFFile {
|
||||
description = "Whether to overlay the image onto every page of the PDF.",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
defaultValue = "false")
|
||||
private boolean everyPage;
|
||||
private Boolean everyPage;
|
||||
}
|
||||
|
@ -14,18 +14,16 @@ public class RemoveBlankPagesRequest extends PDFFile {
|
||||
@Schema(
|
||||
description = "The threshold value to determine blank pages",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
example = "10",
|
||||
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",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED,
|
||||
minimum = "0.1",
|
||||
maximum = "100",
|
||||
example = "99.9",
|
||||
defaultValue = "99.9")
|
||||
private float whitePercent = 99.9f;
|
||||
private float whitePercent;
|
||||
}
|
||||
|
@ -29,29 +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",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean convertPDFToImage;
|
||||
private Boolean convertPDFToImage;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class ManualRedactPdfRequest extends PDFWithPageNums {
|
||||
description = "Convert the redacted PDF to an image",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean convertPDFToImage;
|
||||
private Boolean convertPDFToImage;
|
||||
|
||||
@Schema(
|
||||
description = "The color used to fully redact certain pages",
|
||||
|
@ -13,7 +13,6 @@ 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;
|
||||
@ -22,13 +21,13 @@ public class RedactPdfRequest extends PDFFile {
|
||||
description = "Whether to use regex for the listOfText",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean useRegex;
|
||||
private Boolean useRegex;
|
||||
|
||||
@Schema(
|
||||
description = "Whether to use whole word search",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean wholeWordSearch;
|
||||
private Boolean wholeWordSearch;
|
||||
|
||||
@Schema(
|
||||
description = "The color for redaction",
|
||||
@ -46,5 +45,5 @@ public class RedactPdfRequest extends PDFFile {
|
||||
description = "Convert the redacted PDF to an image",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean convertPDFToImage;
|
||||
private Boolean convertPDFToImage;
|
||||
}
|
||||
|
@ -13,37 +13,37 @@ public class SanitizePdfRequest extends PDFFile {
|
||||
|
||||
@Schema(
|
||||
description = "Remove JavaScript actions from the PDF",
|
||||
defaultValue = "false",
|
||||
defaultValue = "true",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeJavaScript;
|
||||
private Boolean removeJavaScript;
|
||||
|
||||
@Schema(
|
||||
description = "Remove embedded files from the PDF",
|
||||
defaultValue = "false",
|
||||
defaultValue = "true",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeEmbeddedFiles;
|
||||
private Boolean removeEmbeddedFiles;
|
||||
|
||||
@Schema(
|
||||
description = "Remove XMP metadata from the PDF",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeXMPMetadata;
|
||||
private Boolean removeXMPMetadata;
|
||||
|
||||
@Schema(
|
||||
description = "Remove document info metadata from the PDF",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeMetadata;
|
||||
private Boolean removeMetadata;
|
||||
|
||||
@Schema(
|
||||
description = "Remove links from the PDF",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeLinks;
|
||||
private Boolean removeLinks;
|
||||
|
||||
@Schema(
|
||||
description = "Remove fonts from the PDF",
|
||||
defaultValue = "false",
|
||||
requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private boolean removeFonts;
|
||||
private Boolean removeFonts;
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user