[macruby-changes] [254] MacRuby/trunk/sample-macruby/Scripts/pdf2tiff.rb
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 5 21:59:37 PDT 2008
Revision: 254
http://trac.macosforge.org/projects/ruby/changeset/254
Author: lsansonetti at apple.com
Date: 2008-06-05 21:59:36 -0700 (Thu, 05 Jun 2008)
Log Message:
-----------
new sample code, pdf2tiff.rb, ported from RubyCocoa
Added Paths:
-----------
MacRuby/trunk/sample-macruby/Scripts/pdf2tiff.rb
Added: MacRuby/trunk/sample-macruby/Scripts/pdf2tiff.rb
===================================================================
--- MacRuby/trunk/sample-macruby/Scripts/pdf2tiff.rb (rev 0)
+++ MacRuby/trunk/sample-macruby/Scripts/pdf2tiff.rb 2008-06-06 04:59:36 UTC (rev 254)
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+#
+# pdf2tiff.rb
+#
+# Convert a PDF document into a series of TIFF images
+#
+# Created by Ernest Prabhakar. Copyright 2007 Apple, Inc. All Rights Reserved
+# Ported to MacRuby by Laurent Sansonetti.
+#
+
+framework 'Quartz'
+
+unless ARGV.size >= 1
+ $stderr.puts "Usage: #{__FILE__} [file1.pdf] [file2.pdf] ..."
+ exit 1
+end
+
+NSApplication.sharedApplication
+
+ARGV.each do |path|
+ url = NSURL.fileURLWithPath path
+ file = path.split("/")[-1]
+ root = file.split(".")[0]
+
+ pdfdoc = PDFDocument.alloc.initWithURL url
+
+ pdfdoc.pageCount.times do |i|
+ page = pdfdoc.pageAtIndex i
+ pdfdata = page.dataRepresentation
+ image = NSImage.alloc.initWithData pdfdata
+ tiffdata = image.TIFFRepresentation
+ outfile = "#{root}_#{i}.tiff"
+ puts "Writing #{page.description} to #{outfile} for #{path}"
+ tiffdata.writeToFile outfile, atomically:false
+ end
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080605/6c422288/attachment.htm
More information about the macruby-changes
mailing list