Skip to content

Instantly share code, notes, and snippets.

@wycats
Created September 10, 2008 06:07
Show Gist options
  • Save wycats/9832 to your computer and use it in GitHub Desktop.
Save wycats/9832 to your computer and use it in GitHub Desktop.
<?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">
<head>
<title>My First Document</title>
<style type="text/css"> b { color: green; } </style>
</head>
<body>
<p>
<b>Greetings Earthlings!</b>
We've come for your Java.
</p>
</body>
</html>
require "core-renderer"
require "minium"
require "itext-paulo-155"
require "java"
import org.jruby.util.IOOutputStream
import com.lowagie.text.DocumentException
import org.xhtmlrenderer.pdf.ITextRenderer
input_file = "#{File.expand_path(File.dirname(__FILE__))}/humor.html"
output_file = "firstdoc.pdf"
File.open(output_file, 'w') do |file|
renderer = ITextRenderer.new
renderer.document = "file:/#{input_file}"
renderer.layout
renderer.create_PDF(IOOutputStream.new(file))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment