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

Content deleted Content added
Extracting part of a PDF: making instructions clearer
 
(12 intermediate revisions by 7 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 PDF2SVGdvisvgm ====
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, <code>dvisvgm</code> seems to do a better job, and even results in smaller SVGs in some cases. <code>dvisvgm</code> 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 http://www.cityinthesky.co.uk/opensource/pdf2svg/ and compile it. If you are using Linux or FreeBSD or MacPorts, PDF2SVG might also be installable via the package installer.
#Convert the PDF with <ttcode>pdf2svgdvisvgm --pdf --output=file.pdfsvg file.svgpdf</ttcode>
 
If you want to make your SVG smaller, you can add <code>--optimize=all</code> to <code>dvisvgm</code> 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.
 
==== Convert a multiple page pdf to svg ====
Inkscape currently doesn't support extracting multiple pages of a .pdf to svg.
 
===== Conversion with pdf2svg =====
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:
 
#Get PDF2SVGpdf2svg from [[Github]] [https://github.com/dawbarton/pdf2svg here], additional info [http://www.cityinthesky.co.uk/opensource/pdf2svg/ and compile ithere]. If you are using Windows, Linux or FreeBSD or MacPortsOSX, PDF2SVG might alsopdf2svg beis 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''': Binaries can be downloaded from [https://github.com/jalios/pdf2svg-windows here].
 
To convert a pdf:
#Convert the first page of a PDF file with <code>pdf2svg file.pdf file.svg</code>. To extract all pages of a multiple-page PDF use <code>pdf2svg file.pdf output-%02d.svg all</code>. 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.''
 
===Extracting part of a PDF===
Line 44 ⟶ 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
Line 90 ⟶ 110:
===For interest===
 
Inkscape is [[FOSS]]| free and open source software]]. For additional comments see this discussion:
*[[Wikipedia:Graphic Lab/Images to improve#Image:APISmap1.pdf]]
 
Line 101 ⟶ 121:
:Good Q. An example of a (vector) PDF map ready for conversion to SVG is [[:Image:APISmap1.pdf|this]]. PDFs can contain practically any type of information, the most common ones being text, raster images (ordinary images like bitmaps) and vector graphics. The vector information has to be coded into the PDF as such. Quite a lot of organizations publish vector information (like maps) this way, so it's handy to be able to convert ''out'' of PDF, but putting things into PDFs is pointless for us, it doesn't change the type. If you need a raster image converted, best to [[Wikipedia:Graphic Lab/Images to improve|speak to a WikiGraphist]] - [[User:MissMJ|MissMJ]] is the resident pro and very approachable.
 
[[Category:Wikipedia GraphicGraphics Lab|PDF conversion to SVG]]