theeko74 / pdfc Goto Github PK
View Code? Open in Web Editor NEWSimple python script to compress PDF
Simple python script to compress PDF
Hello,
I'm using ghostscript 9.25, 64bit version and I was receiving the error in the title until I updated the 'gs' parameter in the list below to 'gswin64c'. I'm not sure how to handle this for all ghostscript versions (32 & 64 bit) and I'm not sure if this was not just my client problem, hence opening an issue and not a pull request.
Line 50 in 2a1811b
It's just an idea, but wouldn't it be easier if the Ghostscript python library was used instead of converting it to terminal commands and using the Ghostscript binary
level 0 and 1 and 2 are working but 3 give me this error
PS D:\Home\Scripts\pdfc-master> py .\pdf_compressor.py -c 3 -o hs.pdf .\hasse.pdf
Compress PDF...
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Failed to initialise downsample filter, downsampling aborted
Compress PDF...
Traceback (most recent call last):
File "D:\файлы\pdf-compress\pdf-comp\app.py", line 2, in
compress('Скан_20230722.pdf', 'Скан_20230722comp.pdf', power=4)
File "D:\файлы\pdf-compress\pdf-comp\src\pdf_compressor.py", line 47, in compress
subprocess.call(
File "C:\Users\pikaa\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 389, in call
with Popen(*popenargs, **kwargs) as p:
File "C:\Users\pikaa\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1024, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\pikaa\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1493, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Отказано в доступе
The command to add the directory to PATH in .bash_profile
is wrong, it should be
echo 'export PATH="/absolute/path/of/the/folder/script/:$PATH"' >> ~/.bash_profile
Compress PDF...
Compression by -62%.
Final file size is 5.17234MB
Done.
Ghostscript on Windows is not stored as gs.exe
but as gswin64.exe
or gswin32.exe
respectively. I'll do a PR to detect this automatically.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.