Linux Notice App

PDF Reduction with LinUxta Command line


PDF Reduction with LinUxta Command line

LinUxta File PDF Reduction

Different solutions,

SOLUTION 1

# compression with qpdf

qpdf --linearize --object-streams=generate a.pdf a-qpdf.pdf

Attention was also successful in the reduction in the PDF file that was not scanned.

SOLUTION 2

Direct compression with Ghostscript

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=a-gs.pdf a.pdf

Despite the better compression in the above scrip, the reduction is not enough

SOLUTION 3

https://aur.archlinux.org/packages/pdf-compress has a commonly used script to reduce the PDF file.

But this is more recommended to use PDF images from the browser.

You can download the script here.

If you are using different distributions other than Arch, you will need to install some addictions in advance.

You can use this BASH script for PDF compression in Debian, but first you need to install the necessary addictions.

Necessary addictions

You need the following packages for Script to work:

Sudo Apt Update

Sudo Apt Install Ghostscript imagemagick Bash

Optional but recommended packages:

Sudo Apt Install QPDF Exiftool

SCRIPT's features

This script is optimized especially for scanned documents and makes the following procedures:

Converts PDF into monochrome (black-and-white) 1-bit images

Reduces unnecessary high resolution

It can provide 90 %+ size reduction

Dark text is the most effective for white floor

# Simple use

./pdf-compress.sh file.pdf

# Complete a particular goal (40 %dimension = 60 %reduction)

./pdf-compress.sh -r 40 file.pdf

# Quiet Mode

./pdf-compress.sh -q file.pdf

# Change the original file

./pdf-compress.sh -f file.pdf

# Set white/black threshold values

./pdf-compress.sh -b 0.8 -e 0.4 file.pdf

IMPORTANT NOTES

⚠️ This script is only for scanned documents - not suitable for normal PDFs

⚠️ It reduces quality - Readability is maintained but visual quality decreases

⚠️ Monochrome output - Colorful documents become black and white

Examples of usage

./pdf-compress.sh A.PDF

In Ubuntu/Debian, Imagemagick restricts PDF operations by default.

Solution

You need to regulate Imagemagick's PDF policy:

sudo nano /etc/ımagemagick-6/policy.xml

Find this line in the file:

XML

<Policy domain = "coder" rights = "none" pattern = "pdf" />

Replace this line as follows:

XML

<Policy Domain = "Code" Rights = "Read | Write" pattern = "pdf" />

Or delete this line completely/comment:

XML

<!-<Policy domain = "coder" rights = "none" pattern = "pdf" />->

# Check possible locations

Sudo Find/Etc -Name "Policy.xml" 2>/Dev/Null

# Common Locations:

sudo nano /etc/ımagemagick-7/policy.xml

sudo nano /usr/local/etc/ımagemagick-6/policy.xml

After this change, your script will work properly.

Imagemagick's memory/cache limits may arise from the overcoming of the error. Your PDF may be large or system resources may be insufficient.

Solution 1: Increase Imagemagick Limits

Increase Resource Limits in Imagemagick Policy.xml:

sudo nano /etc/ımagemagick-6/policy.xml

Find these lines and increase your values:

<Policy Domain = "Resource" Name = "Memory" value = "256mib"/>

<Policy Domain = "Resource" name = "map" value = "512mib"/>

<Policy Domain = "Resource" Name = "Disk" value = "1gib"/>

<Policy Domain = "Resource" Name = "Area" value = "128MP"/>

Replace them as follows:

<Policy Domain = "Resource" Name = "Memory" value = "2gib"/>

<Policy Domain = "Resource" Name = "map" value = "4gib"/>

<Policy Domain = "Resource" Name = "Disk" value = "8gib"/>

<Policy Domain = "Resource" Name = "Area" value = "1gp"/>


*****

TURKİSH TRANSLATE

 LİNUXTA KOMUT SATIRIYLA PDF KÜÇÜLTME

LİNUXTA DOSYA PDF KÜÇÜLTME

FARKLI ÇÖZÜMLER,

ÇÖZÜM 1

# qpdf ile sıkıştırma

qpdf --linearize --object-streams=generate a.pdf a-qpdf.pdf

DİKKAT TARANMAMIŞ HAZIR PDF DOSYASINDA DA KÜÇÜLTMEDE BAŞARILI OLDU.

ÇÖZÜM 2

# Ghostscript ile doğrudan sıkıştırma

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=a-gs.pdf a.pdf

Taranmamış dosyalarda yukarıdaki scripte göre daha iyi sıkıştırma yapmasına rağmen küçültme yeterli değil

ÇÖZÜM 3

https://aur.archlinux.org/packages/pdf-compress  adresinde pdf dosyası küçültmek için sıkça kullanılan bir script var.

Ama bu daha çok tarayıcıdan pdf yapılan görüntüler için kullanılması tavsiye edilir.

Scripti burdan indirebilirsiniz.

arch dışında farklı dağıtımlar kullanıyorsanız önceden bazı bağımlılıkları yüklemeniz gerekecek.

Bu bash script'i Debian'da PDF sıkıştırma için kullanabilirsiniz, ancak önce gerekli bağımlılıkları yüklemeniz gerekiyor.

Gerekli Bağımlılıklar

Script'in çalışması için şu paketlere ihtiyacınız var:

sudo apt update

sudo apt install ghostscript imagemagick bash

İsteğe bağlı ama önerilen paketler:

sudo apt install qpdf exiftool

Script'in Özellikleri

Bu script özellikle taranmış belgeler için optimize edilmiş ve şu işlemleri yapar:

PDF'i monokrom (siyah-beyaz) 1-bit görüntülere dönüştürür

Gereksiz yüksek çözünürlüğü düşürür

%90+ boyut azaltımı sağlayabilir

Karanlık metin, beyaz zemin için en etkili

# Basit kullanım

./pdf-compress.sh dosya.pdf

# Belirli bir hedefe sıkıştır (%40 boyut kalsın = %60 azaltım)

./pdf-compress.sh -r 40 dosya.pdf

# Sessiz mod

./pdf-compress.sh -q dosya.pdf

# Orijinal dosyayı değiştir

./pdf-compress.sh -f dosya.pdf

# Beyaz/siyah eşik değerlerini ayarla

./pdf-compress.sh -b 0.8 -e 0.4 dosya.pdf

Önemli Notlar

⚠️ Bu script sadece taranmış belgeler içindir - normal PDF'ler için uygun değil

⚠️ Kaliteyi düşürür - okunabilirlik korunur ama görsel kalite azalır

⚠️ Monokrom çıktı - renkli belgeler siyah-beyaz olur

Kullanım Örnekleri

 ./pdf-compress.sh a.pdf

 Ubuntu/Debian'da ImageMagick varsayılan olarak PDF işlemlerini kısıtlar.

Çözüm

ImageMagick'in PDF politikasını düzenlemeniz gerekiyor:

sudo nano /etc/ImageMagick-6/policy.xml

Dosyada şu satırı bulun:

xml

<policy domain="coder" rights="none" pattern="PDF" />

Bu satırı şu şekilde değiştirin:

xml

<policy domain="coder" rights="read|write" pattern="PDF" />

Veya bu satırı tamamen silin/yoruma alın:

xml

<!-- <policy domain="coder" rights="none" pattern="PDF" /> -->

# Olası lokasyonları kontrol et

sudo find /etc -name "policy.xml" 2>/dev/null

# Yaygın lokasyonlar:

sudo nano /etc/ImageMagick-7/policy.xml

sudo nano /usr/local/etc/ImageMagick-6/policy.xml

Bu değişiklikten sonra script'iniz düzgün çalışacaktır.

ImageMagick'in bellek/cache limitlerinin aşılmasından kaynaklanan hata çıkabilir.. PDF'iniz büyük olabilir veya sistem kaynakları yetersiz olabilir.

Çözüm 1: ImageMagick Limitlerini Artırın

ImageMagick policy.xml dosyasında resource limitlerini artırın:

sudo nano /etc/ImageMagick-6/policy.xml

Şu satırları bulun ve değerlerini artırın:

<policy domain="resource" name="memory" value="256MiB"/>

<policy domain="resource" name="map" value="512MiB"/>

<policy domain="resource" name="disk" value="1GiB"/>

<policy domain="resource" name="area" value="128MP"/>

Bunları şu şekilde değiştirin:

<policy domain="resource" name="memory" value="2GiB"/>

<policy domain="resource" name="map" value="4GiB"/>

<policy domain="resource" name="disk" value="8GiB"/>

<policy domain="resource" name="area" value="1GP"/>





No comments

Powered by Blogger.