Skip to content

Conversation

@Ovgodd
Copy link
Collaborator

@Ovgodd Ovgodd commented Nov 17, 2025

Purpose

Ensure images maintain their original aspect ratio in PDF exports, aligning behavior with DOCX/ODT exports

image

Proposal

  • Ensure getImageDimensions() supports both SVG and raster formats
  • Apply proportional height calculation in the PDF renderer
  • Add MAX_WIDTH constraint to match DOCX/ODT behavior

@Ovgodd Ovgodd requested a review from AntoLC November 17, 2025 15:34
@Ovgodd Ovgodd self-assigned this Nov 17, 2025
@Ovgodd Ovgodd added bug Something isn't working export labels Nov 17, 2025
@Ovgodd Ovgodd force-pushed the fix/export-pdf-images-size branch 2 times, most recently from 187657b to 40a5394 Compare November 17, 2025 15:38
@Ovgodd Ovgodd marked this pull request as ready for review November 17, 2025 15:38
@github-actions
Copy link

github-actions bot commented Nov 17, 2025

Size Change: +58 B (0%)

Total Size: 4.07 MB

Filename Size Change
apps/impress/out/_next/static/53d702ff/_buildManifest.js 0 B -883 B (removed) 🏆
apps/impress/out/_next/static/dcd68386/_buildManifest.js 883 B +883 B (new file) 🆕

compressed-size-action

Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

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

Definitively a great improvement !


const PIXELS_PER_POINT = 0.75;
const FONT_SIZE = 16;
const MAX_WIDTH = 600;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it not duplicate with FALLBACK_SIZE ?

Copy link
Collaborator Author

@Ovgodd Ovgodd Nov 18, 2025

Choose a reason for hiding this comment

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

Is it not duplicate with FALLBACK_SIZE ?

They are up to different things:

  • MAX_WIDTH = 600: Maximum width in PDF to prevent images from overflowing the page

Comment on lines 26 to 38
pngConverted = await convertSvgToPng(svgText, previewWidth);

// Get actual dimensions from the converted PNG
if (typeof window !== 'undefined') {
const img = document.createElement('img');
img.src = pngConverted;
await new Promise((resolve) => {
img.onload = () => {
dimensions = { width: img.width, height: img.height };
resolve(null);
};
});
}
Copy link
Collaborator

@AntoLC AntoLC Nov 18, 2025

Choose a reason for hiding this comment

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

I can see we have some informations in convertSvgToPng, could we do something like that maybe ?

const {
  png,
  width: pngWidth,
  height: pngHeight,
} = await convertSvgToPng(svgText, previewWidth);

pngConverted = png;
dimensions = { width: pngWidth, height: pngHeight };

Copy link
Collaborator Author

@Ovgodd Ovgodd Nov 18, 2025

Choose a reason for hiding this comment

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

oh yes and I have to update imageODT and imageDOCS too !

Comment on lines 69 to 73
async function getImageDimensions(blob: Blob) {
if (typeof window !== 'undefined') {
const bmp = await createImageBitmap(blob);
const { width, height } = bmp;
bmp.close();
return { width, height };
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am a bit concerned about potential performance implications when lot of images and heavy images, is there maybe a less greedy way to get the size of an images?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh I see, after research wdyt by switched to document.createElement('img') which should be lighter than createImageBitmap(). This matches the approach already used in imageDocx.tsx

I put it in a new fixup

@Ovgodd Ovgodd force-pushed the fix/export-pdf-images-size branch 2 times, most recently from 315a885 to 1c38592 Compare November 18, 2025 10:53
@Ovgodd Ovgodd requested a review from AntoLC November 18, 2025 10:53
@Ovgodd Ovgodd force-pushed the fix/export-pdf-images-size branch from 1c38592 to ce469ac Compare November 18, 2025 14:36
images were distorted in PDF exports; height is now computed to fix that

Signed-off-by: Cyril <c.gromoff@gmail.com>
@Ovgodd Ovgodd force-pushed the fix/export-pdf-images-size branch from ce469ac to 2e64298 Compare November 18, 2025 14:36
@Ovgodd Ovgodd merged commit 2e64298 into main Nov 18, 2025
21 of 22 checks passed
@Ovgodd Ovgodd deleted the fix/export-pdf-images-size branch November 18, 2025 15:08
@AntoLC AntoLC linked an issue Nov 18, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working export

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The PDF exporter shrinks images

3 participants