mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-02-07 00:17:07 +01:00
📁 pre-commit
Signed-off-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
This commit is contained in:
parent
7eb7774979
commit
cf7556c105
@ -23,18 +23,18 @@ import java.util.*;
|
||||
@Tag(name = "Analysis", description = "Analysis APIs")
|
||||
public class AnalysisController {
|
||||
|
||||
|
||||
|
||||
@PostMapping(value = "/page-count", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get PDF page count",
|
||||
@Operation(summary = "Get PDF page count",
|
||||
description = "Returns total number of pages in PDF. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Integer> getPageCount(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
return Map.of("pageCount", document.getNumberOfPages());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(value ="/basic-info", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get basic PDF information",
|
||||
@Operation(summary = "Get basic PDF information",
|
||||
description = "Returns page count, version, file size. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Object> getBasicInfo(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
@ -47,7 +47,7 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/document-properties", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get PDF document properties",
|
||||
@Operation(summary = "Get PDF document properties",
|
||||
description = "Returns title, author, subject, etc. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, String> getDocumentProperties(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
@ -66,13 +66,13 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/page-dimensions", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get page dimensions for all pages",
|
||||
@Operation(summary = "Get page dimensions for all pages",
|
||||
description = "Returns width and height of each page. Input:PDF Output:JSON Type:SISO")
|
||||
public List<Map<String, Float>> getPageDimensions(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
List<Map<String, Float>> dimensions = new ArrayList<>();
|
||||
PDPageTree pages = document.getPages();
|
||||
|
||||
|
||||
for (PDPage page : pages) {
|
||||
Map<String, Float> pageDim = new HashMap<>();
|
||||
pageDim.put("width", page.getBBox().getWidth());
|
||||
@ -84,13 +84,13 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/form-fields", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get form field information",
|
||||
@Operation(summary = "Get form field information",
|
||||
description = "Returns count and details of form fields. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Object> getFormFields(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
Map<String, Object> formInfo = new HashMap<>();
|
||||
PDAcroForm form = document.getDocumentCatalog().getAcroForm();
|
||||
|
||||
|
||||
if (form != null) {
|
||||
formInfo.put("fieldCount", form.getFields().size());
|
||||
formInfo.put("hasXFA", form.hasXFA());
|
||||
@ -105,7 +105,7 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/annotation-info", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get annotation information",
|
||||
@Operation(summary = "Get annotation information",
|
||||
description = "Returns count and types of annotations. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Object> getAnnotationInfo(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
@ -128,7 +128,7 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/font-info", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get font information",
|
||||
@Operation(summary = "Get font information",
|
||||
description = "Returns list of fonts used in the document. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Object> getFontInfo(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
@ -148,33 +148,33 @@ public class AnalysisController {
|
||||
}
|
||||
|
||||
@PostMapping(value ="/security-info", consumes = "multipart/form-data")
|
||||
@Operation(summary = "Get security information",
|
||||
@Operation(summary = "Get security information",
|
||||
description = "Returns encryption and permission details. Input:PDF Output:JSON Type:SISO")
|
||||
public Map<String, Object> getSecurityInfo(@ModelAttribute PDFFile file) throws IOException {
|
||||
try (PDDocument document = Loader.loadPDF(file.getFileInput().getBytes())) {
|
||||
Map<String, Object> securityInfo = new HashMap<>();
|
||||
PDEncryption encryption = document.getEncryption();
|
||||
|
||||
|
||||
if (encryption != null) {
|
||||
securityInfo.put("isEncrypted", true);
|
||||
securityInfo.put("keyLength", encryption.getLength());
|
||||
|
||||
|
||||
// Get permissions
|
||||
Map<String, Boolean> permissions = new HashMap<>();
|
||||
permissions.put("canPrint", document.getCurrentAccessPermission().canPrint());
|
||||
permissions.put("canModify", document.getCurrentAccessPermission().canModify());
|
||||
permissions.put("canExtractContent", document.getCurrentAccessPermission().canExtractContent());
|
||||
permissions.put("canModifyAnnotations", document.getCurrentAccessPermission().canModifyAnnotations());
|
||||
|
||||
|
||||
securityInfo.put("permissions", permissions);
|
||||
} else {
|
||||
securityInfo.put("isEncrypted", false);
|
||||
}
|
||||
|
||||
|
||||
return securityInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user