[Lowerbounds, Upperbounds]

Algorithms are everywhere.

Update on 2008-01-24:
The “back” feature is no longer needed, at least on Windows Acrobat Reader 8. See: Edit->Preferences->Documents->Restore last view settings when reopening documents

Update on 2007-01-30:
I have patched the source and replaced the zip files so that pdfclose will be less likely to crash Adobe Reader 8. Thanks to this post. Also, apparently pdfopen cannot issue a “back” command to Adobe Reader and you need the full version for that feature.

If you are a Windows user and use Acrobat or Adobe Reader(*) to view PDF files, you may have experienced Acrobat locking your PDF file, making it impossible to overwrite. This is a serious problem when previewing your paper in the PDF format because every time before you generate a new PDF, you need to remember closing the old PDF in Acrobat.

Part of my solution to this problem is to open the PDF using pdfopen:

pdfopen --file foo.pdf

This will allow me to close foo.pdf by:

pdfclose --file foo.pdf

Integrating these two commands into your work-flow is left as an exercise to the reader. :)

But there is still an important usability problem that these two commands won’t solve. Every time you re-open a PDF, you will not be on the same page when you closed it. Instead, you will be on the first page. How would I to fix this? One solution would be to press Alt-Left after I re-opened the PDF file. This goes back in history and brings me to the last view I was at. But I’ve got something better.

I’ve modified the source code of pdfopen from TUG to include an extra option --back to do the obvious thing. So instead of the above, you should open a PDF file by:

pdfopen --file foo.pdf --back

Now the cycle is complete. Phew!

I have posted the exe files in a zip. The source files are available too.

For the record, you can obtain the original pdfopen and pdfclose at this URL:
http://www.tug.org/tex-archive/systems/win32/web2c/current/binary/bin-pdftools-win32.zip

BTW, I’ve read that recent versions of TeXnicCenter and WinEdt can both perform this Acrobat cycle too. But I am not sure if they can go back to the previous view. Heh, surely I know my Emacs can. :P

P.S. I am also aware that you can use gsview32 to preview PDFs and gsview32 does not lock PDF files. That’s one way to avoid this problem.

(*) Really, it’s called Adobe Reader. I don’t know since when they dropped the middle word.

25 Comments

  1. Anonymous
    20:26 on July 15th, 2005

    The best way to view the paper while writing it down using latex, is to use some DVI viewer (yap for windows, xdvi for unix.)
    There are no lockings problems with DVI files, apparently. I use it everyday.

  2. stefan
    10:11 on August 31st, 2005

    You can also use ghostview to view the PDF and there the automatic refresh of a newly compiled PDF like we are used to it by the DVI viewers is available.

  3. Anonymous
    18:17 on December 9th, 2005

    It does not work when multiple pdf are opened.

  4. Anonymous
    18:31 on December 9th, 2005

    When multiple PDF files are opened, the “back” command need to run twice.

  5. It seems that the ‘–back’ option of pdfopen doesn’t work with Adobe Reader 7.0:
    pdfopen –file example.pdf –back
    Cannot execute command “[MenuitemExecute("GoBack")]” (error 16393)

    Someone any idea how to change the code in the source:
    if (bBack) {
    ExecuteCommand(”[MenuitemExecute(\"GoBack\")]“);
    }

    to make it happen again?

    moon

  6. After some testing, it seems that this only happens when you quit Acrobat Reader. To reproduce this error, I tried (with no Acrobat Reader running in the beginning):
    1. pdfopen –file foo.pdf
    2. go to, say page 4
    3. quit Acrobat Reader
    4. pdfopen –file foo.pdf –back

    After these, foo.pdf opens successfully, but it’s on page 1 and pdfopen prints that warning message. Is that the behavior that you observed?

    I notice that if you quit Acrobat Reader, then the navigation history will be lost. So I don’t think the “GoBack” method would work because there is no history to go back. I could suppress this error message if it makes your life easier, but I don’t think that’s what’s bugging you.

  7. I acknowledge that this is indeed a problem. In fact, the number of back commands you have to run depends on how many files you have opened between the moment you “pdfopen –file foo.pdf” and “pdfclose –file foo.pdf”.

    This is a somewhat unfortunate consequence of how Acrobat Reader keeps the navigation history. I don’t know how to fix this (yet).

  8. I came up with a similiar solution when working with TeXnicCenter. It is implemented in Perl and uses the OLE interface to Acrobat.

    http://www.dererumnatura.us/archives/2006/03/texniccenter_an.html

  9. Anonymous
    23:31 on April 23rd, 2006

    While you’re at it, is there a way to configure yap/emacs so that when you double click in yap, emacs goes to the right place in the source file? I heard that such a feature exists in WinEdt.

  10. I will do a longer post a bit later in the week. (If you use the auctex package, it’s actually quite easy.)

  11. BTW, I must add that I do know about DVI. Thanks! :P

    The only reason why I sometimes prefer using PDF to preview instead of DVI is that I have color in my text and YAP is still not very good at that. Plus, there is no hyperlink support.

    (I use dviout sometimes too. It’s a very mature DVI previewer on Windows.)

  12. This is also true, but honestly, I never really like the user interface of GSView32 on Windows… If one day I get some time to hack (which, again, is highly unlikely), I want to give it a much better modern user interface.

  13. Bernhard
    11:55 on June 7th, 2006

    Regarding the double click: everytime you do latex you have to use the option -src, i.e. the command line
    latex -src filename
    you can even configure .emacs to do this automatically whenever you hit the Latex button.
    Then, in yap go to View, Options, Inverse Search and type into command line:
    emacs +”%l”:31 “%f”
    The problem with this configuration is that now whenever you double-click in yap, this will open a new emacs-window instead of going to the old window in which you were working in. This seems to be a major hassle but I don’t know how to get around it.

  14. Bernhard
    11:59 on June 7th, 2006

    PS: Note that emacs and latex should be in the Windows path to make everything work out smoothly.

  15. Szabolcs
    15:08 on June 22nd, 2006

    Though the back button in Adobe Reader is active, the –back option doesn’t seem to be working. I gives the error

    Cannot execute command “[MenuitemExecute("GoBack")]” (error 16393)

    I use Adobe Reader 7.0.8. I tried to figure out how pdfdde works, but I had no luck with it.

  16. Szabolcs
    15:26 on June 22nd, 2006

    I’d like to note that I didn’t quit Acrobat Reader before trying to use pdfopen (I read the comment by moon). I closed the document with pdfclose. Actually the back button _is_ clickable after the document is reopened by pdfopen.

    Szabolcs

  17. Anonymous
    10:14 on July 12th, 2006

    It is my understanding that the command “[MenuitemExecute(”GoBack”)]” works only for the full Acrobat, not for Adobe Reader. (See the Wikipedia article on “Texniccenter”.) So the new version of “pdfopen” looks useless to Adobe Reader users. WinEdt supports this function (for Adobe Reader) by using some roundabout way.

  18. Christof
    14:43 on January 26th, 2007

    What I really dislike about latex is the need to convert bitmap graphics into eps, which usually bloats them up tremendously. pdflatex supports .jpg and .png bitmap graphics, and .pdf for vector graphics.

  19. uLI
    18:25 on September 18th, 2007

    Use sam2p to convert bitmapped images into eps. The resulting eps files are only marginally larger than the original jpg or png files.

  20. Basil
    14:44 on January 3rd, 2008

    Hello,

    how do I configure emacs to start pdfopen for viewing a *.pdf file?
    What has to be the value of the variable tex-output-view-style?
    I tried “C:\Programme\MiKTeX 2.5\miktex\bin\pdfopen.exe” but nothing happens… uhm.

    Thanks!

  21. Thomas
    7:52 on February 15th, 2008

    I’m using TexNicCenter and Adobe Reader 8.1. I can’t get the the “back”-feature to work even though I check the box as suggested on 2008-01-24. Are there any other settings that is needed to get this to work?

    Thanks!

  22. Thomas, I do not use TNC and therefore I have no fix for you. But I can guess what *may* be happening to you: TNC tries to circumvent the PDF locking issue by generating a new PDF each time with a different file name. So even though you have the “back” setting in AR8, you are invoking AR8 on a different file each time…

    As for how to fix this, you may have better luck asking in TNC’s forums. Sorry!

  23. Miguel
    6:18 on May 1st, 2008

    I have the same problem as Thomas, and it not depends on TNC but only about open/close pdf
    and mainly on Adobe Acrobat (pro).
    It seems that Acro/adobe Reader works differently on Adobe Acrobat.
    Maybe you can find the solution

  24. kmc
    14:53 on May 18th, 2008

    Even if ‘restore last view’ enabled, Acrobat 7.0 Pro only restore last view for the same file, if compiled and generated by LaTeX, Acrobat treats it like a new file and thus no ‘last view’ for it.
    I really like a re-implementation for the ‘back’ option, please.

    Thank you.