Skip to content
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

[Feature Request] Dimensions/Height/Width of PDF file #302

Open
Zloka opened this issue Jan 18, 2019 · 18 comments
Open

[Feature Request] Dimensions/Height/Width of PDF file #302

Zloka opened this issue Jan 18, 2019 · 18 comments

Comments

@Zloka
Copy link

Zloka commented Jan 18, 2019

Is is possible to extract the dimensions of the PDF-file somehow?

My use-case is that I would like to render lists of varying components (headings, paragraphs, buttons and also PDF-files). fitPolicy={0} nicely make the PDFs full width, but I can't seem to get them to render without specifying a height. Furthermore, the dimensions of the PDFs can vary (e.g. some are longer), so hard-coding an arbitrary value doesn't work very well.

I figured since the screen width is known, it would be possible to set the correct height dynamically if one knows the dimensions of the PDF, but is this at all possible?

@Zloka
Copy link
Author

Zloka commented Jan 18, 2019

Never mind, noticed onLoadComplete supplies the dimensions. My bad, closing.

@Zloka Zloka closed this as completed Jan 18, 2019
@Zloka
Copy link
Author

Zloka commented Jan 21, 2019

Actually, I'd like to reopen this issue. It would seem that that onLoadComplete supplies the values for the component, not the actual PDF file. Is there a way of getting the actual paper size/dimensions?

@Zloka Zloka reopened this Jan 21, 2019
@NikitaSubbotin
Copy link

same issue

@NikitaSubbotin
Copy link

@wonday do you have any ideas how we can get pdf original size?

@wonday
Copy link
Owner

wonday commented Jan 23, 2019

Why need original size?
onLoadComplete return the width and height of pdf page.
You can give a view width and calculate view height by (pdf page height/width) * (view width), then set to obj.

@ObidosDev
Copy link

@wonday there exists another case, for example, you want to render something on top of pdf file, within specific place described with points depends on real pdf file sizes, so u need to convert it to current sizes using real sizes

@NikitaSubbotin
Copy link

the same document size returns different sizes on ios and android

@ReyRod
Copy link

ReyRod commented Jan 25, 2019

Problem is that dimensions provided in the component are of the canvas and not the real page size, native component used in this library currently doesn't provide that, i've made a PR into the native dependency so it can be returned and have the owner of this repo or maybe a PR to return the real page size provided by the native component and not the canvas DImuthuUpe/AndroidPdfViewer#743 DImuthuUpe/AndroidPdfViewer#742

@ebrarislami-technoperia

@Zloka Did you find any solution?

@Zloka
Copy link
Author

Zloka commented May 30, 2019

@ebrarislami-technoperia No, sadly I did not. Based on the issue you opened your use-case seems similar to mine.

@ReyRod
Copy link

ReyRod commented May 31, 2019 via email

@Zloka
Copy link
Author

Zloka commented May 31, 2019

Yup, that was our solution as well: including the dimensions as metadata sent alongside the file.

@ebrarislami-technoperia
Copy link

@ReyRod @Zloka Thanks. Using backend solution solved our issue too.

@kishansbs
Copy link

how can get exact pdf page height and width on onLoadComplete.

@raychan3690
Copy link

Maybe try pdfView.getPageSize(currentPage).width?

@meliodev
Copy link

Hi @Zloka ! How did you calculate dimensions before putting them as metadata ?

@Zloka
Copy link
Author

Zloka commented Nov 21, 2020

@meliodev I crop and compress the files in addition to measuring them, so the entire process is probably needlessly complex if all you want to do is calculate the dimensions.

Using pdf-lib, you could provide the PDF data as a Buffer, and then simply call something like:

import { PDFDocument } from 'pdf-lib';

// Up to you to provide buffer somehow.
const pdf = await PDFDocument.load(buffer);
const { width, height } = pdf.getPage(0).getSize(); // Get the first page or iterate all pages depending on your needs...

@meliodev
Copy link

@meliodev I crop and compress the files in addition to measuring them, so the entire process is probably needlessly complex if all you want to do is calculate the dimensions.

Using pdf-lib, you could provide the PDF data as a Buffer, and then simply call something like:

import { PDFDocument } from 'pdf-lib';

// Up to you to provide buffer somehow.
const pdf = await PDFDocument.load(buffer);
const { width, height } = pdf.getPage(0).getSize(); // Get the first page or iterate all pages depending on your needs...

Thanks @Zloka I'll try it !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants