16

Im new to latex and sometimes I get this error message:

line 5: ! I can't write on file 'MasterThesis.pdf'. Please type another file name for output! Emergency stop.<to be reaad again>... ...\end{document}
Line 1: !==> Fatal error occured, no output PDF file produced!

Today when I got this message nothing seems to work to fix it. I have tried the following:

  • Installed a new editor which gives the same error (TeStudio and TexMaker)
  • Deleted all files except the tex file
  • Close all programs and processes in task manager that seems to be PDF-related
  • Restart the editor (TexMaker)
  • Reboot the computer
  • I got several GB left on the disk drive
  • Searched through the internet to find a solution
  • Rename the tex file to only letters (no spaces, dots, symbols, etc)
  • Change the name of the folder that contains the file

Last thing I did was to remove everything in the tex file (with backup of course) except for the following:

\documentclass[12pt, a4paper]{article}

\begin{document}
    Hello
\end{document}

But I still get the same error.

If I create a new empty file it manage to compile. Then I paste my work into it and the error occures. So I press ctrl+z a couple of times to undo until I reach the document that works but then the error is still there Im using Windows 8 and TexMaker.

Im working on my master thesis and it's very frustrating when I can't continue my work. Could someone please help me with this?

  • Welcome to TeX.SX! – Andrew Swann Apr 27 '15 at 13:59
  • 9
    are you using acrobat to view the pdf? that locks the file. most other pdf readers do not do that. – David Carlisle Apr 27 '15 at 14:03
  • Acrobat Reader is not installed. Im using "PDF-XChange Viewer". How could I stop it? I never opened the file in PDF-XChange Viewer. – Jesper Lundin Apr 27 '15 at 14:07
  • I have an app named reader which was installed on my computer when I bought it but I don't think I can remove it. – Jesper Lundin Apr 27 '15 at 14:29
  • @JesperLundin Try this. In TexMaker, go to options, and select the embedded viewer. This viewer, internal to TexMaker, should allow you to compile and view. Per Acrobat 'reader/viewer', because it holds file handles you have to actually close the viewer after each usage of the reader if any other process needs to use that file in Windows. – R. Schumacher Apr 27 '15 at 15:22
  • I tried Built-in Viewer, Built-in Viewer+Embed and External Viewer but they all gives the same error as before. If I create a new empty file it manage to compile. Then I paste my work into it and the error occures. So I press ctrl+z a couple of times to undo until I reach the document that works but then the error is still there... very weird... – Jesper Lundin Apr 27 '15 at 16:12
  • The reason behind the error is given in http://tex.stackexchange.com/questions/240860/i-cant-write-on-file-filename-pdf/333196#333196 – Bhanu Chander Oct 08 '16 at 11:56

4 Answers4

10

I had the same problem. If you use Adobe Acrobat reader X, go to the Preferences of Acrobat Reader. In the menu Security (Enhanced) deselect Protection and Protection Enhanced OR add the Folder Path of your pdf folder build with latex.
That's work with me !

de Nunwan
  • 101
7

The most common reason for the error "can't write to filename.pdf, save it to different name" that I observed during my works is because I've kept open the PDF file generated by quick-building the LateX file.

I mean if the pdf file was kept open, that was generated in the same directory (same folder) as the latex file, then LateX shows error. Try closing that opened pdf and then build your LateX file. It works!

  • 1
    This holds for some PDF viewers including Acrobat but not for others like Sumatra and Okular. The difference is that some PDF viewers lock the file to prevent it being changed while it is open in the viewer, for compiling latex this feature tends to be a nuisance as noted. – Dai Bowen Oct 08 '16 at 12:05
5

I found the problem thanks to https://www.overleaf.com. I created an account an pasted my code and it resulted with an error in a tikz figure, I forgot to put an semicolon, " ; ", in the end of a line which caused the program to not compile which also resulted in errors in other tex files that were not related to the one with the error. Many thanks to a friend on facebook who responded to my post on facebook about this problem.

5

I know this is not the answer to your question, but I sometimes also get that error.

If you work with a cloud drive such as Google Drive or Dropbox you often run into problems because the cloud starts syncing before writing to all the files is done.

The bigger your tex file, the longer it takes to compile, and the bigger your chances of encountering this type of error

A solution (If that is the problem) would be to stop the syncing with the cloud for the period of compiling.

Elad Den
  • 3,941