View Single Post
Old 11-16-2024, 11:25 AM   #27
Rémi Ozene
Member
Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.Rémi Ozene is as sexy as a twisted cruller doughtnut.
 
Posts: 14
Karma: 15490
Join Date: Aug 2023
Device: Pocketbook Inkpad EO & Pocketbook Inkpad lite 970
Quote:
Originally Posted by ab78727 View Post
I tried the following on colab.research.google.com and it seemed to retrieve the file and run gs on it (I just gave it some basic arguments and not the ones that you had specified)
I asked CHATGPT to make me a script on Google Colab using Ghostscript to lighten the background of a PDF image file with a dark background from archive.org. The execution of the script took nearly 30 minutes, for a file of 600 pages and 30 megas. Here is the Chatgpt script (notebook with format ipynb), for a file named "myfile.pdf":

# Étape 1 : Install Ghostscript
!apt-get install -y ghostscript

# Étape 2 : Check for the presence of the file named "myfile.pdf"
import os

input_file = "/content/ myfile.pdf" # Input file name
output_file = "/content/output_lightened.pdf" # Output file name

if not os.path.exists(input_file):
raise FileNotFoundError(
"The file 'myfile.pdf' was not found in the /content directory. "
"Please upload your file with this name."
)

# Step 3: Apply Ghostscript to lighten the background
print("Processing the file with Ghostscript...")
gs_command = f"""
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/default \
-dNOPAUSE \
-dBATCH \
-dColorConversionStrategy=/Gray \
-dProcessColorModel=/DeviceGray \
-sOutputFile={output_file} \
{input_file}
"""

# Run the Ghostscript command
os.system(gs_command)

# Step 4: Check if the output file has been generated
if not os.path.exists(output_file):
raise FileNotFoundError("The processed file has not been generated. Check the input and processing parameters.")

print("The treatment is complete. File processed : output_lightened.pdf")

# Step 5: Download the processed file
from google.colab import files
print("Download the clarified file...")
files.download(output_file)
Rémi Ozene is offline   Reply With Quote