Skip to content

feat: add Images to PDF conversion tool (closes #261)#272

Merged
iib0011 merged 2 commits intoiib0011:mainfrom
mgrivalsky:feature/images-to-pdf
Oct 29, 2025
Merged

feat: add Images to PDF conversion tool (closes #261)#272
iib0011 merged 2 commits intoiib0011:mainfrom
mgrivalsky:feature/images-to-pdf

Conversation

@mgrivalsky
Copy link

Description

This PR implements the feature requested in #261 — converting images to PDF.

Changes

  • Added ConvertToPdf tool under PDF tools
  • Implemented image scaling, orientation, and page type options
  • Integrated jsPDF for PDF generation
  • Added unit tests
  • Updated language support and UI text

heightPx: number;
} | null>(null);

const compute = async (file: File | null, currentScale: number) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a service.ts file with this util method

}
};

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this useEffect, You should use the same signature for the compute function as in the protect-pdf index file
and use it in ToolContent (compute={compute})

title={title}
input={input}
inputComponent={
<Box display="flex" flexDirection="column" gap={3}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here; just the input box has to be in the inputComponent.
The following options will be added in getGroups props

Comment on lines +126 to +192
<Box>
<Typography gutterBottom>PDF Type</Typography>
<RadioGroup
row
value={pageType}
onChange={(e) => setPageType(e.target.value as 'a4' | 'full')}
>
<FormControlLabel
value="a4"
control={<Radio />}
label="A4 Page"
/>
<FormControlLabel
value="full"
control={<Radio />}
label="Full Size (Same as Image)"
/>
</RadioGroup>

{pageType === 'full' && imageSize && (
<Typography variant="body2" color="text.secondary">
Image size: {imageSize.widthMm.toFixed(1)} ×{' '}
{imageSize.heightMm.toFixed(1)} mm ({imageSize.widthPx} ×{' '}
{imageSize.heightPx} px)
</Typography>
)}
</Box>

{pageType === 'a4' && (
<>
<Box>
<Typography gutterBottom>Orientation</Typography>
<RadioGroup
row
value={orientation}
onChange={(e) =>
setOrientation(e.target.value as 'portrait' | 'landscape')
}
>
<FormControlLabel
value="portrait"
control={<Radio />}
label="Portrait (Vertical)"
/>
<FormControlLabel
value="landscape"
control={<Radio />}
label="Landscape (Horizontal)"
/>
</RadioGroup>
</Box>

<Box>
<Typography gutterBottom>Scale image: {scale}%</Typography>
<Slider
value={scale}
onChange={(_, v) => setScale(v as number)}
onChangeCommitted={(_, v) => compute(input, v as number)}
min={10}
max={100}
step={1}
valueLabelDisplay="auto"
/>
</Box>
</>
)}
</Box>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This have to be moved in getGroups props.

resultComponent={
<ToolFileResult title={'Output PDF'} value={result} extension={'pdf'} />
}
compute={() => compute(input, scale)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compute={compute}

Comment on lines +19 to +29
const [scale, setScale] = useState<number>(100);
const [orientation, setOrientation] = useState<'portrait' | 'landscape'>(
'portrait'
);
const [pageType, setPageType] = useState<'a4' | 'full'>('a4');
const [imageSize, setImageSize] = useState<{
widthMm: number;
heightMm: number;
widthPx: number;
heightPx: number;
} | null>(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a file nammed types.ts for InitialValuesType then initialize it before the react component.
for every comment, you can check what has been done in protect-pdf folder for example

Copy link
Collaborator

@Chesterkxng Chesterkxng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for your contribution.
Please checkout the changes requested.

Copy link
Collaborator

@Chesterkxng Chesterkxng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work !

@iib0011 iib0011 merged commit f3c5946 into iib0011:main Oct 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants