-
-
Notifications
You must be signed in to change notification settings - Fork 848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Responsive PDF with Annotations layer #575
Comments
Don't fiddle with css, just set page width like this:
|
@oldboyxx Would be good to use e.g. ResizeObserver on documentWrapperRef, but your solution is definitely getting there :) React-PDF gotta know the exact render size to render all layers properly. |
When I use this fix, I have a new issue, each time I change the page the content around blink or move!!! Any idea? |
How do you add zoomIn/zoomOut capabilities when having a fixed width? |
@gugol2 This code below worked perfectly for the following conditions:
Note: I have multiplied with Default state const [isFullscreen, setIsFS] = useState(false);
const [scale, setScale] = useState(0.6);
const [sidebar, setSidebar] = useState(true);
const pdfWrapperRef = React.useRef(); Toolbar Zoom In/Out & Focus Mode <Tooltip placement="left" title="Zoom Out">
<ToolbarButton
type="primary"
icon={<MinusOutlined />}
disabled={scale <= 0.4}
onClick={() => setScale(scale-0.2)}
/>
</Tooltip>
<Tooltip placement="left" title="Zoom In">
<ToolbarButton
type="primary"
icon={<PlusOutlined />}
disabled={scale >= 1}
onClick={() => setScale(scale+0.2)}
/>
</Tooltip>
<Tooltip
placement="left"
title={
sidebar ? 'Activate Focus Mode' : 'De-activate Focus Mode'
}
>
<ToolbarButton
type="primary"
icon={<AimOutlined />}
style={{
background: sidebar ? '#fff' : '#0190be',
color: sidebar ? '#0190be' : '#fff',
}}
onClick={() => {
if(!sidebar) {
setScale(0.8);
}
toggleSidebar(!sidebar);
}}
/>
</Tooltip> Passing props to PDF FC <div ref={pdfWrapperRef}>
<PDF
pdf={pdf}
scale={scale}
page={pageNumber}
pdfWrapperRef={pdfWrapperRef}
onSuccess={onDocumentLoadSuccess}
/>
</div> PDF Component const PDF: React.FC<PDFType> = ({
pdf,
scale,
page,
pdfWrapperRef,
onSuccess,
}) => (
<Document
file={pdf}
renderMode="canvas"
loading={<LottieSplash animationData={splash} />}
onLoadSuccess={onSuccess}
onLoadError={console.error}
error={
'Unable to load the library article. Please reach out to the support for further assistance.'
}
>
<Flex
flexDirection="row"
style={{
justifyContent: 'space-around'
}}
>
<FirstPage
scale={scale}
width={(
pdfWrapperRef.current?.getBoundingClientRect().width*.95
) || undefined}
pageNumber={page}
/>
</Flex>
</Document>
); |
How did you handle fullscreen? Can't see it in your example |
What am I trying to achieve?
I want the PDF Document to scale down as the screen size scales down so everything looks good on mobile, while still maintaining the annotations layer for clickable links.
Describe solutions I've tried
I have pretty much the same problem as this unresolved issue: #339 , I tried his solution and a few others, to no avail. I can get the document page to scale down, but the annotations layer is not scaling down with the page.
I don't see anything that works with my setup, am I missing something to get the annotations layer to also be responsive?
My current code:
pdf.css:
Article component:
Environment
The text was updated successfully, but these errors were encountered: