Skip to content

Instantly share code, notes, and snippets.

@Saabbir
Last active January 19, 2021 07:39
Show Gist options
  • Save Saabbir/7565eea67ef71001622b70462f3c24f1 to your computer and use it in GitHub Desktop.
Save Saabbir/7565eea67ef71001622b70462f3c24f1 to your computer and use it in GitHub Desktop.

How to extract vector graphics (SVG images) from a PDF file

What we need to do:

  1. Enable WSL on Windows 10.
  2. Install Ubuntu (latest version) on WSL from the Windows Store.
  3. Install poppler-utils Command-line tool on WSL.
  4. Convert PDF file to an SVG file using pdftocairo tool, contained into poppler-utils.
  5. Use Inkspace to ungroup, copy, paste the desired vector graphic to a new SVG file.
  6. Use Illustrator to export that graphic as an SVG image.

How to install poppler-utils on WSL

Open Ubuntu command-line, and run the following commands:

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt install poppler-utils

Now poppler-utils should have been installed successfully on WSL. To check the currently installed version of poppler-utils run pdftocairo -v in the Ubuntu Command-line.

If it returns a version, Congratulations! you have successfully installed poppler-utils on WSL.

Now, copy the desired PDF file to the WSL directory to convert it into an SVG file. To open the current WSL directory in the Windows Explorer, run explorer.exe . from the Ubuntu Command-line.

After that, run the following command from the Ubuntu Command-line to convert a PDF file into an SVG file.

# syntax
pdftocairo [options] <PDF-file> [<output-file>]

# example
pdftocairo -svg input-file-name.pdf output-file-name.svg

The above example command should create a output-file-name.svg file from input-file-name.pdf file.

After that:

  • Open the newly created SVG file into the Inkspace program.
  • Right-click the vector graphic and click "Ungroup" from the pop-up menu. This splits the image up into its vector components so you can extract the parts you require.
  • Click and drag your cursor over the part of the image you want to extract. Once you release the mouse button, the selected image will have bounding boxes with scale/rotation handles around it.
  • Right-click the selected image and click "Copy." Click "File," then "New," then "Default" and click "Edit" and "Paste" to extract the vector graphic from the SVG file to the new document.
  • Click and drag the vector image into position on the blank page. Use the scale handles around the image to enlarge it to the dimensions that you prefer.
  • Click "File" and "Save" and type a name for the vector file. Select "SVG" as the "Save as type" to store the file in a vector format.
  • After that, use Adobe Illustrator to export that graphic as an SVG file.

Reference links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment