3

I want to paginate an ePub file based on how many words are there per page, then to insert the "page numbers" into the ePub file. In this case, I will have the same page numbers while I read this file on different devices.

Is there a way to achieve this? Thanks!

2

It's not possible to dynamically change content in epub2 books, however, you could theoretically use JavaScript in an epub3 book to re-paginate a book, however, this would be overkill, since the epub3 standard supports page numbers.

Unfortunately, very few freeware apps besides iBooks (iOS, macOS) and Azardi (Windows, macOS, Linux) support epub3 page numbers.

If your book is a textbook, you might want to consider using a print-on-demand service provider.

0

I figured out a way to do this. It s not a perfect solution, but it works!

The idea is that I convert a ePub file to a Word file using calibre. I then use the Macros function of the Microsoft Word to insert the calculated "page numbers" into the text. Finally, I convert the modified Word file back to a ePub file using calibre again.

Here is the code if you are interested in. Please google it if you do not know how to use the Macros function. It's simple.

Modify the code to suit your purpose:

  1. In this code, I define a page has 300 word. You can change it to whatever you want.
  2. The page number looks like "8 ". You can change it to other format like "(8)"...

 

Sub DemoWords()
Application.ScreenUpdating = False
Dim Rng As Range, i As Long, j As Long, k As Long, w As Long
Const l As Long = 300   'Word per page, now 300
With ActiveDocument
  Set Rng = .Range(0, 0)
  With .Range
    For i = 1 To .Words.Count Step l
      Rng.MoveEnd wdWord, l
      With Rng
        .Collapse wdCollapseEnd
        .InsertBefore "__" & Round(i / l) + 1 & "__ "
        .Collapse wdCollapseEnd
      End With
    Next
  End With
End With
Application.ScreenUpdating = True
End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.