I am writing an academic article and I saved all my figures in svg format. Then I converted (after a few cosmetic stuffs) it to pdf_tex/pdf so that they fit the paper . The problem is that my editor asks me the figures in pdf format. How can I convert all my pdf_tex/pdf files in selftcontained pdf figures so that the rendering when including the generated pdf will be the same ?
[Tex/LaTex] create pdf figures from pdf_tex and pdf files
graphicspdf
Related Solutions
Page 2 of CTAN/info/svg-inkscape/InkscapePDFLaTeX.pdf suggests the alternative use of the import
package. Assuming all three files (.PDF
, .PDF_TEX
, and .SVG
) are in the same folder as chapter1.tex
, then all you need is
\documentclass{article}
\usepackage{graphicx,import}
\begin{document}
\input{chapter1/chapter1}
\end{document}
and
\chapter{test chapter}
\begin{figure}[h!]\centering
\import{chapter1/}{peeling_flow_constant_width.pdf_tex}
\end{figure}
The following code will extract all graphics and floats. To prove it, I load the extracted objects again with \includepdf
(see the animation).
% this file name is extractor.tex
% compile it with pdflatex -shell-escape extractor
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{template.tex}
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\usepackage[active,tightpage,\placeholder]{preview}
%\PreviewEnvironment{\placeholder}
\PreviewBorder=12pt\relax
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
\end{filecontents*}
\usepackage{pgffor,pdfpages}
\begin{document}
\foreach \x in{graphics,floats}{%
\immediate\write18{pdflatex -jobname=template-\x\space "\def\noexpand\placeholder{\x} \noexpand\input{template}"}%
\includepdf[pages=-]{template-\x}%
}
\end{document}
The code above just simulates your scenario. To apply it in your real scenario, do the following.
Step 1
Assume that your input file is as follows.
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
Step 2
Insert
\usepackage[active,tightpage,graphics]{preview}
\PreviewBorder=12pt\relax
in your input file. So your input file becomes as follows.
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\usepackage[active,tightpage,graphics]{preview}
\PreviewBorder=12pt\relax
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
Save this input file as anyfilename-graphics.tex
Step 3
Invoke pdflatex anyfilename-graphics
to obtain a PDF file containing all extracted graphics.
Step 4
Repeat Step 2 but replace graphics
with floats
, save the file as anyfilename-floats.tex
. Now compile with pdflatex anyfilename-floats
to get a PDF file containing all extracted floats (figure or table).
Step 5
Done!
Best Answer
You can try
EDIT:
To address the problem with objects outside the pdf, you could define the size of the resulting pdf. But I am afraid, the numbers have to be adjusted for each figure.
SECOND EDIT:
In fact
standalone
itself is capable of adding desired margins. This can be done with