I am using MiKTeX 2.9 on Windows 7.

I'm getting the error: "can't write on pdf file." The pdf doesn't reflect what I wrote. What did I do wrong?

My input:


\textheight=8.5in\textwidth=6.6 in \baselineskip=18pt \parskip=6pt

\begin{document}  % added, was missing


\newpage \baselineskip=12pt


  • You're missing a \begin{document}. I'm guessing the log file will state this clearly or your editor.
    – abdulhaq-e
    Oct 19, 2012 at 20:38
  • No, I have: \oddsidemargin=1.0in\evensidemargin=0.in \textheight=8.5in\textwidth=6.6 in \baselineskip=18pt \parskip=6pt %opening \title{Title} \author{Author} \begin{document} \maketitle \begin{abstract}
    – user21127
    Oct 19, 2012 at 20:40
  • I can't see what you posted in the comment in the actual question.
    – abdulhaq-e
    Oct 19, 2012 at 20:43
  • 5
    This can happen when the output PDF file is locked by another application, e.g. it is open in Adobe Reader. Oct 19, 2012 at 20:54
  • You were right. The error was caused by the pdf already being open. Closing it fixed the problem. Thanks!
    – user21127
    Oct 19, 2012 at 21:07

1 Answer 1


The error message is generated by the prompt_file_name procedure in TeX.

Most likely causes:

  • The output PDF file already exists and is locked by another application, e.g. Adobe Reader (on Windows).

    • In this case, one can usually close the open document (or close the PDF viewer entirely), retype the output file name in TeX's prompt, and press ENTER to try again.
    • If this doesn't work, try deleting the PDF file in Windows Explorer, and hopefully it will tell you what application is the culprit.
    • You could also try a tool like Unlocker.

    (If you are interested in finding a PDF viewer that does not lock open documents, see this related question on superuser.)

  • Insufficient hard disk space.
  • Insufficient memory. See https://tex.stackexchange.com/a/16901/17427
  • Trying to write to a directory that doesn't exist. (This is more likely if you are writing external files through something like tikzexternalize, rather than for the main document output file)*.
  • Trying to write in a protected/unsafe location. See for example http://www.tex.ac.uk/cgi-bin/texfaq2html?label=includeother and https://tex.stackexchange.com/a/2214/17427

A couple of things to note:

  • One cannot type x at this prompt to abort. That will write on a file called x.pdf.
  • In pdflatex, pressing ENTER without retyping the filename unhelpfully writes on a file called .pdf.
  • In lualatex, pressing ENTER without retyping the filename prompts again.
  • In xelatex, this prompt doesn't occur. Instead, one seems to get the message ** ERROR ** Unable to open ... and then it exits.

*Thanks to Sextus Empiricus for pointing this one out.

  • I've deleted the pdf and it worked. Thank you
    – CroCo
    Jul 1, 2015 at 20:01
  • @cyberSingularity I came across the same problem "can't write on" in my case it was related to Tikz wanting to write in a folder (external figures) that did not exist. You might wish to add this to the solution. Dec 10, 2019 at 21:24
  • @SextusEmpiricus: Sorry for the belated action, but I've now done this. Many thanks! Jan 31, 2020 at 11:01
  • I think I found an additional cause: I got the same error because of Avast antivirus "protecting" the documents folder against MikiText or some app in the Latex editor. That happened to me when rendering RMarkdown to pdf in RStudio.
    – Pere
    Oct 26, 2020 at 17:00

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