1. download all png file from Google books(discussed in my previous blog)
2. now lets discuss how to marge all png file into single pdf using python as below:
2 a)Download http://www.reportlab.com/ftp/reportlab-2.5.win32-py2.7.exe and install
in python lib.
2.b)write downl the following code for createing png to image as below:
import os
---------------------------------------------------
from reportlab.lib.pagesizes import letter
from reportlab.platypus import SimpleDocTemplate, Image
filename = './python-logo.png'
doc = SimpleDocTemplate("image.pdf", pagesize=letter)
parts = []
parts.append(Image(filename))
doc.build(parts)
---------------------------------------------------------
2.c) write following script to marge all pdf into single one:
#----join multiple pdf into single one...-----------------------
#Author : Dipankar Dutta
##Step 1: Install python and py python from http://pybrary.net/pyPdf/pyPdf-1.13.win32.exe
#Import...
from pyPdf import PdfFileWriter, PdfFileReader
## open writer.........
output = PdfFileWriter()
n= raw_input("enter the number of file to marge: ");
raw_input("Note that all file must reside in same dir: ");
name=raw_input("enter genearal file name eg. hello10.pdf ..enter hello: ");
outfilename=raw_input("enter the outputfile name: ");
for i in range(0,int(n)):
input = PdfFileReader(file(name+str(i)+'.pdf', "rb"))
for page in range(0,input.getNumPages()):
print "\tadding page %d" % page
output.addPage(input.getPage(page))
# finally, write "output" to document-output.pdf
outputStream = file(outfilename+".pdf", "wb")
output.write(outputStream)
outputStream.close()
step 3> Njoy..
No comments:
Post a Comment