Convert PDF documents to SVG for Inkscape (pdf2svg)
I searched and searched the web for a project that could convert PDF documents into an editable format for some free software on Linux. I use Ubuntu daily at my workplace and only use a single Windows application for accounting software via RDP / VMPlayer. I needed a way to be able to modify PDF documents and I have Inkscape with all the features I need, except a functioning PDF import filter. Inkscape uses pstoedit which doesn't extract embedded raster images and convert them for the SVG format. There is a plugin for pstoedit to convert to SVG for $50, but it caused a segfault on my machine. So no joy with a single tool to automagically convert my documents.
I spent a loooong time trying different formats from pstoedit and converting through various other software to end up with an SVG file that I can use in Inkscape with included raster images. The following is the process I used to create the best results. The steps I have used are for creating one page at a time. Some more automation could be added to make most of this work without all these steps, as well as to do each page in the PDF document automatically.
Step 1
Create a working directory for this project. You will likely be creating hundreds of files during this process and it can get messy if it's mixed in with other documents.
Step 2
Make a Level 1 Postscript file from a page in the PDF document. When extracting pages from a PDF document, pstoedit's intermediate file formats have no support for Level 2 Postscript raster images. We'll create a Level 1 Postscript file from a PDF page that pstoedit will handle correctly.
pdf2ps -f pagenum -l pagenum -dLanguageLevel=1 document.pdf page.ps
Step 3
Convert the page to the fig format. The pstoedit tool does this job decently, and creates tons of files in the process. This process creates a .fig document with all of the images in separate EPS files. The .fig document simply references the image files to be included. At this point you could use xfig to make modifications, but it would be horribly slow and difficult to work with. This process will also rasterize all text, but I'll show in a later step how to get vectors back in your document.
pstoedit -f fig page.ps page.fig
Step 4
Convert from the fig format to the SVG format. When this is done, the SVG document contains only some formatting and placement information, while referencing all of the external EPS files.
fig2dev -L svg page.fig page.svg
Step 5
Convert EPS images to PNG images for use with Inkscape. Inkscape can't import those raster EPS files, only vector EPS files (it uses pstoedit to do the conversions, so it is limited by that tool). The EPS images must be converted to an image format that Inkscape can use. I chose PNG because the format is free, standardized, and lossless. Unfortunately, there is a problem that prevents a direct conversion. When pstoedit created the EPS files with embedded raster images, the EPS file may specify an incorrect image size/formatting. This shows up as white lines that surround the raster images, and the white lines are inconsistent between the images. What must be done is to extract the raster image data from the EPS file, not using the EPS specified sizing and formatting. The way to do this is rather ugly, but it works. First, the EPS files will be converted to PDF files. Second, the tool pdfimages will extract the raster images from the PDF files. Third, the Imagemagick tool convert will conver the images to PNG files.
#!/bin/sh
mkdir tmpimages
for epsfile in *.eps
do echo "${epsfile}"
convert "${epsfile}" "${epsfile}.pdf"
pdfimages "${epsfile}.pdf" tmpimages/
convert tmpimages/* "${epsfile}.png"
rm -f "${epsfile}.pdf"
rm -f tmpimages/*
done
rm -rf tmpimages/
Step 6
Change all the references in the SVG file from .eps to .eps.png. Open your favorite text editor (or get creative with sed) and change all .eps to .eps.png.
Step 7
Add the proper attributes in the
Rabu, 12 September 2007
covert pdf jadi svg (inkscape format)
Langganan:
Posting Komentar (Atom)
2 komentar:
no need to go through all this, just download a development build of inkscape, it imports pdf and pdf-based ai very well natively, without any additional software
thanks for the comment, but just knowing lately, btw thanks again
Posting Komentar