Skip to content

Instantly share code, notes, and snippets.

@janxious
Forked from mustmodify/html5.html
Created December 20, 2011 01:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janxious/1499780 to your computer and use it in GitHub Desktop.
Save janxious/1499780 to your computer and use it in GitHub Desktop.
Attempts to get DocRaptor to render inline SVG images
<!DOCTYPE html>
<html>
<head>
<title>MathML and SVG in text/html</title>
</head>
<body>
<a href="https://developer.mozilla.org/en/Code_snippets/Embedding_SVG">Source</a>
<h1>SVG in text/html</h1>
<p><svg height=86 width=90 viewBox='5 9 90 86' style='float: left;'>
<path stroke=#F53F0C stroke-width=10 fill=#F5C60C stroke-linejoin=round d='M 10,90 L 90,90 L 50,14 Z'/>
<line stroke=black stroke-width=10 stroke-linecap=round x1=50 x2=50 y1=45 y2=75 />
</svg>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink">
<body>
<a href="https://developer.mozilla.org/en/Code_snippets/Embedding_SVG">Source</a>
<p>hello</p>
<svg:svg version="1.1" baseProfile="full" width="150" height="150">
<svg:rect x="10" y="10" width="100" height="100" fill="red"/>
<svg:circle cx="50" cy="50" r="30" fill="blue"/>
</svg:svg>
<p>world</p>
</body>
</html>
require 'rubygems'
require 'doc_raptor'
def render_with_doc_raptor( html )
DocRaptor.api_key SOME_KEY
response = DocRaptor.create(:document_content => html, :document_type => :pdf, :name => 'filename.pdf', :test => true, :strict => "none")
puts "Response Code: #{response.code}"
if response.code == 200
f = File.open('public/sample.pdf', 'w')
f.puts response.to_s
f.close
puts "please check /sample.pdf"
else
puts "\n\n#{response.body}"
end
end
Dir.glob('public/svg/*.*').each do |filename|
f = File.open(filename, 'r')
puts "======================================="
puts "Trying #{filename}..."
render_with_doc_raptor( f.read )
puts "\n\n\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment