Skip to content

Instantly share code, notes, and snippets.

@namishelex01
Created July 19, 2021 12:57
Show Gist options
  • Save namishelex01/a3bee0e659f5c322d778b506cb9a2235 to your computer and use it in GitHub Desktop.
Save namishelex01/a3bee0e659f5c322d778b506cb9a2235 to your computer and use it in GitHub Desktop.
Merge pdfs, create pdf from images(jpg, png, etc)
import PyPDF2
from PIL import Image
def mergePdfs():
pdfs = ['sf_1.pdf', 'sf_2.pdf']
merger = PyPDF2.PdfFileMerger()
for pdf in pdfs:
merger.append(pdf)
merger.write("SF_final_offer.pdf")
merger.close()
def make_pdf():
im3 = Image.open("Image_no_1.jpg")
im2 = Image.open("Image_no_2.jpg")
im_list = [im2, im3]
finalpdf = "final_pdf.pdf"
im3.save(finalpdf, "PDF" ,resolution=100.0, save_all=True, append_images=im_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment