Class: TaliaCore::DataTypes::PdfData
- Inherits:
-
FileRecord
- Object
- ActiveRecord::Base
- DataRecord
- FileRecord
- TaliaCore::DataTypes::PdfData
- Defined in:
- lib/talia_core/data_types/pdf_data.rb
Overview
FileRecord that contains a PDF document.
Instance Attribute Summary
Attributes inherited from DataRecord
Instance Method Summary collapse
-
#create_from_writer(writer_opts = {}) ⇒ Object
Create the PDF data using PDF::Writer.
-
#extract_mime_type(location) ⇒ Object
The MIME type is always
application/pdf
.
Methods inherited from FileRecord
#all_bytes, #get_byte, #position, #reset, #seek, #size
Methods included from TaliaCore::DataTypes::PathHelpers::ClassMethods
Methods included from DataLoader::ClassMethods
Methods included from IipLoader
#convert_original?, #create_from_files, #create_from_stream, #create_iip, #open_original_image, #open_original_image_file, #open_original_image_stream, #orig_location, #prepare_image_from_existing!
Methods included from TaliaUtil::IoHelper
#base_for, #file_url, #open_from_url, #open_generic
Methods included from PathHelpers
#data_directory, #data_path, #extract_filename, #file_path, #full_filename, #static_path, #tempfile_path
Methods included from FileStore
#all_text, #assign_type, #create_from_data, #create_from_file, #is_file_open?, #write_file_after_save
Methods inherited from DataRecord
#all_bytes, #content_string, find_by_type_and_location!, find_data_records, #get_byte, #mime_type, #position, #reset, #seek, #size
Instance Method Details
#create_from_writer(writer_opts = {}) ⇒ Object
Create the PDF data using PDF::Writer. The writer will be passed to the block given to this method, and the resulting PDF will be saved as the record’s file.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/talia_core/data_types/pdf_data.rb', line 15 def create_from_writer(writer_opts = {}) activate_pdf writer = PDF::Writer.new(writer_opts) do |pdf| yield(pdf) end filename = File.join(Dir.tmpdir, "#{rand 10E16}.pdf") writer.save_as(filename) self.create_from_file('', filename, true) # set to delete tempfile on create self end |
#extract_mime_type(location) ⇒ Object
The MIME type is always application/pdf
8 9 10 |
# File 'lib/talia_core/data_types/pdf_data.rb', line 8 def extract_mime_type(location) 'application/pdf' end |