Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question
    
More general, how to mimic the PSTricks output with TikZ? –  Who is crazy first Aug 29 at 18:16
    
Never mimic others! ;-). BTW problem solved? –  Harish Kumar Aug 30 at 1:18

1 Answer 1

up vote 1 down vote accepted

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 (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

share|improve this answer
    
Are you sure no EPS generated on the fly? –  Who is crazy first Aug 29 at 18:39
    
I don't know, really. I suppose there is an intermediate .eps file that is generated, then epstopdf and pdfcrop are launched and finally the generated .pdf image is incorporated in the main file. There remains no .eps file in the aux directory. –  Bernard Aug 29 at 18:45
    
There will be no eps file. –  Herbert Aug 29 at 21:01
    
@Herbert: Didn't know that. Thanks for the information. –  Bernard Aug 29 at 21:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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