pdfview-android icon indicating copy to clipboard operation
pdfview-android copied to clipboard

Page number

Open DZESU opened this issue 5 years ago • 12 comments

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

DZESU avatar Nov 14 '19 03:11 DZESU

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 avatar Feb 04 '20 07:02 Dmitry-Borodin

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.

mspnr avatar Aug 11 '20 23:08 mspnr

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.

Dmitry-Borodin avatar Aug 12 '20 00:08 Dmitry-Borodin

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".

mspnr avatar Aug 13 '20 00:08 mspnr

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.

Dmitry-Borodin avatar Aug 13 '20 14:08 Dmitry-Borodin

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

petrovichtim avatar Jun 02 '21 06:06 petrovichtim

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.

Dmitry-Borodin avatar Jun 07 '21 13:06 Dmitry-Borodin

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

petrovichtim avatar Jun 19 '21 10:06 petrovichtim

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

I already have a job, thank you.

Dmitry-Borodin avatar Jun 20 '21 02:06 Dmitry-Borodin

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

eduyash09 avatar Jul 03 '23 14:07 eduyash09

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.

Dmitry-Borodin avatar Jul 03 '23 18:07 Dmitry-Borodin

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

eduyash09 avatar Jul 04 '23 05:07 eduyash09