mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-08-02 18:45:21 +00:00

🔄 Dynamic Processing Strategies - Adaptive routing: Same tool uses different backend endpoints based on file analysis - Combined vs separate processing: Intelligently chooses between merge operations and individual file processing - Cross-format workflows: Enable complex conversions like "mixed files → PDF" that other tools can't handle ⚙️ Format-Specific Intelligence Each conversion type gets tailored options: - HTML/ZIP → PDF: Zoom controls (0.1-3.0 increments) with live preview - Email → PDF: Attachment handling, size limits, recipient control - PDF → PDF/A: Digital signature detection with warnings - Images → PDF: Smart combining vs individual file options File Architecture Core Implementation: ├── Convert.tsx # Main stepped workflow UI ├── ConvertSettings.tsx # Centralized settings with smart detection ├── GroupedFormatDropdown.tsx # Enhanced format selector with grouping ├── useConvertParameters.ts # Smart detection & parameter management ├── useConvertOperation.ts # Multi-strategy processing logic └── Settings Components: ├── ConvertFromWebSettings.tsx # HTML zoom controls ├── ConvertFromEmailSettings.tsx # Email attachment options ├── ConvertToPdfaSettings.tsx # PDF/A with signature detection ├── ConvertFromImageSettings.tsx # Image PDF options └── ConvertToImageSettings.tsx # PDF to image options Utility Layer Utils & Services: ├── convertUtils.ts # Format detection & endpoint routing ├── fileResponseUtils.ts # Generic API response handling └── setupTests.ts # Enhanced test environment with crypto mocks Testing & Quality Comprehensive Test Coverage Test Suite: ├── useConvertParameters.test.ts # Parameter logic & smart detection ├── useConvertParametersAutoDetection.test.ts # File type analysis ├── ConvertIntegration.test.tsx # End-to-end conversion workflows ├── ConvertSmartDetectionIntegration.test.tsx # Mixed file scenarios ├── ConvertE2E.spec.ts # Playwright browser tests ├── convertUtils.test.ts # Utility function validation └── fileResponseUtils.test.ts # API response handling Advanced Test Features - Crypto API mocking: Proper test environment for file hashing - File.arrayBuffer() polyfills: Complete browser API simulation - Multi-file scenario testing: Complex batch processing validation - CI/CD integration: Vitest runs in GitHub Actions with proper artifacts --------- Co-authored-by: Connor Yoh <connor@stirlingpdf.com> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import * as pdfjsLib from 'pdfjs-dist';
|
|
|
|
export interface PdfSignatureDetectionResult {
|
|
hasDigitalSignatures: boolean;
|
|
isChecking: boolean;
|
|
}
|
|
|
|
export const usePdfSignatureDetection = (files: File[]): PdfSignatureDetectionResult => {
|
|
const [hasDigitalSignatures, setHasDigitalSignatures] = useState(false);
|
|
const [isChecking, setIsChecking] = useState(false);
|
|
|
|
useEffect(() => {
|
|
const checkForDigitalSignatures = async () => {
|
|
if (files.length === 0) {
|
|
setHasDigitalSignatures(false);
|
|
return;
|
|
}
|
|
|
|
setIsChecking(true);
|
|
let foundSignature = false;
|
|
|
|
try {
|
|
// Set up PDF.js worker
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdfjs-legacy/pdf.worker.mjs';
|
|
|
|
for (const file of files) {
|
|
const arrayBuffer = await file.arrayBuffer();
|
|
|
|
try {
|
|
const pdf = await pdfjsLib.getDocument({ data: arrayBuffer }).promise;
|
|
|
|
for (let i = 1; i <= pdf.numPages; i++) {
|
|
const page = await pdf.getPage(i);
|
|
const annotations = await page.getAnnotations({ intent: 'display' });
|
|
|
|
annotations.forEach(annotation => {
|
|
if (annotation.subtype === 'Widget' && annotation.fieldType === 'Sig') {
|
|
foundSignature = true;
|
|
}
|
|
});
|
|
|
|
if (foundSignature) break;
|
|
}
|
|
} catch (error) {
|
|
console.warn('Error analyzing PDF for signatures:', error);
|
|
}
|
|
|
|
if (foundSignature) break;
|
|
}
|
|
} catch (error) {
|
|
console.warn('Error checking for digital signatures:', error);
|
|
}
|
|
|
|
setHasDigitalSignatures(foundSignature);
|
|
setIsChecking(false);
|
|
};
|
|
|
|
checkForDigitalSignatures();
|
|
}, [files]);
|
|
|
|
return {
|
|
hasDigitalSignatures,
|
|
isChecking
|
|
};
|
|
}; |