later using for loop we created five blank a4 size pages(dimensions of a4 219×297). In the first line of our above script, we imported the PyPDF2 module and also it’s class PdfFileWriter as w. In the second step of our script, we open the file using the open() method in the “wb” format. Pdf.addBlankPage(219,297) #a4 size dimensionsĪs the output of our program, we will able to see the PDF file that we have just created.
Example program to create a pdf file using pyPdf Python module from PyPDF2 import PdfFileWriter as w Now let us create a pdf file using the PdfFileWriter class, open() method, and PyPDF2 module. In the above step, we opened a file “pavan.pdf” using open() method in “wb” format (i.e combination of write mode and binary mode). Opening the pdf file: file=open("pavan.pdf","wb") In the next step of our tutorial, we will open a new pdf file for writing contents into that file. In this tutorial, we use the PdfFileWriter class to create a pdf, So we have to import the PdfFileWriter class into our program. In the PyPDF2 module, we have many classes like PdfFileWriter and PdfFileReader, etc.
PyPDF2 is not a predefined module, so before using it we have to install it using command prompt as: # Installation of PyPDF2 module So we are going to use the PyPDF2 module to create a new pdf file. PyPDF2 is the extended version of the pyPdf module in python.
#PYTHON ROTATE PDF PAGE PYPDF HOW TO#
In this scenario, we will learn how to create a PDF file using pyPdf Python module.