Height issue while loading Document inside another component (Swiper) #1189
Unanswered
GeorgePals
asked this question in
Q&A
Replies: 1 comment 4 replies
-
You were really close. const page = await pdf.getPage(x);
const viewport = await page.getViewport({ scale: 1 });
const height = viewport.height; |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm not that sure if it is a Swiper or a
react-pdf
issue, but let me explain why I'm posting here.I have something like:
The issue is that, when
autoHeight
istrue
on Swiper, then the first slide is always ~158px in height, while the actual slide should be something like ~6.000px in height (it's the PDF :)).I've tried everything I could think of. From preloading the
SwiperSlides
(so, Swiper, can already "know" the height of the SwiperSlide) to, IDK, I've lost count.What I think that is the main issue is that the PDF and its dimensions are not "known" (even if preloaded), until it's actually added on the DOM.
I've also tried to "get the height" of the DIV that encloses the PDF, but for some reason, it didn't work.
The only way that the Swiper is able to display the slides (PDFs) correctly (and this is why I think that it is a react-pdf issue) is if I give the DIV that encloses the PDF, a constant height.
i.e.
but, of course, this can not work for the simple reason that not every PDF has the same height.
So, the question is: Can I, somehow, find out the height of the
<Document />
before adding it on the DOM? Is this possible? I've tried using the:await pdf.getPage(x).height
to get each page (so I can sum up the heights later), but I'm gettingundefined
for each page of the PDF.Edit: I've also tried:
width * A4AspectRatio * numPages
to get the height of the PDF, but guess what, it does not work because by the time that theheight
constraint is calculated, the PDF is already attached on the DOM.Edit 2: This seems to work (not 100%):
but, can I access the numPages earlier?
Any ideas on this are extremely welcome.
Sorry for not posting any code, but I think that I would make things much more difficult to explain, while this way, I'm posting directly the issue.
Thank you in advance for any contribution!
Beta Was this translation helpful? Give feedback.
All reactions