Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PDF/A-1b #1029

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def render(*a, &b)
# pdf.render_file "foo.pdf"
#
def render_file(filename)
File.open(filename, 'rb+') { |f| render(f) }
File.open(filename, 'wb') { |f| render(f) }
end

# The bounds method returns the current bounding box you are currently in,
Expand Down
1 change: 0 additions & 1 deletion prawn.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency('pdf-reader', ['~> 1.4', '>= 1.4.1'])
spec.add_development_dependency('rubocop', '~> 0.47.1')
spec.add_development_dependency('rubocop-rspec', '~> 1.10')
spec.add_development_dependency('nokogiri', '~> 1.7')

spec.homepage = 'http://prawnpdf.org'
spec.description = <<END_DESC
Expand Down
2 changes: 1 addition & 1 deletion spec/prawn/pdfa_1b_spec_impl.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'spec_helper'
require 'prawn/vera_pdf'
require_relative 'vera_pdf'

describe Prawn::Document do
include Prawn::VeraPdf
Expand Down
21 changes: 8 additions & 13 deletions lib/prawn/vera_pdf.rb → spec/prawn/vera_pdf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'nokogiri'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have spec/extensions dir for things like this. It probably should be renamed to helpers but that's how it is. For historical reasons.

Please put this file in that dir.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It is better located in extensions. No need to require the veraPDF helpers any more. 👍

require 'rexml/document'
require 'open3'

module Prawn
Expand Down Expand Up @@ -29,17 +29,12 @@ def valid_pdfa_1b?(pdf_data)
end

def reported_as_compliant?(xml_data)
xml_doc = Nokogiri::XML xml_data
raise Exception, 'The veraPDF xml report was not well formed.' unless xml_doc.errors.empty?

xml_doc.remove_namespaces!
validation_result = xml_doc.xpath('/processorResult/validationResult')
assertions = validation_result.xpath('assertions/assertion')
assertions.each do |assertion|
message = assertion.at_xpath('message').content
clause = assertion.at_xpath('ruleId').attribute('clause').content
test = assertion.at_xpath('ruleId').attribute('testNumber').content
context = assertion.at_xpath('location/context').content
xml_doc = REXML::Document.new xml_data
xml_doc.elements.each('/processorResult/validationResult/ns2:assertions/ns2:assertion') do |element|
message = element.elements.to_a('ns2:message').first.text
clause = element.elements.to_a('ns2:ruleId').first.attributes['clause']
test = element.elements.to_a('ns2:ruleId').first.attributes['testNumber']
context = element.elements.to_a('ns2:location/ns2:context').first.text
url = 'https://github.com/veraPDF/veraPDF-validation-profiles/wiki/PDFA-Part-1-rules'
url_anchor = "rule-#{clause.delete('.')}-#{test}"
puts
Expand All @@ -49,7 +44,7 @@ def reported_as_compliant?(xml_data)
puts " Details: #{url}##{url_anchor}"
puts
end
validation_result.attribute('isCompliant').content == 'true'
xml_doc.elements.to_a('/processorResult/validationResult').first.attributes['isCompliant'] == 'true'
end
end
end