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

Page number #5

Open
DZESU opened this issue Nov 14, 2019 · 12 comments
Open

Page number #5

DZESU opened this issue Nov 14, 2019 · 12 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@DZESU
Copy link

DZESU commented Nov 14, 2019

Hi,
I wonder if there is a way to show the current page number that is showing to the user?

@Dmitry-Borodin
Copy link
Owner

Dmitry-Borodin commented Feb 4, 2020

Currently not implemented, but would be nice to have it.
I"m just not sure how it can be done in regards of performance. Any thoughts are welcome.

@Dmitry-Borodin Dmitry-Borodin added enhancement New feature or request help wanted Extra attention is needed labels Feb 4, 2020
@mspnr
Copy link
Contributor

mspnr commented Aug 11, 2020

Here is an idea:

  1. Based on vTranslate and scale we know in general where the PDF as a scroll is positioned.
  2. If we would know total number of pages or the height of a single page, then based on sHeight we could calculate the current page
  3. The only piece, which is missing is total number of pages, which can be retrieved from PDFRegionDecoder (from init or separately)

Regarding the implementation:

  1. Current page can be saved in a variable
  2. As soon as the page has changed, a simple callback could be triggered, returning the page number. Checking current page variable will allow to reduce "triggering frequency".

You do so many complicated calculations, so one another arithmetic expression and one callback in a while will not for sure fall back the overall performance.

@Dmitry-Borodin
Copy link
Owner

I'm not sure if we need math here.
We have loop where we render pages one by one here com/pdfview/PDFRegionDecoder.kt:46
So we can just add some custom super simple bitmap (separator) after each page.
And we can draw page number to the same bitmap where we draw pdf page, or to separator, I'm not sure what is the best approach.

@mspnr
Copy link
Contributor

mspnr commented Aug 13, 2020

It is not a problem to technically draw any text any size any color in decodeRegion. One can use canvas.drawText for that.
The problem is this solution is not elegant.

PDFs are usually beautifully formatted with carefully measured margins, colors etc. If we would implement that solution we can assume, that the page number should be place 5mm from the page border on the left bottom side with size 10 points, black color and the default font type face. But what if the page background is black in this area, or there is already some text, or the font type face is inappropriate there etc.
PDFs have a quality of "immutability" and by drawing something on the pages we can break them and give the resulting picture some "machinery" smell.

That's why I suggested a callback. Page number can be incorporated somewhere on the App bar or on a separate Text view, which can conform with application design and the user can comprehend: "This number is not a part of the PDF".

@Dmitry-Borodin
Copy link
Owner

This is a very good point.
We will have to find out how to calculate it properly, without making codebase much more difficult, and when to decide which page is shown if user is in between 2 pages.
I'm trying to follow KISS principle and making it small and simple. But it would be great to implement page numbers, while separate concerns and in easy to understand way.

@petrovichtim
Copy link

Are there any changes in this issue? We also need to get the current page of the pdf document.

@Dmitry-Borodin
Copy link
Owner

Nope, but you are welcome to provide method to get current page and open PR.
I will publich is to MavenCentral within a month and will be able to release updates.

@petrovichtim
Copy link

Nope, but you are welcome to provide method to get current page and open PR.
I will publich is to MavenCentral within a month and will be able to release updates.

Do you have a telegram account ? I have a job offer

@Dmitry-Borodin
Copy link
Owner

Do you have a telegram account ? I have a job offer

I already have a job, thank you.

@eduyash09
Copy link

Is there any update on this issue or the development on the library is closed?

@Dmitry-Borodin
Copy link
Owner

It's not under active development, I hope to find some time to add compose implementation though.

If you want to add page number - you are welcome to research how can it be done and I'll gladly release an update if we can do it in a good way.

@eduyash09
Copy link

OK, I'll try as the library is pretty good, only the page number and feature of space between two page is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants