I am running gnuplot on Windows 11 with a pdf terminal. After I have produced the .pdf plot I have a look at it and then make changes in the gnuplot script. Running that script now again will produce a new .pdf output file only if the original one is closed. This is a nuisance: is there a way to simply overwrite the original .pdf output file? If I work with a postscript terminal this is no problem: the previous plot is just being overwritten.
-
@KJ I would consider your comment as a full answer. Maybe you want to post it as such, so that the question can be marked as answered. – theozh Aug 03 '23 at 18:36
2 Answers
I undelete this earlier post because apparently @KJ doesn't want to put his comment with more details as answer. Hence, short answer for Windows: use SumatraPDF viewer.
Acrobat Reader (and maybe other PDF viewers) will lock the opened PDFs and will prevent overwriting from other programs.
One possible solution: use Sumatra PDF as PDF viewer and the newly created PDFs by gnuplot (or other programs) will be updated. Apparently, it is for Windows only.

- 22,244
- 5
- 28
- 72
-
-
@user3584513 for more details see KJ's comment. Actually, I was not aware about the 32 MB limit. But most gnuplot output PDFs are probably smaller than that. – theozh Aug 15 '23 at 11:45
I had the same problem and found I could use the taskkill command to close the PDF viewing program from gnuplot. The command:
file=system('taskkill /IM gsview32.exe')
in my gnuplot script would, for example, close the gsview program used to view postscript files. Then I just produce the plot the normal way, then:
set output
without a filename to close the new plot file and call the viewer:
file=system('start "" gnu.ps')
Where gnu.ps is the plot filename I used in:
set output 'gnu.ps'
Edit: After some experimenting, the following was found to work for Foxit Reader:
file=system('taskkill /IM FoxitPDFReader.exe')
file=system('timeout 1 >nul')
set term push
set term pdfcairo enh font "Arial,15" color dl 0.75 size 9,6.5
set out "gnu.pdf"
set size 0.95,0.95
set origin 0.025,0.01
rep
set size 1,1
set origin 0,0
set term pop
set out
file=system('start "" gnu.pdf')
Just save this to a script file and load it any time you want to update the plot. If you save to <gnuplot directory>\share\PDF_plot.plt you can add the following text to <gnuplot directory>\bin\wgnuplot.mnu and have a item to click on the toolbar:
PDF plt!
load 'PDF_plot.plt'{ENTER}

- 76
- 5
-
Actually it does. I use it and I must at least close the tab that displays a given file to unlock it. – helper Aug 16 '23 at 22:33
-
Thanks. I wrote a script that closed only the tab that contained the file I wanted to modify. It was rather complicated and this is an easier fix. – helper Aug 17 '23 at 15:55
-
1You got me thinking and I found gsview has a -e option: (gsview -e filename.ps) that prevents a new window from opening each time it is called and simply refreshes the image to the new image if the window is already open. – helper Aug 18 '23 at 16:42
-
1I had to put the option in the registry in both cases. I used FileTypesMan from NirSoft to make that easy. – helper Aug 18 '23 at 16:48
-
1Using Foxit Reader with /A nolock=1 after the filename works just fine with PDFs larger than 33Mb. I experimented with a 149 Mb PDF and there was no problem. gsview with the -e option also works fine. Open the file again and the window updates. – helper Aug 18 '23 at 18:38
-
@K-J where did you find that /A option? I can't seem to find a complete list of /A options for Foxit anywhere. – helper Aug 19 '23 at 17:04