导出pdf添加标题图片显示

dev_forum
SylorHuang 6 years ago
parent 7dd8189f17
commit 51dc8ae124

@ -1334,6 +1334,7 @@ class ExercisesController < ApplicationController
#导出空白试卷
def export_exercise
@exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC")
@request_url = request.base_url
filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf"
stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css"
render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets

@ -42,7 +42,6 @@ class ZipsController < ApplicationController
begin
@exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id])
@request_url = request.base_url
logger.info("######################____________@request_url____________##########################{@request_url}")
group_id = params[:exercise_group_id]
if @exercise.blank?
normal_status(-1,"试卷不存在")
@ -50,12 +49,12 @@ class ZipsController < ApplicationController
@course = @exercise.course
default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed
@ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。
@ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。
#可以分班选择
if group_id.present?
exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数
user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq
@ex_users = @ex_users.where(user_id: user_ids)
@ex_users = @ex_users.where(user_id: user_ids).limit 1
end
default_ex_users_size = @ex_users.size

@ -38,10 +38,10 @@ class ExerciseUserPdfService
kit = PDFKit.new(html)
base_css = %w(app/templates/exercise_export/exercise_export.css)
base_css.each { |css| kit.stylesheets << Rails.root.join(css) }
#-----正式需删掉
# #-----正式需删掉
# aa = File.open(Rails.root.join("public/123.html"),"w+")
# aa.syswrite(kit.source)
#正式需删掉-------
# #正式需删掉-------
file = Tempfile.new(filename)
kit.to_pdf(file.path)
file

@ -68,13 +68,15 @@
<span class="text-gray mlr5">(<%= q&.question_score %>分)</span>
</div>
<div class="pbt5">
<% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %>
<% if q.question_type == 5 %>
<span class="ques-title"><%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %></span>
<% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %>
<span class="ques-title"><%= q_name&.html_safe %></span>
<div class="mt8 text-gray">
<span><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span>
<span><%= q_title&.html_safe %></span>
</div>
<% else %>
<span class="ques-title"><%= q.question_title.present? ? q.question_title&.html_safe : "" %></span>
<span class="ques-title"><%= q_title&.html_safe %></span>
<% end %>
</div>
<div class="pbt5">

@ -167,10 +167,9 @@
<% end %>
</div>
<div class="pbt5">
<% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %>
<% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %>
<% if q_type == 5 %>
<% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %>
<% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %>
<span class="ques-title"><%= q_name&.html_safe %></span>
<div class="mt8 text-gray">
<span><%= q_title&.html_safe %></span>

Loading…
Cancel
Save