11

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:

\documentclass[12pt]{article}
\usepackage{epsf}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{rotate}
\usepackage{endnotes}
%\usepackage{harvard}
\usepackage{vmargin}
\usepackage[nolists,noheads,tablesfirst,nomarkers]{endfloat}
\usepackage{natbib}
\bibliographystyle{apsr}

\oddsidemargin=1.0in\evensidemargin=0.in
\textheight=8.5in\textwidth=6.6 in \baselineskip=18pt \parskip=6pt

\begin{document}  % added, was missing

TEXT

\newpage \baselineskip=12pt
\doublespacing

\bibliographystyle{apsa}
\bibliography{Dissertation_Proposal}


\end{document}
Mensch
  • 65,388
user21127
  • 111

1 Answers1

26

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 https://texfaq.org/FAQ-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.

David Carlisle
  • 757,742
  • I've deleted the pdf and it worked. Thank you – CroCo Jul 01 '15 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. – Sextus Empiricus Dec 10 '19 at 21:24
  • @SextusEmpiricus: Sorry for the belated action, but I've now done this. Many thanks! – cyberSingularity Jan 31 '20 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 '20 at 17:00