I am trying to read docx and pdf documents and save them in markdown format using aspose.words python. In this process, I want to preserve the page information when saving.
@pmrc MS Word documents are flow by their nature, so there is no “page” concept. Consumer application layouts the document content into pages on the fly. Aspose.Words has it’s own layout engine for this purpose. You can use Document.extract_pages method to achieve what you need:
doc = aw.Document("C:\\Temp\\in.docx")
# save each page as markdown
for pageIndex in range(0, doc.page_count):
doc.extract_pages(pageIndex, 1).save("C:\\Temp\\out_" + str(pageIndex) + ".md")
@alexey.noskov Thank you for the answer. I verified that the pages are successfully splitted. However, I noticed something different from the page I was checking with MS Word. Is there a way to match MS Word’s layout with the Aspose engine?
@pmrc Most likely the problem on your side occurs because fonts required for building document layout are not available in your environment. To build an accurate document layout the fonts are required. If Aspose.Words cannot find the fonts used in the document the fonts are substituted . This might lead into the document layout difference due to difference in font metrics.
Please see our documentation to learn where Aspose.Words looks for fonts: https://docs.aspose.com/words/python-net/specifying-truetype-fonts-location/