Sha256: 06b2f6609f9a6f41b1eda27c1da158753f49a4ed67c48ae5569ffa22deb3bf54

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'
RSpec.describe IiifPrint::PDFDerivativeService do
  let(:valid_file_set) do
    file_set = FileSet.new
    file_set.save!(validate: false)
    file_set
  end

  let(:fixture_path) do
    File.join(
      IiifPrint::GEM_PATH, 'spec', 'fixtures', 'files'
    )
  end

  describe "Creates PDF derivatives" do
    def source_image(name)
      File.join(fixture_path, name)
    end

    def expected_path(file_set)
      Hyrax::DerivativePath.derivative_path_for_reference(file_set, 'pdf')
    end

    # given output file name, check DPI is 150
    def check_dpi(expected)
      metadata = IiifPrint::ImageTool.new(expected).metadata
      # get width of pdf in points (via imagemagick), should be 864x == 12in
      page_width = metadata[:width]
      expect(page_width).to eq 864
      # get total width of image in pixels from pdfimages -list, ==> 1800
      image_width = 1800
      im_list = `pdfimages -list #{expected}`
      expect(im_list.lines[-1].split(' ')[3]).to eq image_width.to_s
      # this combination of page pt width, image px width ==> 150ppi
      expect(image_width / (page_width / 72.0)).to eq 150.0
    end

    def makes_pdf(filename)
      expected = expected_path(valid_file_set)
      expect(File.exist?(expected)).to be false
      svc = described_class.new(valid_file_set)
      svc.create_derivatives(source_image(filename))
      expect(File.exist?(expected)).to be true
      metadata = IiifPrint::ImageTool.new(expected).metadata
      expect(metadata[:content_type]).to eq 'application/pdf'
      check_dpi(expected)
      svc.cleanup_derivatives
    end

    it "creates gray PDF derivative from one-bit source" do
      makes_pdf('ocr_mono.tiff')
    end

    it "creates gray PDF from grayscale source" do
      makes_pdf('lowres-gray-via-ndnp-sample.tiff')
    end

    it "creates color PDF from color source" do
      makes_pdf('4.1.07.tiff')
    end

    it "creates color PDF from color JP2 source" do
      makes_pdf('4.1.07.jp2')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
iiif_print-1.1.0 spec/services/iiif_print/pdf_derivative_service_spec.rb
iiif_print-1.0.0 spec/services/iiif_print/pdf_derivative_service_spec.rb