Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 format everything with pre-commit by <stirlingbot> #2794

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}



}

}
Loading