go back to homepage

Pdfopen for X11

The command-line programs pdfopen and pdfclose allow you to control the X Window System version of Adobe's Acrobat Reader from the command line or from within a (shell) script.

Background

Most people who use the Acrobat Reader to preview PDF files generated from TeX documents will know that it is a hassle to deal with documents that need to be compiled while being viewed.

The Linux version of Adobe's Reader simply does not notice that the PDF file has changed, and the Microsoft Windows version is even worse: it opens the PDF file using mandatory locking, making it absolutely impossible to recompile the document while it is still open in the Reader.

Because the problem was much more severe under Windows, a few years ago Fabrice Popineau has written two small programs that use DDE calls to control the Reader from an external script or batch

  • pdfclose to make the Reader close the file before the compilation starts
  • pdfopen to re-open the file afterwards.

The command lines

pdfclose --file <pdf file>
This will close an X window with the name <pdf file> (for Acrobat Reader 5) or the name Adobe Reader - <pdf file> (for Adobe Reader 7).

pdfclose --all
The Linux pdfclose command ignores the --all command-line switch. The Windows version will close only the files that were opened through pdfopen when --all is given, and this cannot easily be done under X11. Ignoring the options seems wiser than unconditionally closing all open PDF documents.

pdfopen
This command-line sends a "go to previous document" to an already existing, but empty, Adobe Reader window. There are perhaps some situations where this possibility might come in handy.

pdfopen --file <pdf file> [--page <pagenumber>]
The Linux version silently ignores a given --page option, because its behaviour would be near-impossible to predict. The program also reacts a bit differently to the --file option: if the file is already open in the Reader, it will close and re-open the document.

Normally, that last one is the command you want to use under Linux, because it will immediately re-open the PDF file you have given as an argument in the Reader, using the same page & view settings.

Usability

I've tested my programs with Acrobat Reader 5.0.10 under Mandrake Linux 10.1 using X.org 6.8.2, but the code is reasonably generic and should work without changes on most X11 implementations.

The programs will work using the new Adobe Reader 7.0 under Linux as well, but only if you keep your PDF files maximized within the main Adobe Reader window. The PDF document's name has to appear in the window title for the progams to work. Also, you probably want to set the preference "Reopen documents to last viewed page" to "All files". You can find this setting in the Startup page of the preferences screen.

Downloads

Download pdfopen: source

Documentation: xpdfopen.pdf.

Licensing

The programs are released to the public domain. Feel free to use the programs as you see fit, and happy TeXing!

Bugs

If you find a bug in the program, feel free to e-mail me directly. Or, if you expect the problem to be of more general interest, post a message to the tex-live mailing list.

Taco Hoekwater, Feb 27, 2007.