Merge PDF stored in Remote server using Python Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 2 Likes Like Report Prerequisites: Working with PDF files in Python There are many libraries for manipulating PDF files in Python but all are using when that all PDF files already downloaded in your local machine. But what if your target PDF files are in Remote server, you have only URLs of files and no required download in your machine or compute server. Here We will discuss this problem and solution for the same. Installation: Here we use the library of Python PyPDF2 for merging PDFs. pip install PyPDF2 We will merge the same pdf file twice. Link to the pdf file used is here Below is the implementation. Python3 1== from io import BytesIO, SEEK_SET, SEEK_END import PyPDF2 import requests # Create a class which convert PDF in # BytesIO form class ResponseStream(object): def __init__(self, request_iterator): self._bytes = BytesIO() self._iterator = request_iterator def _load_all(self): self._bytes.seek(0, SEEK_END) for chunk in self._iterator: self._bytes.write(chunk) def _load_until(self, goal_position): current_position = self._bytes.seek(0, SEEK_END) while current_position < goal_position: try: current_position = self._bytes.write(next(self._iterator)) except StopIteration: break def tell(self): return self._bytes.tell() def read(self, size = None): left_off_at = self._bytes.tell() if size is None: self._load_all() else: goal_position = left_off_at + size self._load_until(goal_position) self._bytes.seek(left_off_at) return self._bytes.read(size) def seek(self, position, whence = SEEK_SET): if whence == SEEK_END: self._load_all() else: self._bytes.seek(position, whence) # Merge PDFs using URL List url_list = ["lis of URL"] target_pdf_path = './Merged.pdf' pdf_writer = PyPDF2.PdfFileWriter() for url in url_list: response = requests.get(url) reader = PyPDF2.PdfFileReader(ResponseStream(response.iter_content(64))) for page in range(reader.getNumPages()): pdf_writer.addPage(reader.getPage(page)) # write to output file with open(target_pdf_path, 'wb') as g: pdf_writer.write(g) Output: The merged pdf file created is here Create Quiz Comment P parth_ghinaiya Follow 2 Improve P parth_ghinaiya Follow 2 Improve Article Tags : Python python-utility Python-projects Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like