app/controllers/content_blobs_controller.rb
def pdf_or_convert filepath = @content_blob.filepath
    if @content_blob.is_pdf?
      pdf_filepath = @content_blob.filepath
      pdf_filename = @content_blob.original_filename
    else
      pdf_filepath = @content_blob.filepath("pdf")
      @content_blob.convert_to_pdf(filepath, pdf_filepath)

      if File.exists?(pdf_filepath)
        pdf_filename = File.basename(@content_blob.original_filename, File.extname(@content_blob.original_filename))+".pdf"
      else
        raise Exception.new("Couldn't find converted PDF file.")
      end
    end

    send_file pdf_filepath,
              :filename => pdf_filename,
              :type => "application/pdf",
              :disposition => 'attachment'

    headers["Content-Length"] = File.size(pdf_filepath).to_s
  end
#check whether the file is pdf, otherwise convert to pdf
#then return the pdf file
check whether the file is pdf, otherwise convert to pdf
then return the pdf file
check whether the file is pdf otherwise convert to pdf then return the pdf file
def pdf_or_convert filepath = @content_blob.filepath
    if @content_blob.is_pdf?
      pdf_filepath = @content_blob.filepath
      pdf_filename = @content_blob.original_filename
    else
      pdf_filepath = @content_blob.filepath("pdf")
      @content_blob.convert_to_pdf(filepath, pdf_filepath)
      if File.exists?(pdf_filepath)
        pdf_filename = File.basename(@content_blob.original_filename, File.extname(@content_blob.original_filename))+".pdf"
      else
        raise Exception.new("Couldn't find converted PDF file.")
      end
    end
    send_file pdf_filepath,
              :filename => pdf_filename,
              :type => "application/pdf",
              :disposition => 'attachment'
    headers["Content-Length"] = File.size(pdf_filepath).to_s
  end
def pdf_or_convert filepath = @content_blob . filepath if @content_blob . is_pdf? pdf_filepath = @content_blob . filepath pdf_filename = @content_blob . original_filename else pdf_filepath = @content_blob . filepath ( "pdf" ) @content_blob . convert_to_pdf ( filepath , pdf_filepath ) if File . exists? ( pdf_filepath ) pdf_filename = File . basename ( @content_blob . original_filename , File . extname ( @content_blob . original_filename ) ) + ".pdf" else raise Exception . new ( "Couldn't find converted PDF file." ) end end send_file pdf_filepath , :filename => pdf_filename , :type => "application/pdf" , :disposition => 'attachment' headers [ "Content-Length" ] = File . size ( pdf_filepath ) . to_s end
check whether the file is pdf, otherwise convert to pdf
then return the pdf file
check whether the file is pdf otherwise convert to pdf then return the pdf file
filepath