103 lines
2.1 KiB
Markdown
103 lines
2.1 KiB
Markdown
# Guía de Ghostscript
|
|
|
|
Ghostscript permite comprimir y convertir archivos PDF desde la línea de comandos.
|
|
|
|
## 1. Comprimir PDF en Linux
|
|
|
|
```bash
|
|
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=salida.pdf entrada.pdf
|
|
```
|
|
|
|
---
|
|
|
|
## 2. Comprimir PDF en Windows
|
|
|
|
### CMD
|
|
|
|
```cmd
|
|
gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=salida.pdf entrada.pdf
|
|
```
|
|
|
|
### PowerShell
|
|
|
|
```powershell
|
|
gswin64c "-sDEVICE=pdfwrite" "-dCompatibilityLevel=1.4" "-dPDFSETTINGS=/ebook" "-dNOPAUSE" "-dQUIET" "-dBATCH" "-sOutputFile=output_PRO.pdf" "progit.pdf"
|
|
```
|
|
|
|
---
|
|
|
|
## 3. Parámetros importantes
|
|
|
|
- `-sDEVICE=pdfwrite` → salida en PDF
|
|
- `-dCompatibilityLevel=1.4` → compatibilidad del PDF
|
|
- `-dPDFSETTINGS=/screen` → alta compresión, calidad baja
|
|
- `-dPDFSETTINGS=/ebook` → calidad media
|
|
- `-dPDFSETTINGS=/printer` → impresión
|
|
- `-dNOPAUSE` → sin pausas entre páginas
|
|
- `-dQUIET` → sin mensajes excesivos
|
|
- `-dBATCH` → no requiere interacción
|
|
- `-sOutputFile` → archivo final
|
|
|
|
---
|
|
|
|
## 4. Alias útil en Linux
|
|
|
|
```bash
|
|
alias comprimirpdf='gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH'
|
|
```
|
|
|
|
Uso:
|
|
|
|
```bash
|
|
comprimirpdf -sOutputFile=salida.pdf entrada.pdf
|
|
```
|
|
|
|
---
|
|
|
|
## 5. Script Bash
|
|
|
|
```bash
|
|
#!/bin/bash
|
|
# Uso: ./comprimir-pdf.sh entrada.pdf salida.pdf
|
|
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
|
|
-dNOPAUSE -dQUIET -dBATCH \
|
|
-sOutputFile="$2" "$1"
|
|
```
|
|
|
|
Dar permisos:
|
|
|
|
```bash
|
|
chmod +x comprimir-pdf.sh
|
|
```
|
|
|
|
---
|
|
|
|
## 6. Script Windows `.bat`
|
|
|
|
```bat
|
|
@echo off
|
|
if "%~1"=="" (
|
|
echo Arrastra un archivo PDF sobre este script para comprimirlo.
|
|
pause
|
|
exit /b
|
|
)
|
|
|
|
set "input=%~1"
|
|
set "output=%~dpn1_compress.pdf"
|
|
|
|
gswin64c "-sDEVICE=pdfwrite" "-dCompatibilityLevel=1.4" "-dPDFSETTINGS=/ebook" "-dNOPAUSE" "-dQUIET" "-dBATCH" "-sOutputFile=%output%" "%input%"
|
|
|
|
echo PDF comprimido generado: %output%
|
|
pause
|
|
```
|
|
|
|
---
|
|
|
|
## 7. Resumen
|
|
|
|
Ghostscript es muy útil para:
|
|
|
|
- reducir tamaño de PDFs
|
|
- preparar archivos para web o impresión
|
|
- automatizar compresión en scripts
|