Generalepstopdf | Disable Compression

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

epstopdf | Disable Compression

Post by cbkschroeder »

Hello,

I'm new to the community; thank you for taking the time to read my question!!

I'm not at all new to LaTeX (using since '94, probably) but as always, there's learning to be done! Today I'm using MikTeX 2.7 and WinEdt 5.4 on XP SP3.

Here's my issue:

One of my data acquisition systems gives me image output in .xv format. I'd like to be able to import this image into my LaTeX document. Of course, it's trivial to convert this .xv image to whatever I want using the lovely GIMP, so, because I'm using LaTeX, I save this as a .eps file. This, of course, goes nicely into LaTeX. With this I can produce .dvi files (an unavoidable necessity in my situation) as required and all is well. I anticipate, however, that my final document will be compiled using PDFLaTeX; it's trivial to use the wonderful epstopdf package to do on-the-fly conversion of my files from .eps to .pdf (how cool is that?!) BUT (and here's the problem), there's this issue with the darn compression thing. Upon viewing my .pdf document, it becomes patently obvious that epstopdf uses lossy compression by default to produce its output; this I cannot have at all. I'm sure you can appreciate that the subtleties in data must be seen and not lost or altered. So, after this long story comes my question: how do I very simply disable lossy compression use by epstopdf both when it's used on the fly and ('cause it's nice to be able to do it occasionally) when it's called from the CLI? For the record, file size isn't an issue.

I'm sure one might be tempted to suggest that I use GIMP to save to .pdf directly. That would be a perfect solution except that I need to be able to generate .dvi files; .eps files are hence a must. I've got things set up right now such that I change a couple of comment characters and I can trivially go between .dvi and .pdf output; I wish to maintain this arrangement of things.

I've googled on this problem somewhat extensively and have had these nibbles:

http://datenroulette.de/blog/index.php?blog=1&m=200806
http://ansuz.sooke.bc.ca/software/ps-pdf-tricks.php

I'm just not putting it together in my head for some reason, unfortunately. If anyone would be so kind as to lend a moment of their expertise to this issue, I'd be profoundly grateful.

Regardless, thanks again for your time!

Christian

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

epstopdf | Disable Compression

Post by phi »

Hello,
epstopdf doesn't seem to have an option for this. a2ping has an option, but doesn't run on Windows. Nevertheless, you can always call ghostscript directly. a2ping works by injecting the setpagedevice command in the input stream for gs, but writing to the systemdict could also work.
The command line for ghostscript, according to your second source and the a2ping source code, could then look like this:

Code: Select all

gs -q -dBATCH -dNOPAUSE -dSAFER -sDEVICE=pdfwrite -sOutputFile=something.pdf -dAutoFilterMonoImages=false -dAutoFilterGrayImages=false -dAutoFilterColorImages=false -dMonoImageFilter=/LZWEncode -dGrayImageFilter=/LZWEncode -dColorImageFilter=/LZWEncode something.eps
(This is untested, but should work)

Here some other (similar?) ways are described:
http://electron.mit.edu/~gsteele/pdf/
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: epstopdf | Disable Compression

Post by cbkschroeder »

Hi Phi,

Thanks for your reply and your suggestions. I hacked away at this problem quite extensively since I made that posting and can state that I came up with the following last night:

epstopdf --gsopt="-dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -sColorImageFilter=FlateEncode -sGrayImageFilter=FlateEncode -sCompressPages=false -dPreserveHalftoneInfo=true" <filename.eps>

The chart at:

http://pages.cs.wisc.edu/~ghost/doc/cvs/Ps2pdf.htm

is quite useful at helping one identify the results of various options.

With respect to implementing the above when using epstopdf for on-the-fly conversion, I added the following:

\DeclareGraphicsExtensions{.eps,.pdf}
\DeclareGraphicsRule{.eps}{pdf}{.pdf}{`epstopdf --gsopt="-dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -sColorImageFilter=FlateEncode -sGrayImageFilter=FlateEncode -sCompressPages=false -dPreserveHalftoneInfo=true" #1}

just after:

\usepackage[pdftex]{graphicx}
\usepackage{epstopdf}

in my document's preamble. Consequently, epstopdf now performs on-the-fly conversion to .pdf using non-lossy compression.

I hope someone else finds the above useful; my question, as determined with all my Googling, never seemed to be directly answered online anywhere else. Thank you also for your response as the link you sent me is also useful.

If anyone has any comments on the above as to why what I did might not be "proper" or if there's a better suggestion, I'd love to hear your thoughts. Thanks, all, for your time.

Cheers,

Christian
shroomy115
Posts: 4
Joined: Thu Jan 13, 2011 4:52 pm

epstopdf | Disable Compression

Post by shroomy115 »

Sorry to bring this thread back from the dead. I had this same problem with using the epstopdf package on certain EPS files from Matlab, and found a different solution. (For an example of what I was seeing, see http://www.mediafire.com/file/3m7vvtavg ... ersion.pdf for what the file should look like and http://www.mediafire.com/file/utzw6ymjc ... ersion.pdf for the poor conversion.) I tried exporting PDF files directly from Matlab, but they were still plagued with the same poor quality.

I wasn't able to get cbk's solution to work (TexnicCenter and Ghostscript went berserk during the conversion process). What I found to work was to use the EPS level 2 print option from Matlab (documented at http://www.mathworks.com/help/techdoc/ref/print.html). The figures having the problems were EPS level 1. This is probably a less desirable solution, since cbk was able to get epstopdf to work well, but it may be easier for some (like me) to get working.
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

epstopdf | Disable Compression

Post by cbkschroeder »

I, too, will do my part to prevent this thread from finally dying.

I suspect the reason your stuff went "berserk" is because you failed to add the switch "--enable-write18" to the command line when executing LaTeX. The need for this is documented in the epstopdf package manual (page 2 of v2.5, for example). Failing to set this will prevent the LaTeX-external program from being executed.

Hope this helps; when the script works, it's really very convenient. I ended up using a mere three lines to get my job done:

Code: Select all

\epstopdfsetup{update,prepend,verbose,suffix=-generated} % use suffix because you don't want to accidentally overwrite a file that might have been a pdf source. The epstopdf package manual has more on that.

\DeclareGraphicsExtensions{.eps,.pdf}

\epstopdfDeclareGraphicsRule{.eps}{pdf}{.pdf}{epstopdf --gsopt="-dPDFSETTINGS=/prepress -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -sColorImageFilter=FlateEncode -sGrayImageFilter=FlateEncode -sCompressPages=false -dPreserveHalftoneInfo=true" #1 --outfile=\OutputFile}
Cheers,

Christian
Post Reply