<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Pooja Patel</title>
    <description>The latest articles on DEV Community by Pooja Patel (@pooja_patel_85cac8f6751ae).</description>
    <link>https://dev.to/pooja_patel_85cac8f6751ae</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3329481%2F1b47a91e-5944-4fc0-a9e0-d33397fc0122.png</url>
      <title>DEV Community: Pooja Patel</title>
      <link>https://dev.to/pooja_patel_85cac8f6751ae</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pooja_patel_85cac8f6751ae"/>
    <language>en</language>
    <item>
      <title>How to get the length of a PDF file on AWS s3 using Python?</title>
      <dc:creator>Pooja Patel</dc:creator>
      <pubDate>Tue, 22 Jul 2025 20:36:39 +0000</pubDate>
      <link>https://dev.to/pooja_patel_85cac8f6751ae/how-to-get-the-length-of-a-pdf-file-on-s3-using-python--1job</link>
      <guid>https://dev.to/pooja_patel_85cac8f6751ae/how-to-get-the-length-of-a-pdf-file-on-s3-using-python--1job</guid>
      <description>&lt;p&gt;Ever wondered how to find the length of a pdf file on s3? You are at the right place to learn. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Prerequisite:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Access to AWS account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📖 Here are the simple steps to get the length of a pdf file on AWS s3:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Login to AWS console (Create an account if you do not have one)&lt;/li&gt;
&lt;li&gt;Look for service s3&lt;/li&gt;
&lt;li&gt;Create a bucket and upload an object&lt;/li&gt;
&lt;li&gt;Open VS code or your favorite IDE &lt;/li&gt;
&lt;li&gt;Install boto3 and pypdf with below commands:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install boto3 pypdf

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Make sure your aws credentials are configured ~/.aws/credentials, or via environment variables, or IAM roles&lt;/li&gt;
&lt;li&gt;Copy the below python code into file named main.py and run it with the code:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;main.py:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import boto3
from pypdf import PdfReader
from io import BytesIO

#  S3 Configuration 
bucket_name = 'demo-bucket-14576876757'
pdf_key = 'sample_file.pdf'

#  Create S3 client 
s3 = boto3.client('s3')

#  Download the PDF into memory 
response = s3.get_object(Bucket=bucket_name, Key=pdf_key)
pdf_content = response['Body'].read()

#  Load PDF from memory 
reader = PdfReader(BytesIO(pdf_content))

#  Get number of pages 
num_pages = len(reader.pages)
print(f"The PDF has {num_pages} pages.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🖥️ Output:&lt;br&gt;
You should see the output as below:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk4itcst2kxjk29py76e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzk4itcst2kxjk29py76e.png" alt=" " width="330" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;✅ Yes, it is that simple!&lt;/p&gt;

</description>
      <category>aws</category>
      <category>s3</category>
      <category>python</category>
      <category>pypdf</category>
    </item>
  </channel>
</rss>
