Created
June 27, 2016 17:25
-
-
Save nikkomiu/f6263e1a6a3ec67599e50c33a00e7bc5 to your computer and use it in GitHub Desktop.
Ruby Convert SVG to PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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