<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: pdf code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 04:29:09 GMT</pubDate>
    <description>DZone Snippets: pdf code</description>
    <item>
      <title>Auto download pdf from www.estado.com.br</title>
      <link>http://snippets.dzone.com/posts/show/5286</link>
      <description>// This script downloads all pdfs from http://jpdf.estado.com.br&lt;br /&gt;// Note, you must subscribe this newspaper in order to download the pdfs&lt;br /&gt;// You must have wget installed&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;export http_proxy="http://10.1.1.1:8000"&lt;br /&gt;&lt;br /&gt;cookie='sMkjwKA67H8FDcsZX5'&lt;br /&gt;dd=`date +%d`&lt;br /&gt;mm=`date +%m`&lt;br /&gt;yyyy=`date +%Y`&lt;br /&gt;&lt;br /&gt;index="http://jpdf.estado.com.br/menupdfi.php?E=SP&amp;D=$dd/$mm/$yyyy&amp;A=/estadopdf/sp/paginas/$yyyy/$mm/$dd/A01.pdf"&lt;br /&gt;&lt;br /&gt;rm index.txt&lt;br /&gt;./wget/wget -nc -k -S -U Mozilla --proxy --header "Cookie: User=$cookie " -O index.txt $index&lt;br /&gt;if [ ! -f index.txt ]; then exit 1; fi&lt;br /&gt;&lt;br /&gt;l=`gawk  'BEGIN {FS="\""} /option VALUE="\/estadopdf/ { print $2 }' index.txt`&lt;br /&gt;&lt;br /&gt;for x in $l; do &lt;br /&gt;&lt;br /&gt;	# Ignora os classificados&lt;br /&gt;	if [ ${x%01.pdf} -eq "Cl" ]; then continue; fi&lt;br /&gt;	# Ignora o Guia&lt;br /&gt;	if [ ${x%01.pdf} -eq "Q" ]; then continue; fi&lt;br /&gt;&lt;br /&gt;	y=http://jpdf.estado.com.br${x%01.pdf}&lt;br /&gt;	i=1&lt;br /&gt;	flag=0&lt;br /&gt;	&lt;br /&gt;	while [ $i -lt 40 ]; do&lt;br /&gt;		filename=`printf "%s%02d.pdf\n" $y $i`&lt;br /&gt;&lt;br /&gt;		echo "=================================================================="&lt;br /&gt;		echo $filename&lt;br /&gt;		echo "=================================================================="&lt;br /&gt;		./wget/wget -P estado -nc -k -S -U Mozilla --proxy --header "Cookie: User=$cookie " $filename&lt;br /&gt;		if [ $? -eq 1 ]; then&lt;br /&gt;			let flag=flag+1&lt;br /&gt;			if [ $flag -gt 1 ]; then &lt;br /&gt;				flag=0&lt;br /&gt;				echo "Proximo caderno..."; break;&lt;br /&gt;			fi &lt;br /&gt;		fi&lt;br /&gt;		&lt;br /&gt;		sleep 1&lt;br /&gt;		let i=i+1&lt;br /&gt;	done&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Mar 2008 20:27:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5286</guid>
      <author>adr1an0 (Adr)</author>
    </item>
    <item>
      <title>pman  --  create, print, save, view PDF man pages</title>
      <link>http://snippets.dzone.com/posts/show/4274</link>
      <description>pman  --  create, print, save, view PDF man pages&lt;br /&gt;&lt;br /&gt;Author:  ntk&lt;br /&gt;License:    &lt;a href="http://www.opensource.org/licenses/mit-license.php"&gt;The MIT License&lt;/a&gt;, Copyright (c) 2007 ntk&lt;br /&gt;Description:    (batch) convert &lt;a href="http://developer.apple.com/documentation/Darwin/Reference/ManPages/"&gt;man pages&lt;/a&gt; into PDF documents and save them to a specified directory; (batch) print or view PDF man pages from the command line&lt;br /&gt;Platform:    Mac OS X 10.4.10; man bash&lt;br /&gt;Installation:    put pman() into ~/.bash_login (or alternatives)        &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# Usage:&lt;br /&gt;   &lt;br /&gt;pman ls; pman getopts                                 # convert a singel man page to a PDF file, save and open it&lt;br /&gt;pman 8 sticky                                         # same with manual section number&lt;br /&gt;pman m toe                                     &lt;br /&gt;pman -b ls 'open(2)' dd "chmod(2)" curl 'open(n)'     # batch convert man pages into PDF files&lt;br /&gt;pman -p rm srm open\(2\) 'toe(m)' 'ncurses(3)'        # print man pages using the default printer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;pman() {&lt;br /&gt;&lt;br /&gt;section="$1"    &lt;br /&gt;manpage="$2"    &lt;br /&gt;&lt;br /&gt;mandir="/Users/Shared/manpages"    #  save the created PDF man pages to the specified directory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# batch process man pages to PDF files with the "-b" switch and save them to $mandir&lt;br /&gt;# example: pman -b ls 'open(2)' dd 'chmod(2)' 'open(n)' 'sticky(8)'&lt;br /&gt;# cf. man -aW open for "man n open"&lt;br /&gt;&lt;br /&gt;if [[ "$1" = "-b" ]]; then         &lt;br /&gt;&lt;br /&gt;if [[ ! -d $mandir ]]; then        &lt;br /&gt;   mkdir -p $mandir&lt;br /&gt;   chmod 1777 $mandir&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;shift   # remove "-b" from "$@"&lt;br /&gt;&lt;br /&gt;for manfile in "$@"; do &lt;br /&gt;&lt;br /&gt;# example for $manfile: open(2)&lt;br /&gt;manpage="`echo $manfile | grep -Eos '^[^\(]+'`"                              # extract name of man page&lt;br /&gt;section="`echo $manfile | grep -Eos '\([^\)]+\)' | grep -Eos '[^\(\)]+'`"    # extract section of man page&lt;br /&gt;&lt;br /&gt;if [[ ! "$section" ]]; then&lt;br /&gt;   section="1"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [[ ! -f "`man ${section} -W ${manpage} 2&gt;/dev/null`" ]]; then&lt;br /&gt;#if [[ ! -f "`man -W ${section} ${manpage} 2&gt;/dev/null `" ]]; then&lt;br /&gt;   echo "No such man page: man ${section} ${manpage}"&lt;br /&gt;   continue&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;manfile="${mandir}/${manpage}(${section}).pdf"&lt;br /&gt;echo "$manfile"&lt;br /&gt;&lt;br /&gt;if [[ ! -f "$manfile" ]]; then&lt;br /&gt;   man $section -t $manpage 2&gt;/dev/null | pstopdf -i -o "$manfile" 2&gt;/dev/null&lt;br /&gt;   chmod 1755 "$manfile"&lt;br /&gt;   # hide file extension .pdf&lt;br /&gt;   if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;return 0&lt;br /&gt;   &lt;br /&gt;fi          # END of batch processing man pages to PDF files&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# print PDF man pages using the default printer (see man lpr and man lpoptions)&lt;br /&gt;# if necessary, create the specified PDF man pages and save them to $mandir&lt;br /&gt;# example: pman -p rm srm&lt;br /&gt;&lt;br /&gt;if [[ "$1" = "-p" ]]; then         &lt;br /&gt;&lt;br /&gt;if [[ ! -d $mandir ]]; then        &lt;br /&gt;   mkdir -p $mandir&lt;br /&gt;   chmod 1777 $mandir&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;shift   # remove "-p" from "$@"&lt;br /&gt;&lt;br /&gt;for manfile in "$@"; do &lt;br /&gt;&lt;br /&gt;# example for $manfile: open(2)&lt;br /&gt;manpage="`echo $manfile | grep -Eos '^[^\(]+'`"                              # extract name of man page&lt;br /&gt;section="`echo $manfile | grep -Eos '\([^\)]+\)' | grep -Eos '[^\(\)]+'`"    # extract section of man page&lt;br /&gt;&lt;br /&gt;if [[ ! "$section" ]]; then&lt;br /&gt;   section="1"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [[ ! -f "`man ${section} -W ${manpage} 2&gt;/dev/null`" ]]; then&lt;br /&gt;   echo "No such man page: man ${section} ${manpage}"&lt;br /&gt;   continue&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;manfile="${mandir}/${manpage}(${section}).pdf"&lt;br /&gt;echo "$manfile"&lt;br /&gt;&lt;br /&gt;if [[ ! -f "$manfile" ]]; then&lt;br /&gt;   man -t $section $manpage 2&gt;/dev/null | pstopdf -i -o "$manfile" 2&gt;/dev/null&lt;br /&gt;   chmod 1755 "$manfile"&lt;br /&gt;   # hide file extension .pdf&lt;br /&gt;   if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi&lt;br /&gt;   lpr "$manfile"&lt;br /&gt;else&lt;br /&gt;   lpr "$manfile"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;done&lt;br /&gt;&lt;br /&gt;return 0&lt;br /&gt;   &lt;br /&gt;fi          # END of printing man pages using the default printer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# convert a single man page to a PDF file, save it to $mandir and then open it in a PDF viewer&lt;br /&gt;&lt;br /&gt;if [[ -z "$1" ]] || [[ $# -gt 2 ]]; then       # check number of arguments&lt;br /&gt;#if [[ -z "$1" || $# -gt 2 ]]; then  &lt;br /&gt;#if [ -z "$1" -o $# -gt 2 ]; then&lt;br /&gt;  echo "Wrong number of arguments!" &lt;br /&gt;  return 1&lt;br /&gt;fi &lt;br /&gt;&lt;br /&gt;if [[ ! "$manpage" ]]; then     # turn "pman ls" into "pman 1 ls"&lt;br /&gt;   manpage="$section"         # if $manpage is an empty string because there has been no "$2" then $manpage is set to "$section" and ...&lt;br /&gt;   section="1"                # ... $section is set to "1"&lt;br /&gt;fi                            &lt;br /&gt;&lt;br /&gt;if [[ ! -f "`man ${section} -W ${manpage} 2&gt;/dev/null`" ]]; then&lt;br /&gt;   echo "No such man page: man ${section} ${manpage}"&lt;br /&gt;   return 1&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;if [[ ! -d $mandir ]]; then&lt;br /&gt;   mkdir -p $mandir&lt;br /&gt;   chmod 1777 $mandir&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;manfile="${mandir}/${manpage}(${section}).pdf"&lt;br /&gt;&lt;br /&gt;if [[ -f "$manfile" ]]; then&lt;br /&gt;   open "$manfile"&lt;br /&gt;else&lt;br /&gt;   man $section -t $manpage 2&gt;/dev/null | pstopdf -i -o "$manfile" 2&gt;/dev/null&lt;br /&gt;   chmod 1755 "$manfile"&lt;br /&gt;   # hide file extension .pdf&lt;br /&gt;   if [[ -f /Developer/Tools/SetFile ]]; then /Developer/Tools/SetFile -a E "$manfile"; fi&lt;br /&gt;   open "$manfile"&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;return 0&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sat, 07 Jul 2007 10:54:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4274</guid>
      <author>ntk ()</author>
    </item>
    <item>
      <title>PDF Word Link</title>
      <link>http://snippets.dzone.com/posts/show/4039</link>
      <description>// Find Word(s) on Current Page and add link &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;var numWords = this.getPageNumWords(this.pageNum);&lt;br /&gt;p = this.pageNum;&lt;br /&gt;&lt;br /&gt;for ( var i=0; i&lt;numWords; i++){&lt;br /&gt;    var ckWord =  this.getPageNthWord(p,i,true);;&lt;br /&gt;&lt;br /&gt;    if(ckWord == "Solo")&lt;br /&gt;    {&lt;br /&gt;        var q = this.getPageNthWordQuads(p,i);&lt;br /&gt;&lt;br /&gt;        m = (new Matrix2D).fromRotated(this,p);&lt;br /&gt;        mInv = m.invert();&lt;br /&gt;        r = mInv.transform(q);&lt;br /&gt;        r = r.toString();&lt;br /&gt;        r = r.split(",");&lt;br /&gt;        l = addLink(p, [r[4], r[5], r[2], r[3]]);&lt;br /&gt;        l.borderColor = color.red;&lt;br /&gt;        l.borderWidth = 1;&lt;br /&gt;        l.setAction("this.getUrl('http://www.adobe.com/');");&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 May 2007 22:21:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4039</guid>
      <author>ldstudio (Larry Rivera)</author>
    </item>
    <item>
      <title>Simple % bar in a pdf using Ruby</title>
      <link>http://snippets.dzone.com/posts/show/3648</link>
      <description>Will create a bar, filled to the percentage provided, and draw it in a PDF.&lt;br /&gt;&lt;br /&gt;Requires PDF Writer, call method after setting up PDF to @pdf&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def generate_pdf_bar(p = 50, x = 10, y = 'center', w = 200, h = 10)&lt;br /&gt;     # adjustments&lt;br /&gt;    if y == 'center'&lt;br /&gt;      y = @pdf.page_height / 2 - h&lt;br /&gt;    else&lt;br /&gt;      y = @pdf.page_height - y - h&lt;br /&gt;    end&lt;br /&gt;    p = w / 100 * p&lt;br /&gt;&lt;br /&gt;      # Empty&lt;br /&gt;    @pdf.stroke_color  Color::RGB::Black&lt;br /&gt;    @pdf.rectangle(x, y, w, h).close_stroke&lt;br /&gt;&lt;br /&gt;     # Fill&lt;br /&gt;    @pdf.fill_color    Color::RGB::Black&lt;br /&gt;    @pdf.stroke_color  Color::RGB::Black&lt;br /&gt;    @pdf.rectangle(x, y, p, h).close_fill_stroke&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Mar 2007 12:01:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3648</guid>
      <author>abscond (James Darling)</author>
    </item>
    <item>
      <title>Export Adobe FDF and XFDF from ActiveRecord</title>
      <link>http://snippets.dzone.com/posts/show/3487</link>
      <description>I needed to export XFDF from an application.  This code is kind of untested, but is based on the solution I came up with.  I would appreciate responses/modifications.  It's very straightforward mixin stuff, for the most part.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# (X)FDF Export for ActiveRecord&lt;br /&gt;# Based on Justin Koivisto's FDF library for PHP&lt;br /&gt;# Author: Sean Cribbs, seancribbs_AT_gmail_DOT_com, http://seancribbs.com&lt;br /&gt;module FDF&lt;br /&gt;  def self.included(base)&lt;br /&gt;    base.extend ClassMethods&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  module ClassMethods&lt;br /&gt;    # Options:&lt;br /&gt;    #  &lt;tt&gt;:filename&lt;/tt&gt; - The filename of the associated PDF document.  REQUIRED!&lt;br /&gt;    #  &lt;tt&gt;:indentation&lt;/tt&gt; - How much to indent the resulting XFDF (XML)&lt;br /&gt;    #  &lt;tt&gt;:include&lt;/tt&gt; - Which associated models to include in the generated XFDF.&lt;br /&gt;    #  &lt;tt&gt;:exclude_attributes&lt;/tt&gt; - Which attributes of the current model should not be exported.  By default all non-internal attributes are exported (i.e. everything but _id fields).&lt;br /&gt;    #  &lt;tt&gt;:include_attributes&lt;/tt&gt; - Which attributes of the current model should be exported in addition to the default. By default all non-internal attributes are exported (i.e. everything but _id fields).&lt;br /&gt;    #  &lt;tt&gt;:attributes&lt;/tt&gt; - Override which attributes to export.&lt;br /&gt;    def exports_xfdf(options = {})&lt;br /&gt;      raise ArgumentError, "A :filename option must be specified." unless options[:filename]&lt;br /&gt;      options[:indentation] ||= 2&lt;br /&gt;      options[:include] = options[:include].is_a?(Array) ? options[:include] : [options[:include]].compact&lt;br /&gt;      unless included_modules.include? XFDFMethods&lt;br /&gt;        class_inheritable_accessor :xfdf_options&lt;br /&gt;        extend ClassMethods&lt;br /&gt;        include XFDFMethods&lt;br /&gt;      end&lt;br /&gt;      self.xfdf_options = options&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    # Options:&lt;br /&gt;    #  &lt;tt&gt;:filename&lt;/tt&gt; - The filename of the associated PDF document.  REQUIRED!&lt;br /&gt;    #  &lt;tt&gt;:include&lt;/tt&gt; - Which associated models to include in the generated FDF.&lt;br /&gt;    #  &lt;tt&gt;:exclude_attributes&lt;/tt&gt; - Which attributes of the current model should not be exported.  By default all non-internal attributes are exported (i.e. everything but _id fields).&lt;br /&gt;    #  &lt;tt&gt;:include_attributes&lt;/tt&gt; - Which attributes of the current model should be exported in addition to the default. By default all non-internal attributes are exported (i.e. everything but _id fields).&lt;br /&gt;    #  &lt;tt&gt;:attributes&lt;/tt&gt; - Override which attributes to export.&lt;br /&gt;    def exports_fdf(options = {})&lt;br /&gt;      raise ArgumentError, "A :filename option must be specified." unless options[:filename]&lt;br /&gt;      options[:include] = options[:include].is_a?(Array) ? options[:include] : [options[:include]].compact&lt;br /&gt;      unless included_modules.include? FDFMethods&lt;br /&gt;        class_inheritable_accessor :fdf_options&lt;br /&gt;        extend ClassMethods&lt;br /&gt;        include FDFMethods&lt;br /&gt;      end&lt;br /&gt;      self.fdf_options = options&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  module XFDFMethods&lt;br /&gt;    def to_xfdf(options = {})&lt;br /&gt;      options.reverse_merge! self.class.xfdf_options&lt;br /&gt;      fields = Util.collect_values(self, self.class.content_columns.map(&amp;:name), options)&lt;br /&gt;      filename = options[:filename]&lt;br /&gt;      xml = Builder::XmlMarkup.new :indentation =&gt; options[:indentation]&lt;br /&gt;      xml.instruct!&lt;br /&gt;      xml.xfdf("xmlns" =&gt; "http://ns.adobe.com/xfdf/", "xml:space" =&gt; "preserve") {&lt;br /&gt;        xml.f :href =&gt; filename&lt;br /&gt;        xml.fields {&lt;br /&gt;          fields.each do |field, value|&lt;br /&gt;            xml.field(:name =&gt; field) {&lt;br /&gt;              if value.is_a? Array&lt;br /&gt;                  value.each {|item| xml.value(item.to_s) }&lt;br /&gt;              else&lt;br /&gt;                xml.value(value.to_s)&lt;br /&gt;              end&lt;br /&gt;            }&lt;br /&gt;          end&lt;br /&gt;        }&lt;br /&gt;      }&lt;br /&gt;      xml.target!&lt;br /&gt;    end    &lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  module FDFMethods&lt;br /&gt;    def to_fdf(options={})&lt;br /&gt;      options.reverse_merge! self.class.fdf_options&lt;br /&gt;      fields = Util.collect_values(self, self.class.content_columns.map(&amp;:name), options)&lt;br /&gt;      filename = options[:filename]&lt;br /&gt;      data = "%FDF-1.2\n%&#226;&#227;&#65533;?&#211;\n1 0 obj\n&lt;&lt; \n/FDF &lt;&lt; /Fields [ "&lt;br /&gt;      fields.each do |field, value|&lt;br /&gt;        if value.is_a? Array&lt;br /&gt;          data &lt;&lt; "&lt;&lt;/T(#{field})/V["&lt;br /&gt;          value.each {|v| data &lt;&lt; "(#{v.strip})"}&lt;br /&gt;          data &lt;&lt; "]&gt;&gt;"&lt;br /&gt;        else&lt;br /&gt;          data &lt;&lt; "&lt;&lt;/T(#{field})/V(#{value.strip})&gt;&gt;"&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    data &lt;&lt; "] \n/F (#{filename}) /ID [ &lt;#{MD5.md5(Time.now).to_s}&gt;\n ] &gt;&gt;" &lt;&lt;&lt;br /&gt;            " \n&gt;&gt; \nendobj\ntrailer\n" &lt;&lt; "&lt;&lt;\n/Root 1 0 R \n\n&gt;&gt;\n%%EOF\n"&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  module Util&lt;br /&gt;    def self.collect_values(object, defaults, options = {})&lt;br /&gt;      attrs = []&lt;br /&gt;      if options[:attributes]&lt;br /&gt;        attrs = stringify_all(options[:attributes]) rescue []&lt;br /&gt;      else        &lt;br /&gt;        [:include_attributes, :exclude_attributes].each do |opt|&lt;br /&gt;          options[opt] = stringify_all(options[opt]) rescue []&lt;br /&gt;        end&lt;br /&gt;        attrs = stringify_all(defaults) + options[:include_attributes] - options[:exclude_attributes]&lt;br /&gt;      end&lt;br /&gt;      fields = attrs.inject({}) do |hash, key|&lt;br /&gt;        value = object.send(key) rescue nil&lt;br /&gt;        hash.merge key =&gt; value&lt;br /&gt;      end&lt;br /&gt;      fields.merge collect_association_values(object, options)&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.collect_association_values(object, options = {})&lt;br /&gt;      return {} if options[:include].blank?&lt;br /&gt;      values = {}&lt;br /&gt;      options[:include].each do |association|&lt;br /&gt;        unless object.send(association).blank?&lt;br /&gt;          models = object.send(association)&lt;br /&gt;          unless models.is_a? Array&lt;br /&gt;            columns = models.class.content_columns.map(&amp;:name)&lt;br /&gt;            values.merge! association_dump(association, models, columns)&lt;br /&gt;          else&lt;br /&gt;            models.each_with_index do |model, index|&lt;br /&gt;              columns = model.class.content_columns.map(&amp;:name)&lt;br /&gt;              values.merge! association_dump("#{association.singularize}_#{index+1}", model, columns)&lt;br /&gt;            end&lt;br /&gt;          end&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;      values&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.association_dump(prefix, object, attributes)&lt;br /&gt;      attributes.inject({}) do |hash, attr|&lt;br /&gt;        value = object.send(attr) rescue nil&lt;br /&gt;        hash.merge "#{prefix}_#{attr}" =&gt; value&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.stringify_all(ary)&lt;br /&gt;      ary.compact.map(&amp;:to_s).uniq&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;ActiveRecord::Base.send :include, FDF&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Also available from: http://pastie.caboo.se/38835</description>
      <pubDate>Sat, 10 Feb 2007 00:43:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3487</guid>
      <author>seancribbs (Sean Cribbs)</author>
    </item>
    <item>
      <title>Add a watermark to a multi-page PDF (a-la Pragmatic Programmers)</title>
      <link>http://snippets.dzone.com/posts/show/1704</link>
      <description>This adds a text watermark to every page of a PDF document, as used by Pragmatic Programmers. Nothing secret here, more of a way to excercise "human" DRM. Used as:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;   perl makepdf.pl "John Doe"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;use PDF::Reuse;&lt;br /&gt;use PDF::Reuse::Util;&lt;br /&gt;use strict;&lt;br /&gt;&lt;br /&gt;my ($name) = @ARGV;&lt;br /&gt;&lt;br /&gt;prFile('book_for_someone.pdf');&lt;br /&gt;&lt;br /&gt;my $sourcePdf = 'pdf_that_your_designer_made.pdf';&lt;br /&gt;my $greeting = "This book is personalized for " . $name;&lt;br /&gt;&lt;br /&gt;my $left = 1;&lt;br /&gt;while ($left) {&lt;br /&gt;   prFont('HO');&lt;br /&gt;   prAdd("0 0 0 rg\n0 g\nf\n");&lt;br /&gt;   prText( 38, 800, $greeting);&lt;br /&gt;   $left = prSinglePage($sourcePdf);   &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;prEnd;&lt;/code&gt;</description>
      <pubDate>Thu, 16 Mar 2006 05:50:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1704</guid>
      <author>julik ()</author>
    </item>
    <item>
      <title>Creating a PDF using iText and ColdFusion</title>
      <link>http://snippets.dzone.com/posts/show/1646</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;cfscript&gt;&lt;br /&gt;// create document&lt;br /&gt;document 		= CreateObject("java", "com.lowagie.text.Document");&lt;br /&gt;document.init();&lt;br /&gt;&lt;br /&gt;// writer&lt;br /&gt;fileIO 			= CreateObject("java", "java.io.FileOutputStream");&lt;br /&gt;fileIO.init(pdf_path);&lt;br /&gt;writer 			= CreateObject("java", "com.lowagie.text.pdf.PdfWriter");&lt;br /&gt;writer.getInstance(document, fileIO);&lt;br /&gt;document.open();&lt;br /&gt;&lt;br /&gt;// newsinfo header image&lt;br /&gt;Image 			= CreateObject("java", "com.lowagie.text.Image");&lt;br /&gt;jpg 			= Image.getInstance(header_image);&lt;br /&gt;jpg.setAbsolutePosition(28, 713);&lt;br /&gt;jpg.setDpi(300,300);&lt;br /&gt;document.add(jpg);&lt;br /&gt;&lt;br /&gt;// top margin; dumb i know but i was in a hurry&lt;br /&gt;paragraph = CreateObject("java", "com.lowagie.text.Paragraph");&lt;br /&gt;paragraph.init(" ");&lt;br /&gt;for (i=0; i lt 9; i=i+1) {&lt;br /&gt;	document.add(paragraph);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// the fonts&lt;br /&gt;FontFactory 	= createobject("java", "com.lowagie.text.FontFactory");&lt;br /&gt;Font 			= createObject("java", "com.lowagie.text.Font");&lt;br /&gt;TimesLargeBI 	= Font.init(Font.TIMES_ROMAN, 14.0, Font.BOLDITALIC);&lt;br /&gt;TimesNormal 	= Font.init(Font.TIMES_ROMAN, 12.0);&lt;br /&gt;&lt;br /&gt;// all the text&lt;br /&gt;paragraph 		= CreateObject("java", "com.lowagie.text.Paragraph");&lt;br /&gt;&lt;br /&gt;paragraph.init("Hello World!", TimesLargeBI);&lt;br /&gt;paragraph.setIndentationLeft(indentation_left);&lt;br /&gt;paragraph.setIndentationRight(indentation_right);&lt;br /&gt;document.add(paragraph);&lt;br /&gt;&lt;br /&gt;paragraph.init("#dateFormat(now(), 'long')#", TimesNormal);&lt;br /&gt;paragraph.setIndentationLeft(indentation_left);&lt;br /&gt;paragraph.setIndentationRight(indentation_right);&lt;br /&gt;document.add(paragraph);&lt;br /&gt;&lt;br /&gt;document.close();&lt;br /&gt;&lt;/cfscript&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Mar 2006 01:54:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1646</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Finding pdf paper from CiteULike</title>
      <link>http://snippets.dzone.com/posts/show/125</link>
      <description>I use CiteULike (http://citeulike.org) to manage papers a lot.&lt;br /&gt;Unfortunately, I don't have access to paid site. But some authors&lt;br /&gt;are generous enough to put pdf on his own site, which I find&lt;br /&gt;using google search.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;javascript:(function(){&lt;br /&gt;var title = document.title.substring(11);&lt;br /&gt;var query = '%22' + title + '%22 ' + 'filetype:pdf';&lt;br /&gt;var url = 'http://www.google.com/search?q=' + encodeURI(query);&lt;br /&gt;window.open(url);&lt;br /&gt;})();&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;It simply takes the paper title from windows title. Then it searches the title(enclosed in quotation) for pdf files of the same name.</description>
      <pubDate>Mon, 11 Apr 2005 04:03:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/125</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
