Reads an EPS/Illustrator/PDF file and generates code for rendering in Prawn the vector content of that file
Ruby
Switch branches/tags
Nothing to show
Pull request Compare This branch is 3 commits ahead, 5 commits behind Bluejade:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bin
examples
lib
spec
LICENCE
README.rdoc

README.rdoc

PrawnVectorImport: import Adobe Illustrator / EPS / PDF Vector Shapes for Use with Prawn

PrawnVectorImport can import vector shapes, lines, stroke and fill color, and dash settings from PDF documents and PDF compatible Illustrator files.

Motivation

I needed to include logos into PDF documents generated by Prawn. You could also use this to embed other pre-rendered vector graphics.

Usage

PrawnVectorImport requires the PDF::Reader gem:

$ gem install pdf-reader

First, generate your Adobe Illustrator / PDF file. If using Illustrator, when you save, save as PDF compatible, uncompressed. NOTE: if the graphic includes text that you want imported, convert that text to outlines (Type > Create Outlines) before importing it.

Use PrawnVectorImport from the command line to generate a ruby file:

$ cd PrawnVectorImport/
$ ruby bin/import_vectors.rb path_to_ai_or_pdf_file > path_to_file_you_want_to_create

The resulting ruby file is an extension to the Prawn::Graphics module. It contains a method named my_vector_graphics that takes three optional parameters. Rename that method (and the file) to a name that corresponds to your graphics content, then include the file in your project and call the method on a Prawn document object.

If you have Prawn installed in the same directory as PrawnVectorImport, then here is an easy way to test the results:

$ cd PrawnVectorImport/
$ ruby bin/import_vectors.rb ./examples/vector_import_test.ai > ./examples/my_vector_graphics.rb
$ cp examples/my_vector_graphics.rb ../prawn/examples/
$ cp examples/prawn_vector_import.rb ../prawn/examples/
$ cd ../prawn
$ ruby examples/prawn_vector_import.rb

See the ./examples/prawn_vector_import.rb file for an example of how the generated method is called.

Hints

  • Make certain that all of the artwork you want to appear is contained within the artboard.

  • Positioning is based on the lower left corner of the Illustrator document and from the lower left corner of the Prawn bounds.

  • If you don't see anything, and your document is in CMYK, change the Illustrator document and then all artwork to RGB.

  • Delete hidden layers. Artwork that is present, but not visible, may be drawn, creating a larger ruby file and final PDF unnecessarily.

  • Again, convert type to outlines prior to importing if you want the text to appear.

Limitations

It's pretty basic right now. I know it doesn't yet handle transparency. However, at least when an Illustrator document is saved as PDF compatible (I'm using Illustrator CS3), objects may be rotated, and Illustrator even cuts off objects that extend beyond the artboard (see examples/prawn_vector_import.pdf and the original examples/vector_import_test.ai).