Skip to content

Instantly share code, notes, and snippets.

@nikkomiu
Created June 27, 2016 17:25
Show Gist options
  • Save nikkomiu/f6263e1a6a3ec67599e50c33a00e7bc5 to your computer and use it in GitHub Desktop.
Save nikkomiu/f6263e1a6a3ec67599e50c33a00e7bc5 to your computer and use it in GitHub Desktop.
Ruby Convert SVG to PDF
require 'fileutils'
require 'pathname'
#############################################
# This assumes your directory structure is: #
#############################################
# - icons #
# - icon_set #
# - svg #
# - icon_set2 #
# - svg #
# - convert.rb #
#############################################
icons_folder = 'icons'
icons_path = File.join(Dir.pwd, icons_folder)
Dir[File.join(svg_path, '**/*.svg')].each do |svg|
pdf_svg_folder = /#{icons_folder}\/([^\/]*\/[^.]*)/.match(svg)[1].gsub('svg', 'pdf')
pdf_location = File.join(pdf_path, "#{pdf_svg_folder}.pdf")
# Create PDF location
FileUtils.mkdir_p pdf_location unless File.directory?(File.dirname(pdf_location))
puts "Converting #{Pathname.new(svg).basename.to_s}..."
system("rsvg-convert -f pdf -o #{pdf_location} #{svg}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment