Created
December 20, 2012 07:37
-
-
Save smiler/4343574 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
#!/usr/bin/env ruby1.9.1 | |
# encoding: utf-8 | |
require 'prawn' | |
require 'nokogiri' | |
doc = Nokogiri::XML::Document.parse(File.read ARGV[0]) | |
pdf = Prawn::Document.new | |
pdf.text "Hästen är en frukt", :size => 20, :align => :center | |
sorted = doc.xpath('//finding').sort do |a, b| | |
a.xpath('ip')[0].content <=> b.xpath('ip')[0].content | |
end | |
sorted.each do |finding| | |
ip = finding.xpath('ip')[0].content | |
port = finding.xpath('port')[0].content | |
id = finding.xpath('id')[0].content | |
severity = finding.xpath('severity')[0].content | |
txt = finding.xpath('finding_txt')[0].content | |
header = [["IP", "Port", "Id", "Severity"], | |
[ip, port, id, severity]] | |
pdf.move_down 20 | |
pdf.table header do | |
cells.borders = [] | |
row(0).font_style = :bold | |
row(0).borders = [:bottom] | |
end | |
pdf.move_down 10 | |
pdf.text txt | |
pdf.start_new_page | |
end | |
pdf.render_file ARGV[0].gsub(/\.xml$/, '.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment