# Can I close a PDF file, export a picture to the same file, and open it again with Mathematica commands?

I am asking this because I am drawing a plot in Mathematica and export it to a PDF format. I need to check the quality of the plot and may need to modify it and export it again. Sometimes I forget to close the PDF file and I have to go back to close it and run the Mathematica notebook again. Suppose I need to export a plot pic to PDF with the command

Export["C:\\Users\\abc\\figures\\pic.pdf", pic]

Is there a way I can put a command to close the file pic.pdf first (if it is opened), and open pic.pdf with another command after I Export it?

Basically, I am asking if Mathematica is capable of closing and opening a file by its path in another app, say a PDF reader.

• Perhaps it's possible, but it would seem like a bad idea: what if you had made changes to the file you force-closed? I'm sure in most cases it won't be an issue, but that one time you forget and force-close something important, it will hurt! :-) – MarcoB Jan 30 '17 at 22:11
• Since it is just an exported PDF file and I am not editing it directly in the PDF editor, I guess it is OK to force it closed. – nanjun Jan 30 '17 at 22:25
• A process can't close a file it did not open by itself. You need access to the operating system. There are many topics on this you are read about. It is not trivial at all. You need number of tools to do this. And to do all this from inside Mathematica? Forget it :) – Nasser Jan 31 '17 at 2:19
• Why don't you use a PDF viewer that supports auto-refresh once the file has changed? Under Windows you could use "sumatra pdf". – grbl Feb 3 '17 at 16:14
• @nanjun Yes this should be possible. Adobe Acrobat is one of the very few PDF viewer which block the files from beeing written to. – grbl Feb 6 '17 at 12:35

RunProcess[{"taskkill", "/IM", "AcroRd32.exe"}]
SystemOpen["C:\\Users\\abc\\figures\\pic.pdf"]