<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[PDF Python Hub]]></title><description><![CDATA[We publish beginner-friendly Python and PDF tutorials, complete learning paths, and Google Colab notebooks.]]></description><link>https://pdfpythonhub.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6a717dad54c1cef832f5f5f4/97b6b086-935b-4737-9b21-422768e21467.jpg</url><title>PDF Python Hub</title><link>https://pdfpythonhub.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 18 Sep 2026 01:33:59 GMT</lastBuildDate><atom:link href="https://pdfpythonhub.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Split a PDF by Custom Page Selections in Google Colab]]></title><description><![CDATA[With Python, PyMuPDF, and Google Colab, you can easily extract specific pages from a PDF and save them as a new PDF. This is useful when you need to extract individual chapters, sections, or selected ]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-by-custom-page-selections-in-google-colab</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-by-custom-page-selections-in-google-colab</guid><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[Python]]></category><category><![CDATA[Google Colab]]></category><category><![CDATA[automation]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Thu, 17 Sep 2026 13:26:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/5086af49-73ca-452e-9c4a-d9ce47fbf639.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>With Python, PyMuPDF, and Google Colab, you can easily extract specific pages from a PDF and save them as a new PDF. This is useful when you need to extract individual chapters, sections, or selected pages.</p>
<h2>1. Install PyMuPDF</h2>
<p>Run this cell first:</p>
<pre><code class="language-python">%pip install -q -U pymupdf
</code></pre>
<h2>2. Upload your PDF</h2>
<p>Import Google Colab's file upload tool and select your PDF:</p>
<pre><code class="language-python">from google.colab import files
uploaded = files.upload()

if not uploaded:
  raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))
</code></pre>
<h2>3. Open the PDF</h2>
<p>Import PyMuPDF and open the uploaded file:</p>
<pre><code class="language-python">import pymupdf
doc = pymupdf.open(input_pdf)
</code></pre>
<blockquote>
<p><strong>Note:</strong> PyMuPDF uses zero-based page indexing.</p>
<p>Page 1 = index 0</p>
<p>Page 2 = index 1</p>
<p>Page 3 = index 2</p>
</blockquote>
<h2>4. Select the pages to extract</h2>
<p>Specify the pages you want to extract.</p>
<p>For example, this selects pages 1, 3, and 5:</p>
<pre><code class="language-python">pages = [0, 2, 4]
</code></pre>
<h2>5. Create a new PDF</h2>
<p>Create a new PDF and copy the selected pages into it:</p>
<pre><code class="language-python">output = pymupdf.open()

for page_number in pages:
  output.insert_pdf(
      doc,
      from_page=page_number,
      to_page=page_number

)

output.save("selected_pages.pdf")

output.close()

doc.close()
</code></pre>
<h2>6. Download the new PDF</h2>
<p>Once the PDF has been created, download it to your computer:</p>
<pre><code class="language-python">files.download("selected_pages.pdf")
</code></pre>
<h2>Complete Example</h2>
<pre><code class="language-python">%pip install -q -U pymupdf

from google.colab import files
uploaded = files.upload()

if not uploaded:
  raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))

import pymupdf
doc = pymupdf.open(input_pdf)

pages = [0, 2, 4]

output = pymupdf.open()

for page_number in pages:
  output.insert_pdf(
      doc,
      from_page=page_number,
      to_page=page_number

)

output.save("selected_pages.pdf")

output.close()

doc.close()

files.download("selected_pages.pdf")
</code></pre>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1BDarKRMjsGxSd3qu5RKZeG70nSi6gFIE?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<p><em>This mini-guide was originally published on</em> <a href="https://payhip.com/PDFPythonHub"><em><strong>PDF Python Hub</strong></em></a><em>, where you can find more in-depth Python resources for working with PDFs.</em></p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to Split a PDF into Separate PDF Pages in Google Colab?</p>
<p>Check out this mini-guide: <a href="https://payhip.com/PDFPythonHub/blog/news/how-to-split-a-pdf-into-separate-pdf-pages-in-google-colab">How to Split a PDF into Separate PDF Pages in Google Colab.</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Split a PDF into Page Ranges in Google Colab]]></title><description><![CDATA[If you have a multi-page PDF and want to turn specific page ranges into separate PDF files, you can do this easily with PyMuPDF in Google Colab.
For example, you can split a PDF like this:

Pages 1–3 ]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-into-page-ranges-in-google-colab</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-into-page-ranges-in-google-colab</guid><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[Python]]></category><category><![CDATA[automation]]></category><category><![CDATA[Google Colab]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 09 Sep 2026 18:30:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/ec8f540e-a97b-403f-a0ff-80b4baf630c9.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you have a multi-page PDF and want to turn specific page ranges into separate PDF files, you can do this easily with PyMuPDF in Google Colab.</p>
<p>For example, you can split a PDF like this:</p>
<ul>
<li><p>Pages 1–3 → pages_1-3.pdf</p>
</li>
<li><p>Pages 4–6 → pages_4-6.pdf</p>
</li>
<li><p>Pages 7–10 → pages_7-10.pdf</p>
</li>
</ul>
<h2>1. Install PyMuPDF</h2>
<p>First, install the PyMuPDF library:</p>
<pre><code class="language-python">%pip install -q -U pymupdf
</code></pre>
<h2>2. Import Libraries</h2>
<p>Then import the libraries you’ll need:</p>
<pre><code class="language-python">import pymupdf
from google.colab import files
from pathlib import Path
import shutil
</code></pre>
<h2>3. Upload Your PDF</h2>
<p>The following code opens a file picker so you can upload your PDF:</p>
<pre><code class="language-python">uploaded = files.upload()

if not uploaded:
  raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))
</code></pre>
<p>The uploaded file is stored in the variable <code>input_pdf</code>.</p>
<h2>4. Create an Output Folder</h2>
<p>Next, create an output folder called <code>split_ranges</code> where the individual PDF files will be saved:</p>
<pre><code class="language-python">output_dir = Path("split_ranges")
output_dir.mkdir(exist_ok=True)
</code></pre>
<p>We set <code>exist_ok=True</code> so that Python won't return an error if the folder already exists.</p>
<h2>5. Open the PDF</h2>
<p>Next, open the uploaded PDF with PyMuPDF:</p>
<pre><code class="language-python">doc = pymupdf.open(input_pdf)
</code></pre>
<p>The variable <code>doc</code> now represents the entire PDF document.</p>
<h2>6. Define the Page Ranges</h2>
<p>Now define the page ranges you want to split from the PDF.</p>
<p>For example, if you want to create PDFs containing pages 1–3, 4–6, and 7–10:</p>
<pre><code class="language-python">ranges = [
    (1, 3),
    (4, 6),
    (7, 10)
]
</code></pre>
<p>The numbers represent the PDF page numbers, starting at 1.</p>
<h2>7. Split the PDF into Page Ranges</h2>
<p>The following loop goes through every page range. For each range, it creates a new PDF, copies the selected pages into it, saves it, and then closes the new PDF:</p>
<pre><code class="language-python">for start, end in ranges:

    new_pdf = pymupdf.open()

    new_pdf.insert_pdf(
        doc,
        from_page=start - 1,
        to_page=end - 1
    )

    output_path = output_dir / f"pages_{start}-{end}.pdf"

    new_pdf.save(output_path)
    new_pdf.close()
</code></pre>
<p>Here's what happens:</p>
<ul>
<li><p><code>start</code> is the first page of the range.</p>
</li>
<li><p><code>end</code> is the last page of the range.</p>
</li>
<li><p><code>start - 1</code> converts the page number into a zero-based page index.</p>
</li>
<li><p><code>end - 1</code> converts the last page number into a zero-based page index.</p>
</li>
<li><p>A new empty PDF is created for each range.</p>
</li>
<li><p><code>insert_pdf()</code> copies the selected pages into the new PDF.</p>
</li>
<li><p><code>save()</code> creates a file such as pages_1-3.pdf.</p>
</li>
<li><p><code>close()</code> closes the newly created PDF after it has been saved.</p>
</li>
</ul>
<p>For example, a <strong>10-page PDF</strong> with the ranges above will produce:</p>
<p>split_ranges/</p>
<p>├── pages_1-3.pdf</p>
<p>├── pages_4-6.pdf</p>
<p>└── pages_7-10.pdf</p>
<p>The first PDF contains pages 1, 2, and 3.</p>
<p>The second PDF contains pages 4, 5, and 6.</p>
<p>The third PDF contains pages 7, 8, 9, and 10.</p>
<h2>8. Close the Original PDF</h2>
<p>Once all the page ranges have been processed, close the original PDF:</p>
<pre><code class="language-python">doc.close()
</code></pre>
<h2>9. Create a ZIP File</h2>
<p>Instead of downloading every PDF individually, you can put all the individual PDFs into a ZIP file:</p>
<pre><code class="language-python">zip_path = shutil.make_archive(
    "split_ranges",
    "zip",
    output_dir)

files.download(zip_path)
</code></pre>
<p>This creates:</p>
<p><strong>split_ranges.zip</strong></p>
<p>and automatically starts the download in Google Colab.</p>
<h2>Complete Example</h2>
<pre><code class="language-python">%pip install -q -U pymupdf

import pymupdf
from google.colab import files
from pathlib import Path
import shutil

uploaded = files.upload()

if not uploaded:
  raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))

output_dir = Path("split_ranges")
output_dir.mkdir(exist_ok=True)

doc = pymupdf.open(input_pdf)

ranges = [
    (1, 3),
    (4, 6),
    (7, 10)
]

for start, end in ranges:

    new_pdf = pymupdf.open()

    new_pdf.insert_pdf(
        doc,
        from_page=start - 1,
        to_page=end - 1
    )

    output_path = output_dir / f"pages_{start}-{end}.pdf"

    new_pdf.save(output_path)
    new_pdf.close()

doc.close()

zip_path = shutil.make_archive(
    "split_ranges",
    "zip",
    output_dir)

files.download(zip_path)
</code></pre>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/18O9KIIFxT7sX6_ikwB8e35iYYg2Ms-kL?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to Split a PDF into Separate PDF Pages in Google Colab?</p>
<p>Check out this mini-guide: <a href="https://payhip.com/PDFPythonHub/blog/news/how-to-split-a-pdf-into-separate-pdf-pages-in-google-colab">How to Split a PDF into Separate PDF Pages in Google Colab.</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Split a PDF into Separate PDF Pages in Google Colab]]></title><description><![CDATA[If you have a multi-page PDF and want to turn each page into a separate PDF file, you can do this easily with PyMuPDF in Google Colab.
Install PyMuPDF
First, install the PyMuPDF library:
%pip install ]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-into-separate-pdf-pages-in-google-colab</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-split-a-pdf-into-separate-pdf-pages-in-google-colab</guid><category><![CDATA[Python]]></category><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[Google Colab]]></category><category><![CDATA[automation]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Sat, 05 Sep 2026 20:01:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/aacc5150-73e9-4147-b174-22a186770459.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you have a multi-page PDF and want to turn each page into a separate PDF file, you can do this easily with PyMuPDF in Google Colab.</p>
<h2>Install PyMuPDF</h2>
<p>First, install the PyMuPDF library:</p>
<pre><code class="language-python">%pip install -q -U pymupdf
</code></pre>
<h2>Import Libraries</h2>
<p>Then import the libraries you’ll need:</p>
<pre><code class="language-python">import pymupdf
from google.colab import files
from pathlib import Path
import shutil
</code></pre>
<h2>Upload Your PDF</h2>
<p>The following code opens a file picker so you can upload your PDF:</p>
<pre><code class="language-python">uploaded = files.upload()

if not uploaded:
  raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))
</code></pre>
<p>The uploaded file is stored in the variable <code>input_pdf</code>.</p>
<h2>Create an Output Folder</h2>
<p>Next, create an output folder called <code>split_pages</code> where the individual PDF pages will be saved:</p>
<pre><code class="language-python">output_dir = Path("split_pages")
output_dir.mkdir(exist_ok=True)
</code></pre>
<p>We set <code>exist_ok=True</code> so that Python won't return an error if the folder already exists.</p>
<h2>Open the PDF</h2>
<p>Next, open the uploaded PDF with PyMuPDF:</p>
<pre><code class="language-python">doc = pymupdf.open(input_pdf)
</code></pre>
<p>The variable <code>doc</code> now represents the entire PDF document.</p>
<h2>Split the PDF into Individual Pages</h2>
<p>The following loop goes through every page in the PDF. For each page, it creates a new PDF, copies the current page into it, saves it, and then closes the new PDF:</p>
<pre><code class="language-python">for i in range(len(doc)):
  new_pdf = pymupdf.open()
  new_pdf.insert_pdf(doc, from_page=i, to_page=i)
  new_pdf.save(output_dir / f"page_{i + 1}.pdf")
  new_pdf.close()
</code></pre>
<p>Here's what happens:</p>
<ul>
<li><p><code>range(len(doc))</code> generates the page indexes for every page in the PDF.</p>
</li>
<li><p><code>i</code> is the page index, starting at 0.</p>
</li>
<li><p>A new empty PDF is created for each page.</p>
</li>
<li><p><code>insert_pdf()</code> copies the current page into the new PDF.</p>
</li>
<li><p><code>save()</code> creates a file such as <em>page_1.pdf</em>, <em>page_2.pdf</em>, and so on.</p>
</li>
<li><p><code>close()</code> closes the newly created PDF after it has been saved.</p>
</li>
</ul>
<p>For example, a <strong>5-page PDF</strong> will produce:</p>
<p>split_pages/</p>
<p>├── page_1.pdf</p>
<p>├── page_2.pdf</p>
<p>├── page_3.pdf</p>
<p>├── page_4.pdf</p>
<p>└── page_5.pdf</p>
<h2>Close the Original PDF</h2>
<p>Once all the pages have been processed, close the original PDF:</p>
<pre><code class="language-python">doc.close()
</code></pre>
<h2>Create a ZIP File</h2>
<p>Instead of downloading every PDF individually, you can put all the individual PDFs into a ZIP file:</p>
<pre><code class="language-python">shutil.make_archive("split_pages", "zip", "split_pages")
files.download("split_pages.zip")
</code></pre>
<p>This creates:</p>
<p><strong>split_pages.zip</strong></p>
<p>and automatically starts the download in Google Colab.</p>
<h2>Complete Example</h2>
<pre><code class="language-python">%pip install -q pymupdf

import pymupdf
from google.colab import files
from pathlib import Path
import shutil

uploaded = files.upload()

if not uploaded:
    raise ValueError("No PDF was uploaded.")

input_pdf = next(iter(uploaded))

output_dir = Path("split_pages")
output_dir.mkdir(exist_ok=True)

doc = pymupdf.open(input_pdf)

for i in range(len(doc)):
    new_pdf = pymupdf.open()
    new_pdf.insert_pdf(doc, from_page=i, to_page=i)
    new_pdf.save(output_dir / f"page_{i + 1}.pdf")
    new_pdf.close()

doc.close()

shutil.make_archive("split_pages", "zip", "split_pages")

files.download("split_pages.zip")
</code></pre>
<h2>Why Split a PDF into Separate PDFs?</h2>
<p>Splitting a PDF into individual pages is useful when you need to:</p>
<ul>
<li><p><strong>Extract specific pages</strong> from a larger document.</p>
</li>
<li><p><strong>Process pages separately</strong>.</p>
</li>
<li><p><strong>Upload individual pages</strong> as separate documents.</p>
</li>
<li><p><strong>Share only certain pages</strong> with someone.</p>
</li>
<li><p><strong>Organize a large PDF</strong> into smaller files.</p>
</li>
</ul>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1g-WOwCSWdqwdr1jnYJLhX7yj99xZYsxm?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<p><em>This mini-guide was originally published on</em> <a href="https://payhip.com/PDFPythonHub"><em>PDF Python Hub</em></a><em>, where you can find more in-depth Python resources for working with PDFs.</em></p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to count the number of pages in a PDF?</p>
<p>Check out this mini-guide: <a href="https://payhip.com/PDFPythonHub/blog/news/how-to-count-the-number-of-pages-in-a-pdf-using-pymupdf">How to Count the Number of Pages in a PDF Using PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[Export PDF Metadata to JSON Using Python]]></title><description><![CDATA[The Python script below uses PyMuPDF to read basic information from a PDF, saves that information as a JSON file, and downloads the file to your computer.
Install pymupdf
If pymupdf isn't already inst]]></description><link>https://pdfpythonhub.hashnode.dev/export-pdf-metadata-to-json-using-python</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/export-pdf-metadata-to-json-using-python</guid><category><![CDATA[Python]]></category><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[json]]></category><category><![CDATA[python beginner]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 11:37:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/f85af664-a47d-4c20-a634-896af31127cd.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The Python script below uses PyMuPDF to read basic information from a PDF, saves that information as a JSON file, and downloads the file to your computer.</p>
<h2>Install <code>pymupdf</code></h2>
<p>If <code>pymupdf</code> isn't already installed in your Colab environment, run:</p>
<pre><code class="language-python">%pip install -q -U pymupdf
</code></pre>
<h2>Import the dependencies</h2>
<pre><code class="language-python">import pymupdf
import json
from google.colab import files
</code></pre>
<h2>Upload the PDF</h2>
<pre><code class="language-python">uploaded = files.upload()
</code></pre>
<h2>Open the PDF</h2>
<pre><code class="language-python">doc = pymupdf.open("sample.pdf")
</code></pre>
<p>This opens the PDF so Python can access its information.</p>
<p><em>Replace</em> <code>"sample.pdf"</code> <em>with the name of your PDF.</em></p>
<h2>Collect the information</h2>
<p>The script creates a dictionary containing:</p>
<ul>
<li><p><code>page_number</code> — the total number of pages</p>
</li>
<li><p><code>metadata</code> — information such as the PDF title, author, subject, creator, and creation date</p>
</li>
</ul>
<pre><code class="language-python">data = {
    "page_number": doc.page_count,
    "metadata": doc.metadata
}
</code></pre>
<h2>Save the information as JSON</h2>
<pre><code class="language-python">with open("pdf_information.json", "w", encoding="utf-8") as f:
    json.dump(data, f, indent=4, ensure_ascii=False)
</code></pre>
<ul>
<li><p><code>"w"</code> — opens the file in write mode, meaning new content is written to the file.</p>
</li>
<li><p><code>encoding="utf-8"</code> — specifies UTF-8 character encoding, allowing the file to correctly handle characters from different languages and special characters.</p>
</li>
<li><p><code>as f</code> — gives the opened file a short name (f).</p>
</li>
<li><p><code>json.dump()</code> —writes Python data to JSON.</p>
</li>
<li><p><code>indent=4</code> — formats the JSON with 4 spaces of indentation, making it easier for humans to read.</p>
</li>
<li><p><code>ensure_ascii=False</code> — keeps non-ASCII characters as they are instead of converting them into Unicode escape sequences. For example, é stays as é rather than becoming \u00e9.</p>
</li>
<li><p><code>with</code> — automatically closes the JSON file when the block finishes, even if something goes wrong while writing.</p>
</li>
</ul>
<h2>Download the JSON file</h2>
<p>Because this is running in Google Colab, you can download the generated file directly:</p>
<pre><code class="language-python">files.download("pdf_information.json")
</code></pre>
<h2>Complete Example</h2>
<pre><code class="language-python">%pip install -q -U pymupdf

import pymupdf
import json
from google.colab import files

uploaded = files.upload()

doc = pymupdf.open("sample.pdf")

data = {
    "page_number": doc.page_count,
    "metadata": doc.metadata
}

with open("pdf_information.json", "w", encoding="utf-8") as f:
    json.dump(data, f, indent=4, ensure_ascii=False)

files.download("pdf_information.json")
</code></pre>
<h2>Example Output</h2>
<p>The resulting JSON might look like:</p>
<p>{<br />    "page_number": 4,<br />    "metadata": {<br />        "format": "PDF 1.5",<br />        "title": "Artificial Intelligence (AI) ",<br />        "author": "PDF Python Hub",<br />        "subject": "An Overview of Artificial Intelligence, Machine Learning, Generative AI, Ethical Frameworks, and Future Outlook",<br />        "keywords": "Artificial Intelligence, AI, Machine Learning, Deep Learning, Generative AI, Large Language Models, AI Ethics",<br />        "creator": "Google Docs",<br />        "producer": "Skia/PDF m153 Google Docs Renderer",<br />        "creationDate": "D:20260816101230+02'00'",<br />        "modDate": "D:20260818145823+02'00'",<br />        "trapped": "",<br />        "encryption": null<br />    }<br />}</p>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/19Kv37fgtdvSBh5G3x7e9l0_dBT1rJlvV?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to open a PDF file?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/open-your-first-pdf-with-pymupdf">Open Your First PDF with PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Properly Close a PDF with PyMuPDF]]></title><description><![CDATA[doc.close() closes a PDF document that you previously opened with PyMuPDF.
What does doc.close() do?
doc.close():

Releases resources and memory associated with the document.

Closes the document and ]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-properly-close-a-pdf-with-pymupdf</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-properly-close-a-pdf-with-pymupdf</guid><category><![CDATA[Python]]></category><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[python beginner]]></category><category><![CDATA[Python File Handling]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 11:04:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/aabb1a65-9ac6-4ea3-b5a2-16496b854fc5.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><code>doc.close()</code> closes a PDF document that you previously opened with PyMuPDF.</p>
<h2>What does <code>doc.close()</code> do?</h2>
<p><code>doc.close()</code>:</p>
<ul>
<li><p>Releases resources and memory associated with the document.</p>
</li>
<li><p>Closes the document and its underlying resources.</p>
</li>
<li><p>Makes the Document object unavailable for further document operations.</p>
</li>
</ul>
<h2>When should you use it?</h2>
<ul>
<li><p>Use <code>doc.close()</code> when you are finished working with a PDF, especially when:</p>
</li>
<li><p>You created or modified a PDF.</p>
</li>
<li><p>You are processing many PDFs in a loop.</p>
</li>
<li><p>You want to make sure the document is no longer being held open.</p>
</li>
</ul>
<p><strong>Important:</strong> After calling <code>doc.close()</code>, you can no longer work with the document. Attempting to perform operations on a closed document can raise: <code>ValueError: document closed</code></p>
<p>If you need to work with the PDF again, you can open it with <code>pymupdf.open()</code>:</p>
<pre><code class="language-python">doc = pymupdf.open("sample.pdf")
</code></pre>
<p>This creates a new Document object that you can work with normally.</p>
<h2>Should you save the PDF document before closing it?</h2>
<p>If you've modified the PDF, make sure you save your changes to a new file before closing the document.</p>
<p>For example:</p>
<pre><code class="language-python">doc.save("modified.pdf")
</code></pre>
<p>If you close a modified document without saving it, your changes may be lost.</p>
<p><code>doc.close()</code> <em>does not save your changes.</em></p>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1j8jc-bC_2Fcs4IVPnzfPDA3ZiFHjqirj?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to open a PDF file?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/open-your-first-pdf-with-pymupdf">Open Your First PDF with PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[Extract PDF Metadata with PyMuPDF in Python]]></title><description><![CDATA[If you’re working with a PyMuPDF's Document object called doc, you can access its metadata with:
metadata = doc.metadata
PyMuPDF is a Python library for working with PDF files.
What does doc.metadata ]]></description><link>https://pdfpythonhub.hashnode.dev/extract-pdf-metadata-with-pymupdf-in-python</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/extract-pdf-metadata-with-pymupdf-in-python</guid><category><![CDATA[Python]]></category><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[beginner python]]></category><category><![CDATA[pdf metadata]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 10:45:52 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/91841363-5164-497b-af43-7e71ba6c85c2.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you’re working with a PyMuPDF's Document object called <code>doc</code>, you can access its metadata with:</p>
<p><code>metadata = doc.metadata</code></p>
<p>PyMuPDF is a Python library for working with PDF files.</p>
<h2>What does doc.metadata mean?</h2>
<p><code>doc.metadata</code> contains additional information about the PDF document, rather than the PDF document’s main text.</p>
<p>It might contain information such as:</p>
<ul>
<li><p>format</p>
</li>
<li><p>title</p>
</li>
<li><p>author</p>
</li>
<li><p>creator</p>
</li>
</ul>
<h2>Store the metadata</h2>
<pre><code class="language-python">metadata = doc.metadata
</code></pre>
<p>This takes the metadata associated with <code>doc</code> and stores it in a variable called <code>metadata</code>.</p>
<h2>Print the metadata</h2>
<pre><code class="language-python">print(metadata)
</code></pre>
<p>This displays the metadata:</p>
<p>{'format': 'PDF 1.5', 'title': 'Artificial Intelligence (AI) ', 'author': 'PDF Python Hub', 'subject': 'An Overview of Artificial Intelligence, Machine Learning, Generative AI, Ethical Frameworks, and Future Outlook', 'keywords': 'Artificial Intelligence, AI, Machine Learning, Deep Learning, Generative AI, Large Language Models, AI Ethics', 'creator': 'Google Docs', 'producer': 'Skia/PDF m153 Google Docs Renderer', 'creationDate': "D:20260816101230+02'00'", 'modDate': "D:20260818145823+02'00'", 'trapped': '', 'encryption': None}</p>
<p>You can then access individual pieces of information:</p>
<pre><code class="language-python">print(metadata["author"])

print(metadata["creationDate"])
</code></pre>
<h2>Complete Example</h2>
<pre><code class="language-python">metadata = doc.metadata

print(metadata)
</code></pre>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1o4RDtnFuxvFDG8P_3u2YlRXHu3D1_i19?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to open a PDF file?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/open-your-first-pdf-with-pymupdf">Open Your First PDF with PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[Count PDF Pages with Python and PyMuPDF]]></title><description><![CDATA[Once you have opened a PDF with PyMuPDF, you can easily find out how many pages it contains.
Using page_count
page_number = doc.page_count
print(page_number)

The page_count property returns the total]]></description><link>https://pdfpythonhub.hashnode.dev/count-pdf-pages-with-python-and-pymupdf</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/count-pdf-pages-with-python-and-pymupdf</guid><category><![CDATA[Python]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[pdf]]></category><category><![CDATA[beginner python]]></category><category><![CDATA[python pdf]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 10:13:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/5fbeaaa1-f816-467f-94a3-52fce672a510.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Once you have opened a PDF with PyMuPDF, you can easily find out how many pages it contains.</p>
<h2>Using page_count</h2>
<pre><code class="language-python">page_number = doc.page_count
print(page_number)
</code></pre>
<p>The <code>page_count</code> property returns the total number of pages in the PDF.</p>
<p>Here, the number of pages is stored in the variable <code>page_number</code>, and <code>print()</code> displays it.</p>
<p>For example, if the PDF contains 44 pages, the output will be:</p>
<p><code>44</code></p>
<h2>Using len()</h2>
<p>You can also use Python's built-in <code>len()</code> function:</p>
<p><code>len(doc)</code></p>
<p>This returns the total number of pages in the PDF as well.</p>
<p>For example:</p>
<pre><code class="language-notebook-python">print(len(doc))
</code></pre>
<p>Example Output:</p>
<p><code>44</code></p>
<blockquote>
<p>Key takeaway</p>
<p>Both approaches give you the number of pages:</p>
<p><code>doc.page_count</code></p>
<p>or</p>
<p><code>len(doc)</code></p>
</blockquote>
<h2>Complete Example</h2>
<pre><code class="language-python"># Method 1

page_number = doc.page_count
print(page_number)

# Method 2

print(len(doc))
</code></pre>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1PCDK-mZzL6slYLc3YEEr1h2ZFE3m_dgC?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to open a PDF file?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/open-your-first-pdf-with-pymupdf">Open Your First PDF with PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Upload Files in Google Colab]]></title><description><![CDATA[The following code lets you upload one or more files from your computer directly into a Google Colab notebook:
from google.colab import files
uploaded = files.upload()

How it works
1. Import the file]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-upload-files-in-google-colab</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-upload-files-in-google-colab</guid><category><![CDATA[Python]]></category><category><![CDATA[Google Colab]]></category><category><![CDATA[File Upload]]></category><category><![CDATA[python beginner]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 09:37:59 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/e7ef7ae6-ed74-48f1-93c2-570da1c76acf.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The following code lets you upload one or more files from your computer directly into a Google Colab notebook:</p>
<pre><code class="language-python">from google.colab import files
uploaded = files.upload()
</code></pre>
<h2>How it works</h2>
<h3>1. Import the file-upload tool</h3>
<pre><code class="language-python">from google.colab import files
</code></pre>
<p>This imports Colab’s <code>files</code> module, which provides functions for uploading and downloading files in Google Colab.</p>
<h3>2. Open the upload window</h3>
<pre><code class="language-python">uploaded = files.upload()
</code></pre>
<p>When this line runs, Colab displays a <strong>Choose Files</strong> button. You can select one or more files from your computer.</p>
<p>The uploaded file(s) are stored in the <code>uploaded</code> variable as a dictionary.</p>
<p><em>For example, if you select a PDF, Colab uploads it to the notebook environment and stores its information in the</em> <code>uploaded</code> <em>variable.</em></p>
<h3>3. Check the filename(s)</h3>
<pre><code class="language-python">uploaded.keys()
</code></pre>
<h2>Complete Example</h2>
<pre><code class="language-python">from google.colab import files
uploaded = files.upload()
uploaded.keys()
</code></pre>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1xf9r2mr0F3qWHJtl5jZXjBjWIKQK1HFh?usp=sharing"><strong>Open in Google Colab</strong></a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to open a PDF file?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/open-your-first-pdf-with-pymupdf">Open Your First PDF with PyMuPDF</a></p>
]]></content:encoded></item><item><title><![CDATA[How to Install PyMuPDF in Google Colab With Pip]]></title><description><![CDATA[1. Install PyMuPDF
%pip install -q -U pymupdf


%pip runs pip directly from a Jupyter Notebook or Google Colab cell.

install tells pip to install a package.

-U (or --upgrade) updates PyMuPDF if an o]]></description><link>https://pdfpythonhub.hashnode.dev/how-to-install-pymupdf-in-google-colab-with-pip</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/how-to-install-pymupdf-in-google-colab-with-pip</guid><category><![CDATA[Python]]></category><category><![CDATA[Google Colab]]></category><category><![CDATA[pdf]]></category><category><![CDATA[PyMuPDF]]></category><category><![CDATA[python beginner]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Wed, 19 Aug 2026 08:26:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/b7c09b29-0e90-4f55-b453-9d4d15bd811a.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>1. Install PyMuPDF</h2>
<pre><code class="language-python">%pip install -q -U pymupdf
</code></pre>
<ul>
<li><p><code>%pip</code> runs <code>pip</code> directly from a Jupyter Notebook or Google Colab cell.</p>
</li>
<li><p><code>install</code> tells <strong>pip</strong> to install a package.</p>
</li>
<li><p><code>-U</code> (or <code>--upgrade</code>) updates PyMuPDF if an older version is already installed.</p>
</li>
<li><p><code>-q</code> (or <code>--quiet</code>) reduces the amount of installation output.</p>
</li>
<li><p><code>pymupdf</code> is the package name.</p>
</li>
</ul>
<h2>2. Import PyMuPDF</h2>
<pre><code class="language-python">import pymupdf
</code></pre>
<p>This makes the PyMuPDF library available in your Python code.</p>
<h2>3. Check the Installed Version</h2>
<pre><code class="language-python">print(pymupdf.__version__)
</code></pre>
<p>This prints the version of PyMuPDF currently installed.</p>
<p>You should see output similar to:</p>
<p><strong>1.x.x</strong></p>
<h2>Complete Example</h2>
<pre><code class="language-python">%pip install -q -U pymupdf

import pymupdf

print(pymupdf.__version__)
</code></pre>
<p><em>The exact version will depend on the latest version available when you run the installation.</em></p>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1i1YBr1Xg6ZfEyeb9NNYgY-ViKSrVu-df?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to upload files in Google Colab?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/uploading-files-in-google-colab">Uploading Files in Google Colab</a></p>
]]></content:encoded></item><item><title><![CDATA[A Beginner’s Guide to Opening PDFs with PyMuPDF]]></title><description><![CDATA[The code below opens an existing PDF so you can read, extract, or modify its contents.
Import PyMuPDF
import pymupdf

This imports the PyMuPDF library and makes its PDF tools available in your Python ]]></description><link>https://pdfpythonhub.hashnode.dev/a-beginners-guide-to-opening-pdfs-with-pymupdf</link><guid isPermaLink="true">https://pdfpythonhub.hashnode.dev/a-beginners-guide-to-opening-pdfs-with-pymupdf</guid><category><![CDATA[Python]]></category><category><![CDATA[pdf]]></category><category><![CDATA[python libraries]]></category><category><![CDATA[pdf processing]]></category><category><![CDATA[PyMuPDF]]></category><dc:creator><![CDATA[PDF Python Hub]]></dc:creator><pubDate>Thu, 06 Aug 2026 08:21:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a717dad54c1cef832f5f5f4/4227c522-fc9e-4ed6-8ba1-95ffb777b91c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The code below opens an existing PDF so you can read, extract, or modify its contents.</p>
<h2>Import PyMuPDF</h2>
<pre><code class="language-python">import pymupdf
</code></pre>
<p>This imports the PyMuPDF library and makes its PDF tools available in your Python program.</p>
<h2>Open the PDF</h2>
<p><code>pymupdf.open()</code> opens the PDF file named <code>sample.pdf</code>. The returned document is stored in the variable <code>doc</code>, which you can then use to access the PDF's pages and content.</p>
<pre><code class="language-python">doc = pymupdf.open("sample.pdf")
</code></pre>
<h2>Complete Example</h2>
<pre><code class="language-python">import pymupdf

doc = pymupdf.open("sample.pdf")
</code></pre>
<p>In short: <code>import pymupdf</code> loads the library, while<code>pymupdf.open("sample.pdf")</code> opens the PDF and stores it in <code>doc</code> for further processing.</p>
<hr />
<h2>Open the notebook</h2>
<p>Open the Google Colab notebook for this PDF mini-guide and run the code as you follow along.</p>
<p>[<a href="https://colab.research.google.com/drive/1zlZaeJzMq7iXaaRAXeiQ4KhwTniGyEX4?usp=sharing">Open in Google Colab</a>]</p>
<hr />
<h2>More PDF Python Resources</h2>
<p>Want to learn how to install the <code>pymupdf</code> package?</p>
<p>Check out this mini-guide:</p>
<p><a href="https://payhip.com/PDFPythonHub/blog/news/how-to-install-pymupdf-in-google-colab">How to Install PyMuPDF in Google Colab</a></p>
]]></content:encoded></item></channel></rss>