Wikipedia:Graphics Lab/Resources/PDF conversion to SVG: Difference between revisions

Content deleted Content added
Conversion with pdf2svg: adding more detail
Extracting part of a PDF: making instructions clearer
 
(5 intermediate revisions by 4 users not shown)
Line 14:
See also [[commons:Category:PDF maps]].
 
=== How to convert a PDF to SVG ===
 
==== Convert a single page of a pdf to .svg ====
====Conversion with Inkscape====
 
===== Conversion with Inkscape =====
 
#Download [[Inkscape]] from [https://www.inkscape.org www.inkscape.org] (version 0.46 and above)
Line 32 ⟶ 34:
#Upload the SVG to Wikimedia Commons and tag it with {{Tld|Extracted with Inkscape|v}}
 
''Note: Some versions of Inkscape do not have PDF support compiled in; also, text importing does not always produce satisfactory results in Inkscape.''
====Conversion with pdf2svg====
 
==== Conversion with dvisvgm ====
Some versions of Inkscape do not have PDF support compiled in; also, text importing does not always produce satisfactory results in Inkscape. In that case, you might try performing the conversion with the pdf2svg command line tool. (It requires that [[Poppler (software)|Poppler]], [[cairo (graphics)|Cairo]], and [[X_Window_System|X]] are installed on your system.)
Large and complex PDFs such as some of the maps from the USGS are sometimes difficult for PDF2SVG or Inkscape to convert. For PDFs that are not able to be converted by these tools, <ttcode>dvisvgm</ttcode> seems to do a better job, and even results in smaller SVGs in some cases. <ttcode>dvisvgm</ttcode> is often distributed as part of TexLive, and instructions for obtaining it are available on [https://dvisvgm.de/ their website].
 
To convert a PDF to SVG with dvisvgm, run the following command:
#Get pdf2svg from [[Github]] [https://github.com/dawbarton/pdf2svg here], additional info [http://www.cityinthesky.co.uk/opensource/pdf2svg/ here]. If you are using Windows, Linux or FreeBSD or OSX, pdf2svg is installable via the package installer.
<ttcode>dvisvgm --pdf --output=file.svg file.pdf</ttcode>
## '''Ubuntu''': use <tt>sudo apt-get update -y</tt> followed by <tt>sudo apt-get install -y pdf2svg</tt>
## '''Windows''' binaries can be downloaded from [https://github.com/jalios/pdf2svg-windows here].
#Convert the first page of a PDF file with <tt>pdf2svg file.pdf file.svg</tt>. To extract all pages of a multiple-page PDF use <tt>pdf2svg file.pdf output-%02d.svg all</tt>. This generates output files ''output-00.svg'', ''output-01.svg'', etc. where the pattern "%02d" is replaced by the respective two-digit page numbers.
#If necessary use Inkscape to edit the resulting SVG.
 
If you want to make your SVG smaller, you can add <ttcode>--optimize=all</ttcode> to <ttcode>dvisvgm</ttcode> and additionally run the resulting SVG through [https://github.com/RazrFalcon/svgcleaner svgcleaner] to further shrink the file without perceptual quality loss. The main drawback is that <code>dvisvgm</code> cannot embed fonts from PDF, it can only convert them to paths.
====Conversion with dvisvgm====
 
==== Convert a multiple page pdf to svg ====
Large and complex PDFs such as some of the maps from the USGS are sometimes difficult for PDF2SVG or Inkscape to convert. For PDFs that are not able to be converted by these tools, <tt>dvisvgm</tt> seems to do a better job, and even results in smaller SVGs in some cases. <tt>dvisvgm</tt> is often distributed as part of TexLive, and instructions for obtaining it are available on [https://dvisvgm.de/ their website].
Inkscape currently doesn't support extracting multiple pages of a .pdf to svg.
 
===== Conversion with pdf2svg =====
To convert a PDF to SVG with dvisvgm, run the following command:
pdf2svg is a command line tool which allows you to extract multiple or all pages of a pdf to a series of .svg files. To install:
<tt>dvisvgm --pdf --output=file.svg file.pdf</tt>
 
#Get pdf2svg from [[Github]] [https://github.com/dawbarton/pdf2svg here], additional info [http://www.cityinthesky.co.uk/opensource/pdf2svg/ here]. If you are using Windows, Linux or FreeBSD or OSX, pdf2svg is installable via the package installer.
## '''Ubuntu/Debian/Chromebook with Linux support''': Use <code>sudo apt-get update</code> followed by <code>sudo apt-get install pdf2svg</code> in the command line. (''Note: [https://askubuntu.com/questions/1230902/what-is-the-correct-way-to-create-a-persistent-ubuntu-20-04-usb you can run a 'persistent' version of Ubuntu on a USB stick without installing it on your hard drive]'').
## '''Windows''': binariesBinaries can be downloaded from [https://github.com/jalios/pdf2svg-windows here].
 
To convert a pdf:
#Convert the first page of a PDF file with <ttcode>pdf2svg file.pdf file.svg</ttcode>. To extract all pages of a multiple-page PDF use <ttcode>pdf2svg file.pdf output-%02d.svg all</ttcode>. This generates output files ''output-00.svg'', ''output-01.svg'', etc. where the pattern "%02d" is replaced by the respective two-digit page numbers.
#If necessary use Inkscape to edit the resulting SVG.
 
''Note: It requires that [[Poppler (software)|Poppler]], [[cairo (graphics)|Cairo]], and [[X_Window_System|X]] are installed on your system.''
If you want to make your SVG smaller, you can add <tt>--optimize=all</tt> to <tt>dvisvgm</tt> and additionally run the resulting SVG through [https://github.com/RazrFalcon/svgcleaner svgcleaner] to further shrink the file without perceptual quality loss.
 
===Extracting part of a PDF===
Line 55 ⟶ 64:
Inkscape often produces [[#BadSVG|unreasonably large]] SVG files from PDFs, especially if you are only trying to use a small part of the PDF (such as a single vector image or logo on a larger page). In order to reduce the size of the resulting image, it is almost always better to copy and paste the portion of interest into a new Inkscape document rather than try to delete the unwanted content and crop the canvas. To do this:
 
#Open the PDF in Inkscape asand describedchose abovethe page you want to extract the graphic from
#Delete any backgrounds or surrounding text/images near the image you are trying to extract
#Select the entire image you are trying to extract by holding the SHIFT key and dragging