Wikipedia:Graphics Lab/Resources/PDF conversion to SVG: Difference between revisions
Content deleted Content added
m 2 more steps |
→Extracting part of a PDF: making instructions clearer |
||
(22 intermediate revisions by 13 users not shown) | |||
Line 1:
{{Wikipedia how to|WP:PDFTOSVG}}
Please see [[commons:Category:PDF maps]]. ▼
Before learning how to convert PDF images to SVG images it may be useful to learn how to extract images from PDF documents and create PNG, GIF, and JPG images. By using Adobe Reader many images in PDF documents can be right-clicked, copied, and then pasted into any image editor. A popular, free image editor good for beginners using [[Microsoft Windows]] is [[IrfanView]] (if you use [[GNU/Linux]] you may have [[
This is a tutorial in various formats. Some parts are in question-and-answer format, as in FAQs. Parts of this were copied and adapted from this discussion: ▼
*[[Wikipedia talk:WikiProject Maps#PDF map conversion to SVG]]▼
▲Before learning how to convert PDF images to SVG images it may be useful to learn how to extract images from PDF documents and create PNG, GIF, and JPG images. By using Adobe Reader many images in PDF documents can be right-clicked, copied, and then pasted into any image editor. A popular, free image editor good for beginners using [[Microsoft Windows]] is [[IrfanView]] (if you use [[GNU/Linux]] you may have [[Gimp]] in your distribution). Launch it and paste the image into it. Then use the image editor to save the image in any format. You can also select almost any area of a PDF document with Adobe Reader's cropping and selection tools, and then copy that selected area by right-clicking it. Then paste it into any image editor for conversion to other image formats. The PrintScreen key on your keyboard is a good last resort, too. Click that key, and then open an image editor and click "paste" (usually in the edit menu). Finally, [[Wikipedia:Graphic Lab/Image workshop]] can create, extract, or edit almost any image. Just leave a request for help or advice there.
Now here is some info on how to convert PDF image to SVG images. This page covers conversion using free tools. To convert using [[Adobe Illustrator]] go to the following two pages:
Line 10 ⟶ 7:
*[[Wikipedia:Graphic Lab/Images to improve/Archive/Jul 2008#Image:APISmap1.pdf]]
It takes only a few seconds to convert a [[PDF]] to an [[SVG]], using nothing but [[FOSS|free]] software. Go [[free/libre/open-source software|open source and free software]]! This tutorial assumes familiarity with installing programs and downloading, saving, opening and uploading files.
▲This is a tutorial in various formats. Some parts are in question-and-answer format, as in FAQs. Parts of this were copied and adapted from this discussion:
===How to convert a PDF to SVG===▼
▲*[[Wikipedia talk:WikiProject Maps/Archive 5#PDF map conversion to SVG]]
▲=== How to convert a PDF to SVG ===
==== Convert a single page of a pdf to .svg ====
===== Conversion with Inkscape =====
#Download [[Inkscape]] from [
#Download the PDF you want to convert
#Run Inkscape
#Open the PDF file you want convert in Inkscape (not Acrobat)
#
#Wait a little while as Inkscape converts it
#Click ''File>Save As..''
#Under ''Save as type:'', choose "Plain SVG (*.svg)"
#Click ''Save'' in the bottom right corner
#Done! You now have an SVG file with the same name as the PDF, but with the .svg extension
Line 29 ⟶ 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====▼
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.▼
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
## '''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===
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 and chose the 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
#If your selection has multiple boxes that appear when selected, right click and choose ''group''
#Use CTRL+C or ''Edit>Copy'' to copy the image
#Use CTRL+N or ''File>New'' to create a new document
#Use CTRL+V or ''Edit>Paste'' to paste your image into the new document
#Use the ''X'' and ''Y'' text boxes in the toolbar to position your image on the page. If your image has a transparent background, it is recommended to leave a 2px-10px margin (for example, you might want to set both values to "2"), otherwise set both to "0"
#Press CTRL+SHIFT+D or go to ''File>Document Properties...'''
#In the ''Custom size'' box, click ''Resize page to content...''
#If you are leaving a margin around your image, set the units to "px", and set the four margin boxes to the margin you chose earlier
#Click ''Resize page to drawing or selection''
#Save your file as a "Plain SVG" and test and upload as described above
Copying and pasting into a new document can reduce the file size by a large amount, such as in [[:File:LYNX_transportation_logo.svg]], which was reduced 99% from 1.22MB to 5kB.
===If you can't see the SVG on Wikipedia/Commons===
Line 52 ⟶ 95:
===Warning===
{{anchor|BadSVG}}
Some PDFs create very "bad" SVG files when converted automatically. A "bad" SVG can be identified because it will convert slowly (more than 5 seconds), it will be very large for an SVG (over 500kB-1MB) and it will render very slowly on WP - there is a long wait while the text and other images on the page are loaded, but the SVG image does not show up. Bad SVGs put a lot of strain on the Wiki servers. If you suspect you have a "bad" file, go to a Wikigraphist for a manual conversion. These will almost always be ''much'' better than the automated versions in terms of being smaller, better drawn and easier to translate because the text is created properly.
===Images in PDFs===
Line 63 ⟶ 106:
You can tell that a graphic is a raster image in Inkscape 0.47 if after selecting the graphic and choosing Object > Ungroup, you cannot select individual elements. Also, when you click the graphic Inkscape's status bar will show "Image" and its context menu will have an Image Properties item.
If the raster graphic is the only element you want from the PDF, there is no point in saving the file as SVG—it isn't a Scalable Vector Graphic.
However, Inkscape can give you an exact lossless copy of the original image from the PDF at its original size in pixels if you don't uncheck ''Embed images'' when opening the PDF. One way to do so is to use Extensions > Images > Extract Image... Another is to save as SVG, view the SVG in Firefox, right-click on the image in the SVG, choose View Image from the context menu, then use Firefox's File > Save As... to save the image as a [[Portable Network Graphics|PNG]] file.
===For interest===
Inkscape is [[FOSS
*[[Wikipedia:Graphic Lab/Images to improve#Image:APISmap1.pdf]]
Line 78 ⟶ 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
|