Download only the first page of a pdf programmatically (possibly in python)

Viewed 148

To download a pdf given its url programmatically, it is possible to use a function like the one below:

import urllib
import shulil


def download_pdf(pdf_url, destination_path, timeout_secs=5)
    try:
        req = urllib.request.urlopen(pdf_url, None, timeout_secs)
        with open(destination_path, "wb") as f:
            shutil.copyfileobj(req, f)
    except Exception as e:
        raise Exception(f"Exception {e} raised downloading {pdf_url}")

As I am interested only in the first page, and I want to speed up the donwload process, is there a way (with shutil or in any other way) to download only the first page of a pdf, given its url?

Please note: the aim is to speed up the download, getting only the first page, not to get the whole pdf and then extract the first page.


Edit: An alternative idea can be to download the PDF without the images. This would also speed up the process. Is that possible?

0 Answers
Related