Skip to content

WebNinjaDeveloper.com

Programming Tutorials




Menu
  • Home
  • Youtube Channel
  • Official Blog
  • Nearby Places Finder
  • Direction Route Finder
  • Distance & Time Calculator
Menu

Python 3 Docx2PDF Example to Convert Bulk Word (.DOCX) to PDF Documents in Command Line

Posted on January 9, 2023

 

 

Welcome folks today in this blog post we will be converting bulk word (.docx) to pdf documents in command line using docx2pdf library using python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to install the below library using the pip command as shown below

 

 

pip install docx2pdf

 

 

 

Usage

 

 

Now after installing this library you can use the docx2pdf command to convert the docx to pdf documents in the terminal as shown below

 

 

docx2pdf sample.docx sample.pdf

 

 

This above command will convert the sample.docx file to sample.pdf

 

 

Providing Custom Path

 

 

You can even provide custom path inside the command as well

 

 

docx2pdf uploads/sample.docx uploads/sample.pdf

 

 

As you can see we are converting the file stored in uploads folder

 

 

Bulk Conversion in Directory

 

 

You can even convert all the files present inside a certain directory to bulk convert as shown below

 

 

docx2pdf ##directoryname##

 

 

docx2pdf uploads

 

 

This will convert all the docx files present inside the uploads folder to pdf documents

 

 

Usage

 

 

Python
1
2
3
4
5
6
7
8
9
10
11
from docx2pdf import convert
convert("demo.docx")
# Converting docx specifying both the input
# and output paths
convert("uploads/demo.docx", "uploads/demo.pdf")
#directory storing all the files bulk convert
 
convert("uploads")

 

 

As you can see we are importing the docx2pdf module at the very top and then we are using the convert() method to carry out the conversion of docx to pdf files

 

Now if you execute the python script then you will see the conversion process at the command line

 

 

python app.py

 

 

 

Recent Posts

  • Node.js Fluent-FFMPEG Audio Pitch & Speed Changer With Live Preview in Browser Using Express
  • React.js react-awesome-modal Example to Show Popup Modal With Animation in Browser Using Javascript
  • Node.js Express Server Side Form Validation With Custom Error Messages Using express-validator Library in Javascript
  • Node.js Express Project to Validate User Form Data Using joi Schema Validation Library Full Example
  • Node.js Puppeteer Project to Export Handlebars Resume Template to PDF Document in Express Using Javascript
  • Angular
  • Bunjs
  • C#
  • Deno
  • django
  • Electronjs
  • java
  • javascript
  • Koajs
  • kotlin
  • Laravel
  • meteorjs
  • Nestjs
  • Nextjs
  • Nodejs
  • PHP
  • Python
  • React
  • ReactNative
  • Svelte
  • Tutorials
  • Vuejs




©2023 WebNinjaDeveloper.com | Design: Newspaperly WordPress Theme