Created
April 18, 2009 15:16
-
-
Save stepheneb/97646 to your computer and use it in GitHub Desktop.
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
# trying to print an xhtml page to a pdf | |
# using flying saucer and itext | |
# | |
# after patching the maven gem with this: http://gist.github.com/97636 | |
# install these maven jars: | |
# jruby -S gem maven bouncycastle bcmail-jdk14 136 | |
# jruby -S gem maven bouncycastle bcprov-jdk14 136 | |
# jruby -S gem maven com/lowagie itext 2.1.0 | |
# jruby -S gem maven org/xhtmlrenderer core-renderer R8pre2 | |
require 'rubygems' | |
require 'bcmail-jdk14' | |
require 'bcprov-jdk14' | |
require 'itext' | |
require 'core-renderer' | |
# Example: | |
# | |
# JavaIO::File.new("dummy.txt") | |
# | |
module JavaIO | |
include_package "java.io" | |
end | |
module JavaNET | |
include_package "java.net" | |
end | |
java_import java.net.URI | |
java_import com.lowagie.text.pdf.PdfWriter | |
java_import com.lowagie.text.Document | |
java_import com.lowagie.text.Paragraph | |
java_import com.lowagie.text.DocumentException | |
java_import org.xhtmlrenderer.pdf.ITextRenderer | |
# uri = JavaNET::URI.new('http://localhost:3000/pages/48/print') | |
# source = JavaIO::File.new(uri) | |
File.open('page.pdf', 'w') do |output| | |
renderer = ITextRenderer.new | |
renderer.setDocument('http://localhost:3000/pages/48/print') | |
renderer.layout | |
renderer.createPDF(output) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment