Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit07d02c3

Browse files
committed
add pdf metadata remover tutorial
1 parentd97902b commit07d02c3

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
6262
-[How to Implement 2FA in Python](https://thepythoncode.com/article/implement-2fa-in-python). ([code](ethical-hacking/implement-2fa))
6363
-[How to Build a Username Search Tool in Python](https://thepythoncode.com/code/social-media-username-finder-in-python). ([code](ethical-hacking/username-finder))
6464
-[How to Find Past Wi-Fi Connections on Windows in Python](https://thepythoncode.com/article/find-past-wifi-connections-on-windows-in-python). ([code](ethical-hacking/find-past-wifi-connections-on-windows))
65+
-[How to Remove Metadata from PDFs in Python](https://thepythoncode.com/article/how-to-remove-metadata-from-pdfs-in-python). ([code](ethical-hacking/pdf-metadata-remover))
6566

6667
-###[Machine Learning](https://www.thepythoncode.com/topic/machine-learning)
6768
-###[Natural Language Processing](https://www.thepythoncode.com/topic/nlp)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#[How to Remove Metadata from PDFs in Python](https://thepythoncode.com/article/how-to-remove-metadata-from-pdfs-in-python)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
importPyPDF2
2+
3+
defremove_metadata(pdf_file):
4+
# Open the PDF file.
5+
withopen(pdf_file,'rb')asfile:
6+
reader=PyPDF2.PdfReader(file)
7+
8+
# Check if metadata exists.
9+
ifreader.metadataisnotNone:
10+
print("Metadata found in the PDF file.")
11+
12+
# Create a new PDF file without metadata.
13+
writer=PyPDF2.PdfWriter()
14+
15+
# Copy pages from the original PDF to the new PDF.
16+
forpage_numinrange(len(reader.pages)):
17+
page=reader.pages[page_num]
18+
writer.add_page(page)
19+
20+
# Open a new file to write the PDF without metadata.
21+
new_pdf_file=f"{pdf_file.split('.')[0]}_no_metadata.pdf"
22+
withopen(new_pdf_file,'wb')asoutput_file:
23+
writer.write(output_file)
24+
25+
print(f"PDF file without metadata saved as '{new_pdf_file}'.")
26+
else:
27+
print("No metadata found in the PDF file.")
28+
29+
# Specify the path to your PDF file.
30+
pdf_file_path="EEE415PQ.pdf"
31+
32+
# Call the function to remove metadata.
33+
remove_metadata(pdf_file_path)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PyPDF2==3.0.1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp