1

I am generating multiple EPS files, which contain several PostScript drawing commands that are not necessarily encoded efficiently. The first update in the answer to this question describes similar inefficiencies.

Each of my EPS files are around 18 MB, and the resulting PDF files are around 3 MB. I am generating the PDF files using epstopdf, which enables some sort of compression by default.

Are there any suggestions for how to further reduce the resulting PDF file sizes without changing the quality (e.g. rasterizing the vector graphics)?

I tried reducing the precision of the coordinates from 8 digits past the decimal to 3. This reduced the EPS file sizes to about 14 MB, but, counter-intuitively, the PDF file sizes slightly increased.

Update 1: The EPS files contain several occurrences of the sample code below for different coordinates and colors.

newpath
1 setlinejoin
1 setlinecap
<<
/BBox [322      384.0417      615.0087      651.9958]
/Domain [322      384.0417      615.0087      651.9958]
/ShadingType 6
/ColorSpace [/DeviceRGB]
/DataSource
[
0
   350.00000000    651.99583594
   336.00000000    645.75890880
   336.00000000    645.75890880
   322.00000000    639.52198166
   339.17140372    627.26533984
   339.17140372    627.26533984
   356.34280743    615.00869803
   370.19224806    621.16169097
   370.19224806    621.16169097
   384.04168868    627.31468392
   367.02084434    639.65525993
   367.02084434    639.65525993
0.23047     0.29688        0.75 
0.23047     0.29688        0.75 
0.41081     0.54141     0.93366 
0.41112     0.54178     0.93388 
]
>>
gsave
322      615.0087      62.04169      36.98714 rectclip
shfill
grestore

Update 2: I have been able to reduce the PDF file sizes by about 15% by using pdftocairo, followed by gs -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dDetectDuplicateImages=true -sOutputFile=out.pdf in_.pdf.

BaronFiner
  • 154
  • 5

1 Answers1

1

PostScript is a programming language and PDF is not, so often you can actually create a smaller PostScript program than the resulting PDF file.

The 'inefficiencies' you mention in your EPS program, and the precision of the input numbers, are completely irrelevant to the size of the PDF file. The operators in PDF are not the same names as the operators in PostScript, so a 'moveto' in PostScript does not simply get translitereated into a 'moveto' in the resulting PDF file. The precision of numbers in the output PDF file is not tied to the precision of the numbers in the input.

In addition, PostScript interpreters often use a fixed precision arithmetic (Ghostscript for example uses 24:8), so (eg) 1.5 on the input may not be produced as 1.5 on the output, it may instead become 1.49999999.

So the result of this, basically, is that nobody can tell why your PDF files are as large as they are without seeing them. I would suggest that a 6:1 reduction in size is pretty reasonable personally. If you post a representative example somewhere its possible someone could look at it and might be able to offer some suggestions, but without seeing the content its not really possible to tell.

NB rendering the content would most likely increase the size of the PDF file, unless you render at a really low resolution.

EDIT

The supplied example is simply a shading dictionary, the PDF file will contain almost exactly the same data for that particular construct. Its already about as compact as you could expect, I very much doubt it this is the sort of thing occupying 18MB of source, that would be an enormous amount of shadings. There is no realistic way to make that smaller, and rendering it to a bitmap (even at very low resolution) would actually make it larger.

Its entirely possible the EPS contains things like a bitmap preview, which will, of course, be removed when creating a PDF. It may also (depending on the creating application) contain the original document, stored as comments, which will also be removed when creating a PDF file. Without seeing the original EPS its not really possible to suggest much.

I'm afraid posting little bits of the file isn't going to help really.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Thanks for the information. I updated the original question to show some sample code. – BaronFiner Jul 06 '17 at 19:08
  • I am generating the EPS file from scratch by simply writing the commands. There are no comments or previews included. The actual EPS file just includes about 10,000 instances of shading different quadrilaterals, using the type of syntax I included in the question. – BaronFiner Jul 06 '17 at 19:59
  • 1
    Well in that case, the resulting PDF is about as compact as its going to get. – KenS Jul 07 '17 at 07:07