Answers.Body: <p>I figured out a way to do this. It
  s not a perfect solution, but it works!</p>
  
  <p>The idea is that I convert a ePub file to a Word file using <a href="https://calibre-ebook.com/download?" rel="nofollow noreferrer">calibre</a>. I then use the <strong>Macros</strong> 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. </p>
  
  <p>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. </p>
  
  <p>Modify the code to suit your purpose:</p>
  
  <ol>
  <li>In this code, I define a page has 300 word. You can change it to whatever you want.</li>
  <li>The page number looks like "<strong>8</strong> ". You can change it to other format like "(8)"...</li>
  </ol>
  
  <p>&nbsp;</p>
  
  <pre><code>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 "__" &amp; Round(i / l) + 1 &amp; "__ "
          .Collapse wdCollapseEnd
        End With
      Next
    End With
  End With
  Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-23T15:24:44.777Z
Answers.LastActivityDate: 2018-07-06T12:07:50.623Z
Answers.LastEditDate: 2018-07-06T12:07:50.623Z
Answers.UserDisplayName: Kevin
Body: <p>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.</p>
  
  <p>Is there a way to achieve this? Thanks!</p>
  
Tags: <epub><page-break>
Title: How to insert calculated page numbers based on word counting into an ePub file?
UserDisplayName: Kevin
ThreadText: # How to insert calculated page numbers based on word counting into an ePub file?
  
  (Asked by: username_0 on 2018-03-09)
  
  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!
  
  **Tags:** epub, page-break
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-06-23. Score: 0 | Accepted answer
  
  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](https://calibre-ebook.com/download?). 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
  
  ```
  
  
  ---
  
  