Created
December 28, 2019 16:12
-
-
Save giasuddin90/b31d2bef186dfefacadeb0602170fe44 to your computer and use it in GitHub Desktop.
pdf existing file delete and add new pdf file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyPDF2 import PdfFileWriter, PdfFileReader | |
import requests | |
from io import BytesIO | |
import os | |
from io import StringIO | |
from WordpresFileUpload.wordpressFile import wordpress_file_up | |
def download_pdf(page_url, page_range): | |
""" | |
if we provide pdf url and page range to keep | |
it will provide our desired pdf | |
""" | |
response = requests.get(page_url) | |
pdf_file = BytesIO(response.content) | |
existing_pdf = PdfFileReader(pdf_file) | |
filename = str(os.path.basename(page_url)) | |
promo_pdf = PdfFileReader('baddalljob_promo_docs.pdf', 'rb') | |
output = PdfFileWriter() | |
for i in range(page_range): | |
p = existing_pdf.getPage(i) | |
output.addPage(p) | |
output.appendPagesFromReader(promo_pdf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment