转html改为转pdf
This commit is contained in:
parent
437287d93b
commit
c331e5a9c8
|
@ -62,6 +62,10 @@ class AttachmentsController < ApplicationController
|
|||
render :action => 'file'
|
||||
end
|
||||
|
||||
def pdf?(file)
|
||||
file.downcase.end_with?(".pdf")
|
||||
end
|
||||
|
||||
def download
|
||||
# modify by nwb
|
||||
# 下载添加权限设置
|
||||
|
@ -69,9 +73,12 @@ class AttachmentsController < ApplicationController
|
|||
if candown || User.current.admin? || User.current.id == @attachment.author_id
|
||||
@attachment.increment_download
|
||||
if stale?(:etag => @attachment.digest)
|
||||
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".html")
|
||||
if File.exist?(convered_file)
|
||||
send_file convered_file, :type => 'text/html; charset=utf-8', :disposition => 'inline'
|
||||
convered_file = @attachment.disk_filename
|
||||
unless pdf?(convered_file)
|
||||
convered_file = File.join(Rails.root, "files", "convered_office", @attachment.disk_filename + ".pdf")
|
||||
end
|
||||
if File.exist?(convered_file) && pdf?(convered_file)
|
||||
send_file convered_file, :type => 'application/pdf; charset=utf-8', :disposition => 'inline'
|
||||
else
|
||||
send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
|
||||
:type => detect_content_type(@attachment),
|
||||
|
|
|
@ -7,7 +7,7 @@ module Trustie
|
|||
end
|
||||
|
||||
def office?
|
||||
%w(doc docx ppt pptx xls xlsx pdf).any?{|word| @file.downcase.end_with?(word)}
|
||||
%w(doc docx ppt pptx xls xlsx).any?{|word| @file.downcase.end_with?(word)}
|
||||
end
|
||||
|
||||
def conver(saved_file, force=false)
|
||||
|
@ -21,8 +21,11 @@ module Trustie
|
|||
:open_timeout => -1
|
||||
)
|
||||
req = resource.post :txtDes => File.new(@file, 'rb')
|
||||
File.open(saved_file, "wb+") do |f|
|
||||
f.write(req.body)
|
||||
File.delete(saved_file) if File.exist?(saved_file)
|
||||
if req.body.length > 10 && !req.body.eql?('转换出错')
|
||||
File.open(saved_file, "wb+") do |f|
|
||||
f.write(req.body)
|
||||
end
|
||||
end
|
||||
return true
|
||||
rescue =>e
|
||||
|
|
Loading…
Reference in New Issue