Assume I have a file on my machine at file:///c:\figure.bmp.

From my pdf document, that is created by LaTeX using hyperref.sty, how can I open figure.bmp using mspaint.exe (microsoft built-in image editor)?

What is the correct command to do this scenario?

If I call as follows

\href{file:///c:\figure.bmp}{To open the figure, click here.}

the figure.bmp will be opened using Illustrator (for example).

Actually I can change the file association to open bmp using mspaint instead of illustrator. But, I prefer to find another elegant approach, i.e., by specifying both file to be opened and the application used to open.

  • 1
    This is basically a duplicate of tex.stackexchange.com/questions/2851/… . Since this question is more generic, I would suggest closing the other question as a duplicate of this one.
    – Caramdir
    Dec 2 '10 at 3:30
  • @Caramdir: I think we can tolerate having both, since this one is Windows-centric and the other is Unix-centric. Dec 2 '10 at 13:52

It looks like you want a "Launch" action; see Table 8.49 (p. 622) in Section 8.5.3 of the PDF Reference, version 1.6, or Table 8.53 (p. 660) in the same section of version 1.7.

Both versions can be obtained from the Adobe PDF Reference Archive; due to size, version 1.6 (8.8 MiB) might be preferred over version 1.7 (31 MiB). (The ISO standard should be avoided like the plague due to its poor typography.)

It looks like the easiest way to actually use this is to use the pdfLaTeX primitives \pdfstartlink and \pdfendlink; see the manual on the pdfTeX page.


Well, it didn't turn out to be particularly easy, but here is a complete example that almost works for me -- it seems to be interpreted correctly, but fails because (according to Reader) "it is currently disallowed by your system administrator".

(This might seem obvious, but the following is in the "plain" format, not LaTeX -- it's what they call a SpikeSolution.)

Oh, and a warning: I wouldn't suggest testing modifications of this in Adobe's Reader initially; when I tried it on a slightly malformed file, it would forget to close the file when I closed the window, so I would have to close Reader itself before I could re-run TeX. Instead, try it in gsview32, which has the added advantage of giving some sort of diagnostics rather than just not woring.

\pdfcompresslevel=0 % for debuggable PDF output

% taken from http://tex.stackexchange.com/questions/7136/.../7139#7139

% This is surprisingly tricky to get right; check the PDF file in a
% text editor to make sure the correct string was output! For example,
% I had {} instead of a space after the \dirsep, and that got copied
% to the output.
\def\figurepath{C:\dirsep figure.bmp}

See the file
  attr {/C [0.9 0 0] /Border [0 0 2]}
  user {
  /Subtype /Link
  /A <<
    /Type /Action       % This is a PDF "Action" dictionary ...
    /S /Launch          % ... for a "Launch" action
    /Win <<             % Nested dictionary of Windows-only stuff
      /F (mspaint)      % Application
      % Parameters; parens to delimit it as a PDF string, quotes so
      % that spaces won't foul things up, and \pdfescapestring to deal
      % with any (, ), or \ characters in the path
      /P (\pdfescapestring{"\figurepath"})
{\tt \figurepath}

  • Very nice solution.
    – TH.
    Dec 19 '10 at 0:18

You might be able to achieve the desired result if you don't just open the file, but open MSPaint with a call to the desired file.

You can achieve this if you follow the details given on this eHow-page

Open a File Open an image file by specifying the file location on your hard drive. Add a space after "mspaint" and type the full file extension (e.g.: "mspaint c:/folder/subfolder/filename"). Ensure the file name is completely accurate, including the file extension. View an image's exact location by right-clicking on the file and choosing "Properties."

On Windows this should work with using " " around the command line call. I couldn't figure it out though, since

\href{file:///C:/Windows/system32/mspaint.exe C:/Users/haberthuer/Desktop/SomeFile.bmp}{To open the figure, click here.}

just opens my Windows Explorer...

BTW: Why you'd want to open a .BMP file in MSPaint is another question... Could you explain why you want to do that?

  • thank you first. Have you tried your code by yourself first? :D I have done it, but failed. :D I want to run MS Visual Studio to open C# exercise file accompanying my tutorial article in pdf.
    – xport
    Dec 2 '10 at 11:26
  • 1
    As I said, I tried, but it didn't work, sorry. Does the reader of your tutorial absolutely need to open the example in MS Visual Studio. Wouldn't a "download example file here" link be enough to let the reader figure out how to proceed with the exercise file?
    – Habi
    Dec 2 '10 at 13:27
  • Yes, but it is the last option. :D
    – xport
    Dec 2 '10 at 14:28
  • I can't test, but maybe something like \href{run:/mspaint.exe c:\figure.bmp}{...} works (try using different ways to specify the paths).
    – Caramdir
    Dec 2 '10 at 16:49
  • maybe it's just an example, chosen because MS paint is so widely available on Windows machines (it being presumably rather silly to do this on anything else, where the user is expected to have some clue what they are doing and so on...)
    – SamB
    Dec 18 '10 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.