Python 3 pdfrw Library Tutorial to Edit or Alter Title of PDF Document Full Project For Beginners

 

 

Welcome folks today in this blog post we will be editing the title of pdf document in python using pdfrw library. 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 pdfrw

 

 

After installing this library you need to make an app.py file and copy paste the following code

 

 

app.py

 

 

#!/usr/bin/env python

'''
usage:   alter.py my.pdf
Creates alter.my.pdf
Demonstrates making a slight alteration to a preexisting PDF file.
'''

import sys
import os

from pdfrw import PdfReader, PdfWriter

inpfn, = sys.argv[1:]
outfn = 'alter.' + os.path.basename(inpfn)

trailer = PdfReader(inpfn)
trailer.Info.Title = 'My New Title Goes Here'
PdfWriter(outfn, trailer=trailer).write()

Leave a Reply