-
-
Save janxious/1499780 to your computer and use it in GitHub Desktop.
Attempts to get DocRaptor to render inline SVG images
This file contains hidden or 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 'rubygems' | |
require 'doc_raptor' | |
def render_with_doc_raptor( html ) | |
DocRaptor.api_key SOME_KEY_HERE | |
response = DocRaptor.create(:document_content => html, :document_type => :pdf, :name => 'filename.pdf', :test => true, 'doc[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 | |
# Example from https://developer.mozilla.org/en/Code_snippets/Embedding_SVG | |
MOZILLA_XHTML_EXAMPLE = %| | |
<?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> | |
<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>| | |
render_with_doc_raptor( MOZILLA_XHTML_EXAMPLE ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment