Wikipedia:Graphics Lab/Resources/PDF conversion to SVG: Difference between revisions
Content deleted Content added
→Conversion with Inkscape: Optimize output, and don't embed rasters |
Actually, maybe optimized isn't the best choice as it can corrupt images. Add section on using just part of a PDF. |
||
Line 20:
#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
#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
#''Before uploading'' you may assure its W3C-validity, with tool {{Plainlinks|http://tools.wmflabs.org/svgcheck/|SVG-check}}
Line 38 ⟶ 37:
#Convert the PDF with <tt>pdf2svg file.pdf file.svg</tt>
#If necessary use Inkscape to edit the resulting SVG.
===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 as described above
#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:Hersheypark_Logo.svg]], which was reduced 99% from 623kB to 7kB.
===If you can't see the SVG on Wikipedia/Commons===
Line 54 ⟶ 73:
===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 65 ⟶ 84:
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===
|