pdf file size

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

pdf file size

Miki Dovrat-2
Hi,

Can I give lyx (or imagemagick convert through lyx) or some other latex
package an option to resample all graphics in a certain resolution to
reduce the pdf file size?  convert has a -resample option.

I would love to do it "on the fly" without actually producing lower
resolution images on disk, and pointing to them. Can I run a python
script in the lyx tmp directory by lyx, or any such solution?

I know adobe acrobat does this on the output pdf for $300. Doing convert
on the pdf ruins the text as well.

Thanks

Miki

Reply | Threaded
Open this post in threaded view
|

Re: pdf file size

Steve Litt
On Tuesday 18 March 2008 17:03, Miki Dovrat wrote:

> Hi,
>
> Can I give lyx (or imagemagick convert through lyx) or some other latex
> package an option to resample all graphics in a certain resolution to
> reduce the pdf file size?  convert has a -resample option.
>
> I would love to do it "on the fly" without actually producing lower
> resolution images on disk, and pointing to them. Can I run a python
> script in the lyx tmp directory by lyx, or any such solution?
>
> I know adobe acrobat does this on the output pdf for $300. Doing convert
> on the pdf ruins the text as well.
>
> Thanks
>
> Miki

I wonder if you could do something with pdftk.

SteveTTroubleshooting: Just the Facts
Reply | Threaded
Open this post in threaded view
|

Re: pdf file size

Miki Dovrat-2

> I wonder if you could do something with pdftk.
>
> SteveTTroubleshooting: Just the Facts
>

Not that I have seen. You may compress the streams, but not specifically
reduce resolution of an image. However it is a command line and I could
do it with a script working on the pdf output - take apart the streams,
identify the images, and recombine them later, or some thing similar.

I will definitely try that.

Miki

Reply | Threaded
Open this post in threaded view
|

Re: pdf file size

José Matos
In reply to this post by Miki Dovrat-2
On Tuesday 18 March 2008 21:03:11 Miki Dovrat wrote:

> Hi,
>
> Can I give lyx (or imagemagick convert through lyx) or some other latex
> package an option to resample all graphics in a certain resolution to
> reduce the pdf file size?  convert has a -resample option.
>
> I would love to do it "on the fly" without actually producing lower
> resolution images on disk, and pointing to them. Can I run a python
> script in the lyx tmp directory by lyx, or any such solution?
>
> I know adobe acrobat does this on the output pdf for $300. Doing convert
> on the pdf ruins the text as well.
>
> Thanks
>
> Miki

Please add this to lyx bugzilla so that it does not get forgoten. I don't
remember to see this request before. All the times I had this problem before
I have fixed it by hand.

--
José Abílio
Reply | Threaded
Open this post in threaded view
|

Re: pdf file size

maarten rutgers
This post has NOT been accepted by the mailing list yet.
I have been hunting for an answer to this "pdf resulution" queston for a day or two now.
 
What I really want is very easily generate pdf of various sizes for e-mailing (maybe 100dpi, medium quality images), web distribution (150 dpi, higher quality images), and print (300 dpi, high quality images).  I have the usual types of images in my documents.  JPG for photos, some type of EPS or PDF for vector graphics.  PNG for screenshots.  Some vector graphics overlayed on screenshots and photos.  I want my PNGs to be losslessly compressed, and my Jpegs lossily compressed (preferably at a level of loss that I can define).  Ideally I want my PNGs not to be resampled, but i do want my jpegs to be resampled.

Well, you can't have everything you want, but I got pretty close.  

Using the View > PDF (ps2pdf) option from the main menu bar in LyX, you invoke the ghostscript knockoff of Acrobat Distiller called ps2pdf.  As you can see here:
http://www.ghostscript.com/doc/current/Ps2pdf.htm#Ps2pdf_vs_AD
they let you tweak nearly everything that distiller controls, including a few very handy presets called:
/screen (72 dpi)
/ebook (150 dpi)
/print (300 dpi)
Notes (7) - (11) in the above URL describe how lossy the compression is for the various options.

It also describes the litany of options that are encompassed by a setting like /ebook.  I have not been brave enough to try to fiddle with these options on an individual basis and am happy enough with the presets.

To have LyX use these options go to the LyX > Preferences on a mac or Tools > Preferences on a PC.
Then choose File Handling ->Converters. Under Converter Definitions, choose Postscritpt -> PDF (ps2pdf).

Now you should see something like this in the field labelled converter: ps2pdf13 $$i $$o
change this to: ps2pdf13 -dPDFSETTINGS=/ebook $$i $$o
Then click the "modify" button followed by the "save" button.

Now, every time you invoke the View > PDF (ps2pdf) command, you will invoke LyX to first convert all your included graphics to EPS files.  Then to run LaTeX (which will only handle EPS files, not PNG and such) to produce DVI. Then DVIPS to produce PS, and then PS2PDF to produce PDF with the graphics at the specified resolution and compression levels.

The output takes a while, but is generally small in size and looks pretty good.  

Supposedly ps2pdf is smart enough to discern a PNG file from a JPG file and will compress the PNG losslessly and the JPG lossily.  You can read more about that here:
http://www.baw.de/vip/abteilungen/wbk/Publikationen/docs/Distparm.pdf
under the parameter Autofiltercolorimages.

The only quirk I have noticed is that the PNG screenshots do end up with some minor artifacts.  They don't look like JPEG artifacts, but maybe it has something to do with downsampling.  I suspect it has something to do with my screenshots all being at slightly different DPI values (I usually scale them to a fixed width, so they all end up at different DPI levels) and their being rescaled.  Strangely it even happens when I go to print resolution where they appear to be upconverted to 300DPI.  In any case, the artifacts are not terrible and I will happily live with it if it means I can throw in the towel and move on with my work.

If I had my druthers, the PNG screenshots would simply be left alone DPI wise and compressed without loss, but all the DPI and quality changes would be applied to JPG photos.  Oh well, can't have it all.

On a side note, I also looked into pdfTeX / pdfLaTeX, which is what you get when you click the acrobat button in the LyX toolbar. This is much faster, but generally makes for larger pdf files with all the graphics with exactly as many pixels as the original files.  

I could not find anything about an easy way to resample the included images. There is a tempting command you can put in your preamble: \pdfimageresolution=dpi, where you replace the dpi by a number like 72 or 150....
but this only appears to be a fallback when no dpi information is stored in the included image itself.  Since there does appear to be an associated dpi value for all my PNG and JPG images, this command had no effect on the final output.
There is the somewhat more useful \pdfcompresslevel=N command (replace N with 0 through 9 where 0 is no compression and 9 is max compression) which only does lossless compression.  This is super for PNG screenshots, but useless for JPG photos.  A document with a lot of included PNG screenshots of dialog boxes and software windows compresses down very very well at level 9 and there are NO artifacts at all. Looks excellent.  But if there are JPGs at a high resolution, they are unaffected and their resolution is not reduced to keep the file size in check.

If you do want to try this, put those commands in the preamble by selecting from the main menu bar:
Document > Settings.  Then select Preamble and just type your commands in the text box, one per line.

There are other commands you may want to try and you can read about that at http://www.ctan.org/tex-archive/systems/pdftex/ in the pdf file on that page.  (usually called pdftex-a.pdf).

Finally there may be other options out there which involve making PS files and then using adobe's acrobat distiller and fiddling with its options.  Maybe it does not produce the artifacts on the PNG files I experienced with ps2pdf.

In any case, I am tired and will move on, now that I have shared some of what i have found.



Reply | Threaded
Open this post in threaded view
|

Re: pdf file size

andrew
This post has NOT been accepted by the mailing list yet.
the suggestion with the flag in ps2pdf is very useful and it worked for me on first try.
i found a small typo: the flag is /printer not /print -- this and other additional flags for higher quality are found in the reference mentioned.
thank you!