2

I have to overlay some texts on a PDF form. As converting the PDF form to EPS with pdftops produces unsatisfying result, I will not use PSTricks code below.

\documentclass[pstricks,border=12pt]{standalone}

\def\M{4}% columns
\def\N{4}% rows
\def\scale{1}% scale
\def\filename{example-image-a}% filename


\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\scale]{\filename}}

\addtopsstyle{gridstyle}
{
    gridcolor=yellow,
    subgridcolor=gray,
    subgriddiv=10,
    griddots=0,
    subgriddots=5,
    gridwidth=0.4pt,
    subgridwidth=0.2pt,
}

\psset
{
   xunit=0.5\dimexpr\wd\IBox/\M,
   yunit=0.5\dimexpr\ht\IBox/\N,
}

\begin{document}
\begin{pspicture}[showgrid=top](-\M,-\N)(\M,\N)
    \rput(0,0){\usebox\IBox}
    \rput[bl](1,1){This is a text.}
\end{pspicture}
\end{document}

The output I want to achieve looks like the following.

enter image description here

Instead I will use TikZ. My problem is how to set the horizontal and vertical unit in TikZ. More precisely, how to do the following in TikZ?

\psset
{
   xunit=0.5\dimexpr\wd\IBox/\M,
   yunit=0.5\dimexpr\ht\IBox/\N,
}

MWE in TikZ

\documentclass[tikz,12pt,dvipsnames,border=12pt]{standalone}

\def\M{4}% columns
\def\N{4}% rows
\def\scale{1}% scale
\def\filename{example-image-a.pdf}% filename


\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\scale]{\filename}}


\begin{document}
\begin{tikzpicture}[inner sep=0,x=0.5\wd\IBox/\M\relax,y=0.5\ht\IBox/\N\relax]
    \node (image) at (0,0) {\usebox\IBox};
    \node at (1,1) {some text goes here};
    \draw[help lines,red,step=1](-\M,-\N) grid (\M,\N);
\end{tikzpicture}
\end{document}

enter image description here

DONE! Problem solved!

1 Answers1

2

You don't have to convert pdf to ps, since pstricks code can be compiled with pdflatex: you just have to load pstricks with option pdf and launch the compiler with the --enable-write18 switch (MiKTeX) or --shell-escape (TeXLive, MacTeX). Then pstricks will launch auto-pst-pdf and you'll get a pdf image.

Code modified:

\documentclass[border=12pt]{standalone}%

\def\M{4}% columns
\def\N{4}% rows
\def\scale{1}% scale
\def\filename{example-image-a}% filename

\usepackage{graphicx}
\newsavebox\IBox
\savebox\IBox{\includegraphics[scale=\scale]{\filename}}

\usepackage[pdf]{pstricks} 

\addtopsstyle{gridstyle}
{
    gridcolor=yellow,
    subgridcolor=gray,
    subgriddiv=10,
    griddots=0,
    subgriddots=5,
    gridwidth=0.4pt,
    subgridwidth=0.2pt,
}

\psset
{
   xunit=0.5\dimexpr\wd\IBox/\M\relax,
   yunit=0.5\dimexpr\ht\IBox/\N\relax,
}

\begin{document}

\begin{pspicture}[showgrid=top](-\M,-\N)(\M,\N)
    \rput(0,0){\usebox\IBox}
    \rput[bl](1,1){This is a text.}
\end{pspicture}

\end{document}

enter image description here

Bernard
  • 271,350