Showing posts with label PDF. Show all posts
Showing posts with label PDF. Show all posts

20130607

PDFcrop

It's been a while, but guess what?  It's time for more exciting notes on manipulating PDFs for preparation of scientific documents!

To crop a PDF to its bounding box, just try
pdfcrop input.pdf output.pdf
That's all!
This relies on having pdfcrop installed, but it seems to be there in my install of cygwin.

20100306

epstopdf rotating issue

Another post more for my own benefit and future reference.

epstopdf often rotates figures that you'd prefer it didn't. That's ghostscript getting a bit eager. The following kludge will fix it:

export GS_OPTIONS=-dAutoRotatePages=/None

before running epstopdf as usual.

Edit:

Or
export GS_OPTIONS="-dPDFSETTINGS=/prepress -dAutoRotatePages=/None"
to embed fonts as well...

20081106

More PDF font embedding hijinks

I've complained bitterly before about the stupid requirement of many publishers (IEEE, ACM) to embed all fonts in a PDF document -- including the "base fonts", which any compliant reader must be able to render. Because of this, it's actually quite hard to persuade many pieces of software to embed base fonts, because, why would you ever need to do this? This can lead to quite a stalemate, and a lot of frustration.

I had a nice system all working, but in my latest work I've been using Gnuplot with the PDF terminal. This outputs directly to PDF, and avoids a bug in Gnuplot when generating bar charts. All well and good, except that the resultant PDF does not embed the base fonts. And there's virtually no documentation on the Gnuplot PDF terminal, certainly nothing that talks about this.

So, after a lot of frustration and swearing, I came up with the following ugly hack: run the pdf through gnuplot ghostscript with the pre-press option, and output to pdf. Here's the command line I came up with, though it might be more complex than it needs to be:

gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=tmp.pdf -dCompatibilityLevel=1.3 -dPDFSETTINGS=/prepress -c .setpdfwrite -f $1

Where $1 is the name of the input file, and tmp.pdf is the name of the output.

The ironically named "PDF Express" system has yet to verify that the resulting compiled file does the necessary thing, but I'm reasonably confident that it will work now.

20071112

Embed this, mofo!

Oh, I've been really struggling with my fonts. I'm sure I've complained about this before, but I can't find the reference. A number of idiotic publishing companies (ahem, IEEE and ACM) have recently started getting really snotty about embedding fonts into files. In particular, they complain like crazy if you don't embed fonts like symbol and helvetica into your PDF files when you send them to get published. This is particularly idiotic, since these files are part of the "14 base fonts" which every PDF reader must be able to render without needed the fonts to be embedded. So it's a pretty ridiculous rule, and I've wasted some amount of my life whinging at them for having such a rule. In particular, because some perfectly nice PDFs generated by pdflatex have been rejected for this reason. These folks wouldn't give any useful suggestions about how to fix the problem, other than "send us the PS version, and we can generate the compliant PDF." But I'm using PDFLaTeX -- there is no PS version (not even a DVI version). Generating PS would be silly, I'd have to use pdf2ps or similar.
Finally today, I have worked out a clean solution which does not offend me.

Firstly, it turns out that most of the problem is actually coming from the embedded graphics. pdflatex itself does seem to satisfactorily embed most fonts, although you can force it to if necessary, and there are various sites around which say how to do this. But this doesn't help included PDF figures which don't have fonts embedded already. For xfig and so on (another tip: in xfig, the "view --> portrait/landscape" option will fix it so that your figure is output with the correct orientation if it's coming out twisted when you export it), just export direct to PDF and it should work. But some figures are generated in eps format, and then converted to PDF. Usually, I use epstopdf to do this, since it gets the bounding box right, but it doesn't seem to do the trick. So here is what you need to do: issue the command
export GS_OPTIONS=-dPDFSETTINGS=/prepress

and then all will be well. You can work it out for yourself why this will work.

20060117

pdflatex and letter paper

One of the slight irritations in my life was getting pdflatex to output on US letter paper. For some reason, whatever I did, setting [letterpaper] options in the documentclass settings, trying to edit the pdf configuration files and so on, I didn't seem to have much luck. Eventually I found a fix: putting the lines
\setlength{\pdfpagewidth}{8.5in}
\setlength{\pdfpageheight}{11in}

in the preamble seemed to work, but seemed a bit clunky.

Then today, I found a new fix: putting
\usepackage{graphicx}
in the preamble seems to fix the paper size. I have no idea why. In the event, I seem to have this line in a lot of tex files I write since it's used to include graphics. That explains why it's only in a few cases that I've struggled with this problem. It's funny, in all the searching I've done for this problem, I've never seen anyone suggest this solution, so I'll post this here on the offchance that it helps someone else. Or rather, for next time I have the same problem and can't rememeber what I did last time to fix it...

Edit June 06: It seems to have broken again on my system, and the graphicx trick doesn't seem to work anymore. I tried something called 'texconfig', but this didn't seem to make any difference. So, back to the tried and tested pdfpagelength technique. (This seems to partly be a problem with the ACM's sig-alternate style, I think, since it was working fine till I switched class files.

Edit November 06: Here's a slightly cleaner way that means that people still living in the past and using latex -> dvips -> ps2pdf can still compile the same file: include
\usepackage{ifpdf}
\ifpdf
\setlength{\pdfpagewidth}{8.5in}
\setlength{\pdfpageheight}{11in}
\else
\fi

Of course, then you need ifpdf, but it's part of most modern tex distributions (as indeed is pdflatex, which rather renders the whole effort redundant, but means that I can just send people the ifpdf file to get it to compile if they don't have it).

Edit April 2008:
Another thing to remember: when compiling with the ACM style files, remove all use of the 'fullpage' package (and probably other packages that play around with the page size, such as geometry). Otherwise, for some reason, LaTeX creates a never-ending stream of blank pages.