I'd like to take pages of an existing PDF (which are simply images), and draw several boxes on each page. (The bounding boxes of words as detected by an external OCR program.)
What I've tried so far:
can use
\includepdf
(from thepdfpages
package) with option[fitpaper=true]
to make pages of the resulting PDF same as those of the original PDF.can use TikZ to draw rectangles/polygons, with coordinates specified using
current page.north west
and some arithmetic (which I got from this answer), though there are multiple problems:They end up on a separate page,
This separate page has the default (letter/A4) TeX dimensions, not those of the included PDF (though this can be set explicitly)
Here's what I have so far (using example-image-a
instead of my PDF file):
\documentclass{article}
\pagestyle{empty}
\usepackage{pdfpages}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\paperwidth=319.999bp
\paperheight=239.999bp
\pagewidth=319.999bp
\pageheight=239.999bp
\begin{document}
\includepdf[fitpaper=true]{example-image-a}%
\begin{tikzpicture}[remember picture,overlay]
\draw [line width=1mm,opacity=.25] (current page.center) circle (3cm);
\draw[red, thick] ($(current page.north west)+(102 bp,-72 bp)$) -- ($(current page.north west)+(132 bp,-72 bp)$) -- ($(current page.north west)+(132 bp,-90 bp)$) -- ($(current page.north west)+(102 bp,-90 bp)$) -- cycle;
\end{tikzpicture}%
\end{document}
Results in two pages (in the other order if I put the \includepdf
later):
\includepdf
inserts a full page and then switches to the next page. If you put your tikz code into a macro, then use can use thepagecommand
orpictuercommand
options for\includepdf
to execute this code on the same page as the included PDF. I've used this several times to remove headers and foters when PhD students want to include PDF versions of their published articles in their dissertations.