Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save documentprocessing/5dc51f747fda04dca2f65e56501f0303 to your computer and use it in GitHub Desktop.
Save documentprocessing/5dc51f747fda04dca2f65e56501f0303 to your computer and use it in GitHub Desktop.
Convert specific PDF pages to DOCX using pdf2docx API in Python
from pdf2docx import Converter
# PDF file to be converted
pdf_file = 'example.pdf'
# Output DOCX file
docx_file = 'output.docx'
# Create a PDF to DOCX converter object
cv = Converter(pdf_file)
# Convert pages 5 to 10 (note that page indices start from 0, so adjust accordingly)
cv.convert(docx_file, start=4, end=10) # This will convert pages 5 to 9
# Close the converter when done
cv.close()
print("Conversion of specific pages completed! The DOCX file has been created.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment