mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 08:52:28 +01:00
feat: add "Add Page Labels" tool to the application
- Introduced a new tool for adding page labels to PDF documents, allowing users to apply Roman numerals, prefixes, and custom numbering ranges. - Created a new HTML page for the tool with a user-friendly interface for file upload and label rule configuration. - Implemented logic for handling file uploads, processing PDF files, and applying page labels based on user-defined rules. - Added necessary types and utility functions for managing page label styles and normalization of start values. - Updated main application configuration to include the new tool in the navigation. - Added tests for page label utilities to ensure correct functionality.
This commit is contained in:
1 parent
31f43b557f
commit
477839f106
27 files changed
+2318
No files matched your search
@@ -0,0 +1,54 @@
|
||||
import type { PageLabelStyleName } from '@/types';
|
||||
|
||||
export const PAGE_LABEL_STYLE_OPTIONS = [
|
||||
'DecimalArabic',
|
||||
'LowercaseRoman',
|
||||
'UppercaseRoman',
|
||||
'LowercaseLetters',
|
||||
'UppercaseLetters',
|
||||
'NoLabelPrefixOnly',
|
||||
] as const satisfies readonly PageLabelStyleName[];
|
||||
|
||||
export type { PageLabelStyleName } from '@/types';
|
||||
|
||||
type CpdfLabelStyleSource = {
|
||||
decimalArabic: number;
|
||||
lowercaseRoman: number;
|
||||
uppercaseRoman: number;
|
||||
lowercaseLetters: number;
|
||||
uppercaseLetters: number;
|
||||
noLabelPrefixOnly?: number;
|
||||
};
|
||||
|
||||
const NO_LABEL_PREFIX_ONLY_FALLBACK = 5 as CpdfLabelStyle;
|
||||
|
||||
export function resolvePageLabelStyle(
|
||||
cpdf: CpdfLabelStyleSource,
|
||||
style: PageLabelStyleName
|
||||
): CpdfLabelStyle {
|
||||
switch (style) {
|
||||
case 'DecimalArabic':
|
||||
return cpdf.decimalArabic as CpdfLabelStyle;
|
||||
case 'LowercaseRoman':
|
||||
return cpdf.lowercaseRoman as CpdfLabelStyle;
|
||||
case 'UppercaseRoman':
|
||||
return cpdf.uppercaseRoman as CpdfLabelStyle;
|
||||
case 'LowercaseLetters':
|
||||
return cpdf.lowercaseLetters as CpdfLabelStyle;
|
||||
case 'UppercaseLetters':
|
||||
return cpdf.uppercaseLetters as CpdfLabelStyle;
|
||||
case 'NoLabelPrefixOnly':
|
||||
return (
|
||||
(cpdf.noLabelPrefixOnly as CpdfLabelStyle | undefined) ??
|
||||
NO_LABEL_PREFIX_ONLY_FALLBACK
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizePageLabelStartValue(value: number): number {
|
||||
if (!Number.isFinite(value)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Math.max(0, Math.floor(value));
|
||||
}
|
||||
Reference in new issue
Block a user