pdfview-android
pdfview-android copied to clipboard
Page number
Hi, I wonder if there is a way to show the current page number that is showing to the user?
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.
Here is an idea:
- Based on
vTranslate
andscale
we know in general where the PDF as a scroll is positioned. - 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 - The only piece, which is missing is total number of pages, which can be retrieved from
PDFRegionDecoder
(from init or separately)
Regarding the implementation:
- Current page can be saved in a variable
- 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.
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.
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".
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.
Are there any changes in this issue? We also need to get the current page of the pdf document.
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.
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
Do you have a telegram account ? I have a job offer
I already have a job, thank you.
Is there any update on this issue or the development on the library is closed?
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.
OK, I'll try as the library is pretty good, only the page number and feature of space between two page is missing.