2

I have a PDF file that contains a vectorial image generated with PdfPages (from matplotlib.backends.backend_pdf import PdfPages). Now I don't have anymore the script to generate this file, and since I would like to modify this image and incorporate into a tex file, I would like to revert this PDF to a tikz file. It is not important that the tikz representation is precise, but what is important is that contains the main informations (like the position of the lines, since the image it is a plot of a function).

4

I think there is not one way but here is my try:

  1. I used the answer from M4rtini to generate a PDF file which includes some plots generated with PdfPages.

  2. Then I used pdf2svg to convert the PDF file to an SVG file. The exact command for doing that is pdf2svg test.pdf test1.svg 1

  3. Open the SVG File with an editor and find the path corresponding to the curve. In that example the path is given by <path style="fill:none;stroke-width:1.5;stroke-linecap:square;stroke-linejoin:round;stroke:rgb(12.156677%,46.665955%,70.587158%);stroke-opacity:1;stroke-miterlimit:10;" d="M 73.832031 50.111719 L 109.90625 53.1 L 145.976562 62.057031 L 182.050781 76.990625 L 218.125 97.896875 L 254.195312 124.779688 L 290.269531 157.63125 L 326.34375 196.459375 L 362.414062 241.260156 L 398.488281 292.033594 " transform="matrix(1,0,0,-1,0,345.6)"/>

  4. Create TEX file with an pgfplots environment and copy the coordinates into it.

  5. Use x and y filter to scale the extrapolated coordinates appropriately.

For the example the final result is

\documentclass[]{article}

\usepackage{tikz,pgfplots}
\pgfplotsset{width=7cm,compat=1.12}

\begin{document}
\begin{tikzpicture}
  \begin{axis}
    \addplot[blue,
    x filter/.code={\pgfmathparse{(#1-73.832031)/(109.90625-73.832031)}\pgfmathresult},
    y filter/.code={\pgfmathparse{(#1-50.111719)/(53.1-50.111719)}\pgfmathresult}] coordinates {
      (73.832031,50.111719)
      (109.90625,53.1)
      (145.976562,62.057031)
      (182.050781,76.990625)
      (218.125,97.896875)
      (254.195312,124.779688)
      (290.269531,157.63125)
      (326.34375,196.459375)
      (362.414062,241.260156)
      (398.488281,292.033594) };
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • Sorry, I accidentally committed the answer during writing. – hzhr Jun 10 '17 at 12:23
  • Ah, now this is a useful looking answer :) – Dai Bowen Jun 10 '17 at 12:25
  • 2
    Another useful way might be to use svg2tikz. – hzhr Jun 10 '17 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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