mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 00:28:39 +01:00
- 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.
55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
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));
|
|
}
|