Description of the Bug
In frontend/src/hooks/usePdfSearch.ts, the search text positions are extracted from raw PDF coordinate space:
item.transform[4] // x position in PDF units (~1/72 inch)
item.transform[5] // y position in PDF units (~1/72 inch)
In frontend/src/components/chat/PDFViewer.tsx, these values are used directly as CSS pixel values for the highlight overlay:
left: ${r.left}px // raw PDF unit → used as CSS px
top: ${r.top}px // raw PDF unit → used as CSS px
PDF coordinate space is measured in points (1/72 inch), while CSS uses pixels (1/96 inch on standard displays). Additionally, the PDF page may be rendered at a different scale factor (e.g., "fit width" or zoom level). The actual coordinates can be orders of magnitude off from the rendered page pixels.
Furthermore, the highlight width and height are hardcoded:
These hardcoded values are unrelated to the actual text bounding box.
The result is that search highlights appear in completely wrong positions on the PDF page, making the search feature misleading.
Steps to Reproduce
- Open a PDF document in the viewer
- Use the search feature to find a word
- Observe that the highlight rectangle appears in the wrong position on the page
- The highlight size is also incorrect (fixed 50x10px regardless of the text)
Expected Behavior
Search highlight positions should be transformed from PDF coordinate space to CSS pixel space using the page's viewport transform and current zoom level.
Affected Files
frontend/src/hooks/usePdfSearch.ts (lines ~40-46)
frontend/src/components/chat/PDFViewer.tsx (highlight overlay)
Suggested Fix
Transform PDF coordinates to CSS pixel values:
const viewport = page.getViewport({ scale: currentScale });
const transformed = viewport.convertToViewportPoint(
item.transform[4], item.transform[5]
);
// Now use transformed coordinates as pixel values
GSSoC '26
Description of the Bug
In
frontend/src/hooks/usePdfSearch.ts, the search text positions are extracted from raw PDF coordinate space:In
frontend/src/components/chat/PDFViewer.tsx, these values are used directly as CSS pixel values for the highlight overlay:PDF coordinate space is measured in points (1/72 inch), while CSS uses pixels (1/96 inch on standard displays). Additionally, the PDF page may be rendered at a different scale factor (e.g., "fit width" or zoom level). The actual coordinates can be orders of magnitude off from the rendered page pixels.
Furthermore, the highlight width and height are hardcoded:
These hardcoded values are unrelated to the actual text bounding box.
The result is that search highlights appear in completely wrong positions on the PDF page, making the search feature misleading.
Steps to Reproduce
Expected Behavior
Search highlight positions should be transformed from PDF coordinate space to CSS pixel space using the page's viewport transform and current zoom level.
Affected Files
frontend/src/hooks/usePdfSearch.ts(lines ~40-46)frontend/src/components/chat/PDFViewer.tsx(highlight overlay)Suggested Fix
Transform PDF coordinates to CSS pixel values:
GSSoC '26