[V2] feat(convert): add PDF/X export option (#5285)

# Description of Changes

This pull request adds support for converting PDF files to PDF/X format
in the frontend, alongside the existing PDF/A conversion. The changes
include UI updates, translation strings, configuration, and processing
logic to enable PDF to PDF/X conversion using the same backend endpoint
as PDF/A, with appropriate user options and warnings.

**PDF/X Conversion Support:**

- Added a new `ConvertToPdfxSettings` component for configuring PDF/X
conversion options, including output format selection and digital
signature warnings.
(`frontend/src/core/components/tools/convert/ConvertToPdfxSettings.tsx`)
- Updated the conversion settings UI to display PDF/X options when
converting from PDF to PDF/X.
(`frontend/src/core/components/tools/convert/ConvertSettings.tsx`)

**Configuration and Processing Logic:**

- Extended conversion constants and parameters to recognize PDF/X as a
target format, map it to the PDF/A backend endpoint, and ensure correct
file naming and processing behavior.
(`frontend/src/core/constants/convertConstants.ts`,
`frontend/src/core/hooks/tools/convert/useConvertOperation.ts`,
`frontend/src/core/hooks/tools/convert/useConvertParameters.ts`)
- Ensured that PDF/X conversions are processed separately per file,
similar to PDF/A.
(`frontend/src/core/hooks/tools/convert/useConvertOperation.ts`)

**UI and Translation Updates:**

- Updated translation strings to include PDF/X options, descriptions,
and warnings. (`frontend/public/locales/en-GB/translation.toml`)

<img width="366" height="998" alt="image"
src="https://github.com/user-attachments/assets/b28fa095-9350-4db2-a0b5-bddcf003fa46"
/>


<!--
Please provide a summary of the changes, including:

- What was changed
- Why the change was made
- Any challenges encountered

Closes #(issue_number)
-->

---

## Checklist

### General

- [ ] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [ ] I have read the [Stirling-PDF Developer
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md)
(if applicable)
- [ ] I have read the [How to add new languages to
Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md)
(if applicable)
- [ ] I have performed a self-review of my own code
- [ ] My changes generate no new warnings

### Documentation

- [ ] I have updated relevant docs on [Stirling-PDF's doc
repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/)
(if functionality has heavily changed)
- [ ] I have read the section [Add New Translation
Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags)
(for new translation tags only)

### Translations (if applicable)

- [ ] I ran
[`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md)

### UI Changes (if applicable)

- [ ] Screenshots or videos demonstrating the UI changes are attached
(e.g., as comments or direct attachments in the PR)

### Testing (if applicable)

- [ ] I have tested my changes locally. Refer to the [Testing
Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing)
for more details.

---------

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
Balázs Szücs
2026-01-23 16:50:39 +01:00
committed by GitHub
parent 039e3b5fa8
commit 4d84dcdd42
10 changed files with 145 additions and 22 deletions

View File

@@ -17,6 +17,7 @@ import ConvertFromEmailSettings from "@app/components/tools/convert/ConvertFromE
import ConvertFromCbzSettings from "@app/components/tools/convert/ConvertFromCbzSettings";
import ConvertToCbzSettings from "@app/components/tools/convert/ConvertToCbzSettings";
import ConvertToPdfaSettings from "@app/components/tools/convert/ConvertToPdfaSettings";
import ConvertToPdfxSettings from "@app/components/tools/convert/ConvertToPdfxSettings";
import ConvertFromCbrSettings from "@app/components/tools/convert/ConvertFromCbrSettings";
import ConvertToCbrSettings from "@app/components/tools/convert/ConvertToCbrSettings";
import ConvertFromEbookSettings from "@app/components/tools/convert/ConvertFromEbookSettings";
@@ -147,6 +148,9 @@ const ConvertSettings = ({
onParameterChange('pdfaOptions', {
outputFormat: 'pdfa-1',
});
onParameterChange('pdfxOptions', {
outputFormat: 'pdfx',
});
onParameterChange('cbrOptions', {
optimizeForEbook: false,
});
@@ -232,6 +236,9 @@ const ConvertSettings = ({
onParameterChange('pdfaOptions', {
outputFormat: 'pdfa-1',
});
onParameterChange('pdfxOptions', {
outputFormat: 'pdfx',
});
onParameterChange('cbrOptions', {
optimizeForEbook: false,
});
@@ -406,6 +413,19 @@ const ConvertSettings = ({
</>
)}
{/* PDF to PDF/X options */}
{parameters.fromExtension === 'pdf' && parameters.toExtension === 'pdfx' && (
<>
<Divider />
<ConvertToPdfxSettings
parameters={parameters}
onParameterChange={onParameterChange}
selectedFiles={selectedFiles}
disabled={disabled}
/>
</>
)}
{/* eBook to PDF options */}
{['epub', 'mobi', 'azw3', 'fb2'].includes(parameters.fromExtension) && parameters.toExtension === 'pdf' && (
<>

View File

@@ -0,0 +1,31 @@
import { useEffect } from 'react';
import { ConvertParameters } from '@app/hooks/tools/convert/useConvertParameters';
import { StirlingFile } from '@app/types/fileContext';
interface ConvertToPdfxSettingsProps {
parameters: ConvertParameters;
onParameterChange: <K extends keyof ConvertParameters>(key: K, value: ConvertParameters[K]) => void;
selectedFiles: StirlingFile[];
disabled?: boolean;
}
const ConvertToPdfxSettings = ({
parameters,
onParameterChange,
selectedFiles: _selectedFiles,
disabled: _disabled = false
}: ConvertToPdfxSettingsProps) => {
// Automatically set PDF/X-3 format when this component is rendered
useEffect(() => {
if (parameters.pdfxOptions.outputFormat !== 'pdfx-3') {
onParameterChange('pdfxOptions', {
...parameters.pdfxOptions,
outputFormat: 'pdfx-3'
});
}
}, [parameters.pdfxOptions.outputFormat, onParameterChange]);
return null;
};
export default ConvertToPdfxSettings;

View File

@@ -110,6 +110,7 @@ export const FROM_FORMAT_OPTIONS = [
export const TO_FORMAT_OPTIONS = [
{ value: 'pdf', label: 'PDF', group: 'Document' },
{ value: 'pdfa', label: 'PDF/A', group: 'Document' },
{ value: 'pdfx', label: 'PDF/X', group: 'Document' },
{ value: 'docx', label: 'DOCX', group: 'Document' },
{ value: 'odt', label: 'ODT', group: 'Document' },
{ value: 'cbz', label: 'CBZ', group: 'Archive' },
@@ -136,7 +137,7 @@ export const TO_FORMAT_OPTIONS = [
export const CONVERSION_MATRIX: Record<string, string[]> = {
'any': ['pdf'], // Mixed files always convert to PDF
'image': ['pdf'], // Multiple images always convert to PDF
'pdf': ['png', 'jpg', 'gif', 'tiff', 'bmp', 'webp', 'docx', 'odt', 'pptx', 'odp', 'csv', 'txt', 'rtf', 'md', 'html', 'xml', 'pdfa', 'cbz', 'cbr', 'epub', 'azw3'],
'pdf': ['png', 'jpg', 'gif', 'tiff', 'bmp', 'webp', 'docx', 'odt', 'pptx', 'odp', 'csv', 'txt', 'rtf', 'md', 'html', 'xml', 'pdfa', 'pdfx', 'cbz', 'cbr', 'epub', 'azw3'],
'cbz': ['pdf'],
'docx': ['pdf'], 'doc': ['pdf'], 'odt': ['pdf'],
'xlsx': ['pdf'], 'xls': ['pdf'], 'ods': ['pdf'],
@@ -164,6 +165,7 @@ export const EXTENSION_TO_ENDPOINT: Record<string, Record<string, string>> = {
'txt': 'pdf-to-text', 'rtf': 'pdf-to-text', 'md': 'pdf-to-markdown',
'html': 'pdf-to-html', 'xml': 'pdf-to-xml',
'pdfa': 'pdf-to-pdfa',
'pdfx': 'pdf-to-pdfa', // PDF/X uses the same endpoint as PDF/A
'cbr': 'pdf-to-cbr',
'cbz': 'pdf-to-cbz',
'epub': 'pdf-to-epub', 'azw3': 'pdf-to-epub'

View File

@@ -19,8 +19,8 @@ export const shouldProcessFilesSeparately = (
(parameters.fromExtension === 'svg' && parameters.toExtension === 'pdf' && !parameters.imageOptions.combineImages) ||
// PDF to image conversions (each PDF should generate its own image file)
(parameters.fromExtension === 'pdf' && isImageFormat(parameters.toExtension)) ||
// PDF to PDF/A conversions (each PDF should be processed separately)
(parameters.fromExtension === 'pdf' && parameters.toExtension === 'pdfa') ||
// PDF to PDF/A and PDF/X conversions (each PDF should be processed separately)
(parameters.fromExtension === 'pdf' && (parameters.toExtension === 'pdfa' || parameters.toExtension === 'pdfx')) ||
// PDF to text-like formats should be one output per input
(parameters.fromExtension === 'pdf' && ['txt', 'rtf', 'csv'].includes(parameters.toExtension)) ||
// PDF to CBR conversions (each PDF should generate its own archive)
@@ -46,7 +46,7 @@ export const shouldProcessFilesSeparately = (
// Static function that can be used by both the hook and automation executor
export const buildConvertFormData = (parameters: ConvertParameters, selectedFiles: File[]): FormData => {
const formData = new FormData();
const { fromExtension, toExtension, imageOptions, htmlOptions, emailOptions, pdfaOptions, cbrOptions, pdfToCbrOptions, cbzOptions, cbzOutputOptions, ebookOptions, epubOptions } = parameters;
const { fromExtension, toExtension, imageOptions, htmlOptions, emailOptions, pdfaOptions, pdfxOptions, cbrOptions, pdfToCbrOptions, cbzOptions, cbzOutputOptions, ebookOptions, epubOptions } = parameters;
selectedFiles.forEach(file => {
formData.append("fileInput", file);
@@ -79,6 +79,9 @@ export const buildConvertFormData = (parameters: ConvertParameters, selectedFile
formData.append("includeAllRecipients", emailOptions.includeAllRecipients.toString());
} else if (fromExtension === 'pdf' && toExtension === 'pdfa') {
formData.append("outputFormat", pdfaOptions.outputFormat);
} else if (fromExtension === 'pdf' && toExtension === 'pdfx') {
// Use PDF/A endpoint with PDF/X format parameter
formData.append("outputFormat", pdfxOptions?.outputFormat || 'pdfx');
} else if (fromExtension === 'pdf' && toExtension === 'csv') {
formData.append("pageNumbers", "all");
} else if (fromExtension === 'cbr' && toExtension === 'pdf') {
@@ -112,7 +115,8 @@ export const createFileFromResponse = (
): File => {
const originalName = originalFileName.split('.')[0];
if (targetExtension == 'pdfa') {
// Map both pdfa and pdfx to pdf since they both result in PDF files
if (targetExtension == 'pdfa' || targetExtension == 'pdfx') {
targetExtension = 'pdf';
}
@@ -127,14 +131,21 @@ export const convertProcessor = async (
selectedFiles: File[]
): Promise<CustomProcessorResult> => {
const processedFiles: File[] = [];
const endpoint = getEndpointUrl(parameters.fromExtension, parameters.toExtension);
// Map PDF/X to use PDF/A endpoint
const actualToExtension = parameters.toExtension === 'pdfx' ? 'pdfa' : parameters.toExtension;
const endpoint = getEndpointUrl(parameters.fromExtension, actualToExtension);
if (!endpoint) {
throw new Error('Unsupported conversion format');
}
// Convert-specific routing logic: decide batch vs individual processing
const isSeparateProcessing = shouldProcessFilesSeparately(selectedFiles, parameters);
// For PDF/X, we want to treat it similar to PDF/A (separate processing)
const isSeparateProcessing = shouldProcessFilesSeparately(selectedFiles, {
...parameters,
toExtension: actualToExtension // Use the mapped extension for decision logic
});
if (isSeparateProcessing) {
// Individual processing for complex cases (PDF→image, smart detection, etc.)
@@ -143,7 +154,7 @@ export const convertProcessor = async (
const formData = buildConvertFormData(parameters, [file]);
const response = await apiClient.post(endpoint, formData, { responseType: 'blob' });
const convertedFile = createFileFromResponse(response.data, response.headers, file.name, parameters.toExtension);
const convertedFile = createFileFromResponse(response.data, response.headers, file.name, actualToExtension === 'pdfa' ? 'pdfx' : parameters.toExtension);
processedFiles.push(convertedFile);
} catch (error) {
@@ -159,7 +170,7 @@ export const convertProcessor = async (
? selectedFiles[0].name
: 'converted_files';
const convertedFile = createFileFromResponse(response.data, response.headers, baseFilename, parameters.toExtension);
const convertedFile = createFileFromResponse(response.data, response.headers, baseFilename, actualToExtension === 'pdfa' ? 'pdfx' : parameters.toExtension);
processedFiles.push(convertedFile);
}

View File

@@ -36,6 +36,9 @@ export interface ConvertParameters extends BaseParameters {
pdfaOptions: {
outputFormat: string;
};
pdfxOptions: {
outputFormat: string;
};
cbrOptions: {
optimizeForEbook: boolean;
};
@@ -92,6 +95,9 @@ export const defaultParameters: ConvertParameters = {
pdfaOptions: {
outputFormat: 'pdfa-1',
},
pdfxOptions: {
outputFormat: 'pdfx',
},
cbrOptions: {
optimizeForEbook: false,
},

View File

@@ -152,6 +152,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -231,6 +234,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -288,6 +294,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -354,6 +363,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -424,6 +436,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -492,6 +507,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -556,6 +574,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -617,6 +638,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -680,6 +704,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -740,6 +767,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -806,6 +836,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},
@@ -871,6 +904,9 @@ describe('Convert Tool Integration Tests', () => {
pdfaOptions: {
outputFormat: ''
},
pdfxOptions: {
outputFormat: 'pdfx'
},
cbrOptions: {
optimizeForEbook: false
},