【问题标题】:node-latex image rendering节点乳胶图像渲染
【发布时间】:2017-10-06 05:46:07
【问题描述】:

我正在尝试使用 LaTeX 的 graphicsx 包在模板中包含 JPEG 图像,但该包似乎没有呈现该图像。当然,我可能会省略一些内容,但我在下面包含了我的代码以供考虑。

我在 Cloud 9 中使用容器化的 Ubuntu 14.04 实例,texlive-full 包和节点 v6.10.2。

var fs = require('fs');

var input = process.argv[2];
var output = process.argv[3];
var temp = [];

fs.readFile(input, 'utf8', function (err, data) {
  if (err) throw err;
  console.log('>>> Tex file imported.');
  temp.push(data);
  var options = { 'command': 'pdflatex' };
  require('latex')(temp, options).pipe(fs.createWriteStream(output));
  console.log('>>> Tex file built.');
});

我的tex文件如下:

\documentclass{article} \usepackage{graphicx} \begin{document} 
\begin{center} \includegraphics[scale=1]{logo.jpg}
\newline \Large NOTICE
\end{center}
\sffamily Account Number: \textit{12345678} \newline
\newline MR A TEST
\newline 2 THE STREET
\newline FARNBERRY
\newline CLOUD TOWN
\newline GU15 3AA \newline
\newline Amount: 1078.52
\newline Financial Year: \textbf{2017}
\newline
\newline \small{Footer text}
\end{document}

如果我使用命令>pdflatex filename.tex 从终端编译此 tex 文件,则图像在 PDF 中呈现良好。您能帮我渲染包含的图像吗?

谢谢。

【问题讨论】:

  • 我没有发现你的错误。当您将 pdf 输出为 .tex 文件时,您的图像不显示?
  • 嗨@mtkilic 是的,当我运行节点应用程序时,包括输入文件和输出文件作为像这样>node app.js texfile.tex output.pdf 这样的参数,会创建 PDF,但不包括 logo.jpg。
  • 更有可能,您的texfile.texjpg 不在同一个文件夹中。
  • 我可以确认它们在同一个文件夹中,因为当我在同一个 tex 文件上运行终端命令 >pdflatex filename.tex 时,jpg 呈现正常。

标签: node.js latex


【解决方案1】:

这可能是乳胶运行在某个临时目录中完成并且在那里找不到图像的情况。尝试将\includegraphics 更改为具有图像的完整路径

\includegraphics[scale=1]{/full/path/to/directory/containing/logo.jpg}

【讨论】:

    【解决方案2】:

    您能否将您的.tex 文件更改为此并尝试一下?另外,如果你安装了 perl,你可以使用命令latexmk -pdf

    \documentclass{article} 
    \usepackage{graphicx} 
    \begin{document}
    \begin{figure}  
    \begin{center} 
    \includegraphics[scale=1]{logo.jpg}
    \newline \Large NOTICE
    \end{center}
    \sffamily Account Number: \textit{12345678} \newline
    \newline MR A TEST
    \newline 2 THE STREET
    \newline FARNBERRY
    \newline CLOUD TOWN
    \newline GU15 3AA \newline
    \newline Amount: 1078.52
    \newline Financial Year: \textbf{2017}
    \newline
    \newline \small{Footer text}
    \end{figure}
    \end{document}
    

    【讨论】:

    • 嗨@mtkilic 添加图形属性没有帮助。它可以从终端手动编译,但不能从 nodejs 脚本编译。我认为 npm 模块 node_latex 中可能存在错误?我想做的是创建一个概念证明,使用参数化的乳胶模板可以自动化重复文档的制作。到目前为止,如果我不包含图片,它就可以工作 :-) 感谢您的努力。
    • @MattLindsay 上周我不得不从 png 文件创建 10 个 pdf 文件以用于文档。我使用 Python 和 Latex,我将我的脚本上传到 github,也许这会对你有所帮助。 github.com/mtkilic/Python-useful-scripts/blob/master/…我对node.js不太了解,抱歉帮不上忙:/
    • 嗨@mtkilic 感谢您的回购链接,我认为这会很有用。与此同时,我已经改用 gulp-pdflatex2 npm 包,效果很好。
    • @MattLindsay 很高兴听到您发现某些东西对您有用 :)
    猜你喜欢
    • 2014-11-28
    • 2014-10-08
    • 2021-04-28
    • 1970-01-01
    • 1970-01-01
    • 2020-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多