Created
March 6, 2012 19:28
-
-
Save billdueber/1988475 to your computer and use it in GitHub Desktop.
pdf list of links
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
load '/path/to/itextpdf-5.2.0.jar' | |
IText = Java::com.itextpdf.text # same some typing | |
doc = IText::Document.new(IText::PageSize::LETTER, 50, 50, 50, 50) | |
# AddAuthor and addSubject seem to not work, at least for viewing in Preview | |
doc.addAuthor "Bill Dueber" | |
doc.addSubject "Why are we requiring PDF???" | |
# Put it somewhere | |
pdf = IText.pdf::PdfWriter.getInstance(doc, File.open('links.pdf', 'w').to_outputstream); | |
# Get a font: bold, underlined, just like the ugly regular old web | |
font = IText::Font.new(IText::Font::FontFamily::HELVETICA, 12, IText::Font::UNDERLINE, IText::BaseColor.new(0, 0, 255)) | |
# Once we open the doc, we can't muck with the metadata anymore (so says the javadocs, anyway) | |
doc.open | |
# What are we putting in here? | |
links = [ | |
['lib', 'http://www.lib.umich.edu/'], | |
['billdueber', 'http://robotlibrarian.billdueber.com/'] | |
] | |
# Stick them all into the doc | |
links.each do |l| | |
text, href = *l | |
chunk = IText::Chunk.new(text, font) | |
chunk.setAnchor href | |
doc.add IText::Paragraph.new(chunk) | |
end | |
# Close it off. It's now in links.pdf | |
doc.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment