I have the following problem:

I am receiving various scanned PDF files from a Kyocera Scanner Device.

I have to automatically manipulate these PDF Files in order to:

1. Delete the colors from textmarkers
2. Convert the PDF to grayscale
3. Put it in our DMS

I am using a Bash-Script to do the job.

For deleting the textmarker colors and converting to grayscale I use Imagemagick:

```
convert -density 150 INPUT.pdf \
-channel rgba \
-alpha set \
-fuzz 15% \
-fill white \
-opaque 'rgb(255,200,195)' \
-opaque 'rgb(255,253,177)' \
-opaque 'rgb(255,155,240)' \
-opaque 'rgb(255,91,193)' \
-colorspace gray OUTPUT-convert.pdf

```

The resulting image is quite good, BUT the size of the PDF is huge:

Original: 365K
Converted: 1.358K

So I've found a ghostscript command to do the job and reduce the file size:

```
gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -dCompatibilityLevel=1.4 \
-sDEVICE=pdfwrite   \
-sColorConversionStrategy=/LeaveColorUnchanged \
-dPDFSETTINGS=/ebook \
-sOutputFile=OUTPUT-ghostscript.pdf OUTPUT-convert.pdf

```

Now the file sizes are:

Original: 365K
Converted: 1.358K (OUTPUT-convert.pdf)
Ghostscript: 500K (OUTPUT-ghostscript.pdf)

I can't figure out why the size of the PDF after manipulation, from color to grayscale, is higher then the original document. The density (150 dpi) is the resolution of the original document.

When I put the converted PDF (1.358K) through Adobe Acrobat on Windows and recreate the PDF, the size is 213K. I have no loss in quality. How can I achieve this under linux with a bash script?

Any help is appreciated!

Here is a link for example PDF Files:

<http://62.75.158.162/download/yKLu3fkbLy7MgkczDrKdG6osHdXh3jvy/>