feat: add Images to PDF conversion tool (closes #261)#272
feat: add Images to PDF conversion tool (closes #261)#272iib0011 merged 2 commits intoiib0011:mainfrom
Conversation
| heightPx: number; | ||
| } | null>(null); | ||
|
|
||
| const compute = async (file: File | null, currentScale: number) => { |
There was a problem hiding this comment.
Create a service.ts file with this util method
| } | ||
| }; | ||
|
|
||
| useEffect(() => { |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
Here; just the input box has to be in the inputComponent.
The following options will be added in getGroups props
| <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> |
There was a problem hiding this comment.
This have to be moved in getGroups props.
| resultComponent={ | ||
| <ToolFileResult title={'Output PDF'} value={result} extension={'pdf'} /> | ||
| } | ||
| compute={() => compute(input, scale)} |
| 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); |
There was a problem hiding this comment.
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
Chesterkxng
left a comment
There was a problem hiding this comment.
Thanks you for your contribution.
Please checkout the changes requested.
Description
This PR implements the feature requested in #261 — converting images to PDF.
Changes
ConvertToPdftool under PDF toolsjsPDFfor PDF generation