请考虑以下 MWE,它将pst-barcode
在使用该包的页面上的固定位置放置一个二维码(包)textpos
:
\documentclass{article}
\usepackage{pst-barcode}
\usepackage[absolute,showboxes]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}
\textblockorigin{0mm}{0mm}
\newcommand{\insertBarcode}{
\begin{pspicture}(1in,1in)
\psbarcode{Test}{}{qrcode}
\end{pspicture}
}
\begin{document}
\begin{textblock}{75}(80,50)
Here should be a QR code:\\
\insertBarcode\\
But there is none.
\end{textblock}
\vspace*{50mm}
W/o being placed in a \texttt{texblock} environment, the QR code will show up:\\
\insertBarcode
\end{document}
如果此文档使用 XeLaTeX (MikTeX) 编译,则正常页面内容中的二维码可以正常显示。但封闭在环境中的二维码textblock
不会显示。
我收到以下警告:
MiKTeX GPL Ghostscript 9.00: Unrecoverable error, exit code 1
** WARNING ** Filtering file via command -->mgs.exe -q -dNOPAUSE -dBATCH -sPAPERSIZE=a0 -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -dAutoFilterGrayImages=false -dGrayImageFilter=/FlateEncode -dAutoFilterColorImages=false -dColorImageFilter=/FlateEncode -dUseFlateCompression=true -sOutputFile="mik56F0.tmp" "mik56EF.tmp" -c quit<-- failed.
** WARNING ** Image format conversion for PSTricks failed.
** WARNING ** Interpreting special command pst: (ps:) failed.
** WARNING ** >> at page="1" position="(226.77, 618.307)" (in PDF)
** WARNING ** >> xxx "pst: tx@Dict begin STP newpath 0.8 SLW 0 setgray gsave 0. "
使用 LaTeX -> dvi2ps -> ps2pdf,QR 码将按预期显示。
所以我的问题是:是否可以使用 XeLaTeX (MikTeX)将pst-barcode
包装中的条形码放置在环境中?textblock
我将不胜感激任何帮助。
答案1
使用pdflatex --shell-escape mainfilename.tex
或进行编译xelatex --shell-escape mainfilename.tex
。
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{temporary.tex}
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-barcode}
\begin{document}
\begin{pspicture}(1in,1in)
\psbarcode{Test}{eclevel=L width=1 height=1}{qrcode}
\end{pspicture}
\end{document}
\end{filecontents*}
\begin{filecontents*}{another.tex}
\documentclass[border=0pt,pstricks]{standalone}
\usepackage{pst-barcode}
\begin{document}
\begin{pspicture}(1in,1in)
\psbarcode{Another}{eclevel=L width=1 height=1}{qrcode}
\end{pspicture}
\end{document}
\end{filecontents*}
\def\attach#1{%
\immediate\write18{latex #1}% you can replace it with xelatex but don't forget to comment the following dvips and ps2pdf.
\immediate\write18{dvips #1}%
\immediate\write18{ps2pdf #1.ps}%
\includegraphics{#1}}
\usepackage[absolute,showboxes]{textpos}
\setlength{\TPHorizModule}{1mm}
\setlength{\TPVertModule}{1mm}
\textblockorigin{0mm}{0mm}
\usepackage{graphicx}
\begin{document}
\begin{textblock}{75}(80,50)
Here should be a QR code:
\begin{center}
\attach{temporary}
\end{center}
But there is none.
\end{textblock}
\vspace*{50mm}
W/o being placed in a \texttt{texblock} environment, the QR code will show up:\\
\attach{another}
\end{document}
答案2
看起来好像xelatex
Postscript 阻塞了,需要在发货时进行处理(它需要调用 ghostscript 来转换 ps,这在复杂情况下可能会失败)。eso-pic 也存在同样的问题。在我看来,你应该生成条形码的 pdf 文件。
tikz
您可以尝试使用(您需要使用)的外部化库xelatex --shell-escape
来自动执行此操作:
\documentclass[]{scrartcl}
\usepackage{pst-barcode}
\usepackage{tikz}
\usetikzlibrary{external}
\tikzset{external/system call={xelatex --jobname="\image"
"\texsource"}}
\tikzexternalize
\newsavebox\mybarcode
\begin{document}
some text
%\tikzset{external/force remake}
\tikzsetnextfilename{mybarcode}
\savebox\mybarcode{%
\begin{tikzpicture}
\node{\begin{pspicture}(1in,1in)
\psbarcode{Test}{}{qrcode}
\end{pspicture}};
\end{tikzpicture}}
\IfFileExists{mybarcode.pdf}{\includegraphics{mybarcode}}
\end{document}