Skip to content

How to get the page count of a document #780

Closed

Description

@richylyq

Hi,

I would like to know if it is possible to get the page count of a document in this library. If it is possible, how should I go about doing it.

Thanks in advance!

Activity

  1. shashwat-vik commented on Apr 2, 2020

    @shashwat-vik

    Had the same issue. Couldn't find any native approach.
    So read from the XML property file present in DOCX using only the standard libraries (python 3.5):

    import zipfile, re
    
    def getDocxPageCount(docx_fpath):
        docx_object = zipfile.ZipFile(docx_fpath)
        docx_property_file_data = docx_object.read('docProps/app.xml').decode()
        page_count = re.search(r"<Pages>(\d+)</Pages>", docx_property_file_data).group(1)
        return int(page_count)
    
  2. PasaOpasen commented on Aug 29, 2025

    @PasaOpasen

    import zipfile, re

    def getDocxPageCount(docx_fpath):
    docx_object = zipfile.ZipFile(docx_fpath)
    docx_property_file_data = docx_object.read('docProps/app.xml').decode()
    page_count = re.search(r"(\d+)", docx_property_file_data).group(1)
    return int(page_count)

    works properly only when there are pagebreaks between each page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions