Skip to content

Commit

Permalink
🤖 format everything with pre-commit by <stirlingbot> (#2794)
Browse files Browse the repository at this point in the history
Auto-generated by [create-pull-request][1] with **stirlingbot**

[1]: https://github.com/peter-evans/create-pull-request

Signed-off-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
  • Loading branch information
stirlingbot[bot] authored Jan 30, 2025
1 parent e690b09 commit 3220ad2
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
@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())) {
Expand All @@ -47,7 +47,7 @@ public Map<String, Object> getBasicInfo(@ModelAttribute PDFFile file) throws IOE
}

@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())) {
Expand All @@ -66,13 +66,13 @@ public Map<String, String> getDocumentProperties(@ModelAttribute PDFFile file) t
}

@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());
Expand All @@ -84,13 +84,13 @@ public List<Map<String, Float>> getPageDimensions(@ModelAttribute PDFFile file)
}

@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());
Expand All @@ -105,7 +105,7 @@ public Map<String, Object> getFormFields(@ModelAttribute PDFFile file) throws IO
}

@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())) {
Expand All @@ -128,7 +128,7 @@ public Map<String, Object> getAnnotationInfo(@ModelAttribute PDFFile file) throw
}

@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())) {
Expand All @@ -148,33 +148,33 @@ public Map<String, Object> getFontInfo(@ModelAttribute PDFFile file) throws IOEx
}

@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;
}
}



}

}

0 comments on commit 3220ad2

Please sign in to comment.