การวาดภาพพื้นหลัง
ฉันต้องการใช้หน้าของ PDF ที่มีอยู่ (ซึ่งเป็นเพียงภาพ) และวาดหลาย ๆ กล่องในแต่ละหน้า (กรอบของคำที่ถูกตรวจพบโดยโปรแกรม OCR ภายนอก)
สิ่งที่ฉันได้ลองแล้ว:
สามารถใช้
\includepdf(จากpdfpagesแพ็คเกจ) พร้อมตัวเลือก[fitpaper=true]ในการสร้างหน้าของ PDF ที่เป็นผลลัพธ์เหมือนกับ PDF ต้นฉบับสามารถใช้ TikZ เพื่อวาดรูปสี่เหลี่ยม / รูปหลายเหลี่ยมพร้อมพิกัดที่ระบุโดยใช้
current page.north westและเลขคณิต (ซึ่งฉันได้จากคำตอบนี้ ) แม้ว่าจะมีปัญหาหลายประการ:พวกเขาจบลงในหน้าแยกกัน
หน้าแยกนี้มีขนาด TeX เริ่มต้น (letter / A4) ไม่ใช่ของ PDF ที่รวมอยู่ด้วย (แม้ว่าจะสามารถตั้งค่าได้อย่างชัดเจน)
นี่คือสิ่งที่ฉันมีอยู่ (ใช้example-image-aแทนไฟล์ PDF ของฉัน):
\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}
ผลลัพธ์ในสองหน้า (ในลำดับอื่นถ้าฉันใส่ใน\includepdfภายหลัง):
คำตอบ
ใช้eso-pic's \AddToShipoutPictureFG*หนึ่งสามารถบรรลุนี้ (ผมได้รับข้อผิดพลาดที่ไม่ได้กำหนดลำดับการควบคุมใน\pagewidthและ\pageheightและแสดงความคิดเห็นพวกเขา):
\documentclass{article}
\pagestyle{empty}
\usepackage{eso-pic}
\usepackage{pdfpages}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\paperwidth=319.999bp
\paperheight=239.999bp
%\pagewidth=319.999bp
%\pageheight=239.999bp
\begin{document}
\AddToShipoutPictureFG*{%
\put(0,0){\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}%
}}%
\includepdf[fitpaper=true]{example-image-a}%
\end{document}
ใช้ตัวเลือกpicturecommandของ\includepdfและนำของคุณtikzpicture-stuff ในมี:
\documentclass{article}
\usepackage{pdfpages}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}
\includepdf[
fitpaper=true,
picturecommand={%
\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}}
]{example-image-a}
\end{document}
โปรดทราบว่าpicturecommandตัวมันเองใช้\AddToShipoutPictureจากeso-picแพ็คเกจดังนั้นนี่คือสถานที่ที่เหมาะสมในการวางสิ่งที่คุณวาด
ตามวิธีนี้ :
\documentclass[a4paper]{article}
\usepackage{pdfpages}
\usepackage{tikz}
\begin{document}
\includepdf[
fitpaper=true,
picturecommand={%
\begin{tikzpicture}[remember picture,overlay,
x={(current page.south east)},y={(current page.north west)}
]
% Help CoSy
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=south] at (\x/10,0) {0.\x}; }
\foreach \y in {1,...,9} { \node [anchor=west] at (0,\y/10) {0.\y}; }
% Stuff
\draw[red, thick, rounded corners] (0.1,0.9) rectangle (0.25,0.75);
\draw [cyan, very thick] (0.5,0.5) circle[radius=2cm];
\draw[yellow, line width=4mm, ->] (0.7,0.1) -- (0.9,0.3);
\draw [blue, very thick] (current page.center) circle[radius=3cm];
\end{tikzpicture}}
]{example-image-a.pdf}
\end{document}