2

Straight to it. Is it possible to include a docx file the same way that you would include a pdf file?

So instead of

\includepdf[pages=1-]{somepdffile.pdf}

I could just write something like:

\includedocx[pages=1-]{someMSwordfile.docx}

I know that I could just pdf the wordfile (and I do), but I get so many documents and the content change daily. It would make my process so much more efficient if I could just change the content in the wordfile and then it would correct in the main file :)

thx in advance

  • 1
    Have you had a look at automated conversion from .docx to something else, for example with pandoc? The quality of results can vary, but just a thought. And welcome to TeX.SX! – alpenwasser Jan 10 '18 at 12:39
2

If you compile your document with -shell-escape you can use the \DeclareGraphicsRule macro which allows you to set up rules to convert from any arbitrary format to a format understood by the graphicx package (in this case PDF).

You would need to find a command line application to convert from DOCX to PDF. e.g., Pandoc or perhaps something like OfficeToPDF, though I have never used it.

Then do something like this (compile with pdflatex -shell-escape):

Pandoc example

\documentclass{article}
\usepackage{pdfpages}
% add new rule to convert docx to pdf
\DeclareGraphicsRule{.docx}{pdf}{.pdf}{`pandoc #1 -o \noexpand\OutputFile}
\begin{document}
\includepdf[pages=-]{mydocument.docx}
\end{document}

OfficeToPDF example

\documentclass{article}
\usepackage{pdfpages}
% add new rule to convert docx to pdf
\DeclareGraphicsRule{.docx}{pdf}{.pdf}{`officetopdf #1 \noexpand\OutputFile}
\begin{document}
\includepdf[pages=-]{mydocument.docx}
\end{document}
  • Better remove \pagestyle{empty}. What if the document contains other content? The included pages will get this anyhow. Can you explain why you use \epstopdfDeclareGraphicsRule rather than \DeclareGraphicsRule? – cfr Jan 11 '18 at 3:32
  • @cfr. Oh! As I look a little closer, I see that the graphicx package loads epstopdf automatically if -shell-escape is used. So, you're right, it can be simplified! – David Purton Jan 11 '18 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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