How Python Work
- Install Python (https://www.python.org/downloads/)
- Write a script in Notepad and save this file on desktop or any location in computer
- open CMD and run command to execute that NOTEPAD file
Merge Two Images (from two Different Folders)
Folder # 1 - signatures
Folder # 2 - photos
Python Code (Prepare the Python Script)
Copy this script into a file (notepad) and save it as merge_images.py (for example, on your Desktop):
-----------------------
from PIL import Image
import os
# Update these paths to match your desktop folders
user = os.getlogin()
desktop = os.path.join("C:\\Users", user, "Desktop")
photo_folder = os.path.join(desktop, "photos")
signature_folder = os.path.join(desktop, "signatures")
output_folder = os.path.join(desktop, "merged")
# Create output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
for photo_file in os.listdir(photo_folder):
if photo_file.lower().endswith(('.jpg', '.jpeg', '.png')):
photo_path = os.path.join(photo_folder, photo_file)
signature_path = os.path.join(signature_folder, photo_file)
if os.path.exists(signature_path):
photo = Image.open(photo_path).convert("RGB")
signature = Image.open(signature_path).convert("RGB")
# Resize signature to match photo width
signature = signature.resize((photo.width, int(photo.height * 0.25)))
total_height = photo.height + signature.height
merged_image = Image.new("RGB", (photo.width, total_height), color=(255, 255, 255))
merged_image.paste(photo, (0, 0))
merged_image.paste(signature, (0, photo.height))
merged_path = os.path.join(output_folder, photo_file)
merged_image.save(merged_path)
print("✅ Merging complete! Check the 'merged' folder on your Desktop.")
-----------------------
Run CMD (Command Prompt)
Enter following in CMD to go on Desktop
cd %USERPROFILE%\Desktop
Enter following in CMD to run python scrip (file that was save on desktop)
python merge_images.py
----------------------------------------
Extract text of 1st two pages and number of pages from PDF file
install these Libraries by giving command in CMD
pip install pymupdf pandas openpyxl
Save this Python scrip in note pad and save on desktop and save Pdf files in pdf folder on desktop
import fitz # PyMuPDF
import os
import pandas as pd
# Path to your PDF folder on Desktop
folder_path = r'C:\Users\RAUF-MULTIMEDIA\Desktop\pdf'
# Path to save the Excel file
output_path = r'C:\Users\RAUF-MULTIMEDIA\Desktop\pdf_texts.xlsx'
# List to store extracted data
data = []
# Loop through all PDF files in the folder
for filename in os.listdir(folder_path):
if filename.lower().endswith('.pdf'):
pdf_path = os.path.join(folder_path, filename)
try:
doc = fitz.open(pdf_path)
text = ''
num_pages = doc.page_count # total pages in this PDF
# Extract text from the first two pages (or fewer if not available)
for page_num in range(min(2, num_pages)):
text += doc[page_num].get_text()
doc.close()
# Add extracted data to the list
data.append({
'Filename': filename,
'NumPages': num_pages,
'Text': text.strip()
})
except Exception as e:
data.append({
'Filename': filename,
'NumPages': None,
'Text': f'Error reading file: {e}'
})
# Create DataFrame and save to Excel
df = pd.DataFrame(data)
df.to_excel(output_path, index=False)
print("✅ Text and page counts successfully extracted and saved to Excel!")
Save above text in Notepad and File Name and extension (save this file on desktop)
extract_pdf_text.py
Run it via Command Prompt:
cd %USERPROFILE%\Desktop
extract_pdf_text.py
No comments:
Post a Comment