Commit 5b8071f9 authored by jplang's avatar jplang

Adds support for macro and Redmine links in PDF export (#13051).

git-svn-id: https://svn.redmine.org/redmine/trunk@13944 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent c1628c47
......@@ -49,7 +49,6 @@ class IssuesController < ApplicationController
include SortHelper
include IssuesHelper
helper :timelog
include Redmine::Export::PDF
def index
retrieve_query
......@@ -89,7 +88,7 @@ class IssuesController < ApplicationController
}
format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
format.csv { send_data(query_to_csv(@issues, @query, params), :type => 'text/csv; header=present', :filename => 'issues.csv') }
format.pdf { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'issues.pdf') }
format.pdf { send_file_headers! :type => 'application/pdf', :filename => 'issues.pdf' }
end
else
respond_to do |format|
......@@ -130,8 +129,7 @@ class IssuesController < ApplicationController
format.api
format.atom { render :template => 'journals/index', :layout => false, :content_type => 'application/atom+xml' }
format.pdf {
pdf = issue_to_pdf(@issue, :journals => @journals)
send_data(pdf, :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf")
send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf"
}
end
end
......
......@@ -78,7 +78,7 @@ class WikiController < ApplicationController
end
if User.current.allowed_to?(:export_wiki_pages, @project)
if params[:format] == 'pdf'
send_data(wiki_page_to_pdf(@page, @project), :type => 'application/pdf', :filename => "#{@page.title}.pdf")
send_file_headers! :type => 'application/pdf', :filename => "#{@page.title}.pdf"
return
elsif params[:format] == 'html'
export = render_to_string :action => 'export', :layout => false
......@@ -283,9 +283,7 @@ class WikiController < ApplicationController
send_data(export, :type => 'text/html', :filename => "wiki.html")
}
format.pdf {
send_data(wiki_pages_to_pdf(@pages, @project),
:type => 'application/pdf',
:filename => "#{@project.identifier}.pdf")
send_file_headers! :type => 'application/pdf', :filename => "#{@project.identifier}.pdf"
}
end
end
......
......@@ -622,6 +622,8 @@ module ApplicationHelper
end
def parse_inline_attachments(text, project, obj, attr, only_path, options)
return if options[:inline_attachments] == false
# when using an image link, try to use an attachment, if possible
attachments = options[:attachments] || []
attachments += obj.attachments if obj.respond_to?(:attachments)
......
......@@ -19,6 +19,7 @@
module IssuesHelper
include ApplicationHelper
include Redmine::Export::PDF::IssuesPdfHelper
def issue_list(issues, &block)
ancestors = []
......
......@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module WikiHelper
include Redmine::Export::PDF::WikiPdfHelper
def wiki_page_options_for_select(pages, selected = nil, parent = nil, level = 0)
pages = pages.group_by(&:parent) unless pages.is_a?(Hash)
......
<%= raw issues_to_pdf(@issues, @project, @query) %>
\ No newline at end of file
<%= raw issue_to_pdf(@issue, :journals => @journals) %>
\ No newline at end of file
<%= raw wiki_pages_to_pdf(@pages, @project) %>
\ No newline at end of file
<%= raw wiki_page_to_pdf(@page, @project) %>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
# encoding: utf-8
#
# Redmine - project management software
# Copyright (C) 2006-2015 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module Export
module PDF
module WikiPdfHelper
# Returns a PDF string of a set of wiki pages
def wiki_pages_to_pdf(pages, project)
pdf = Redmine::Export::PDF::ITCPDF.new(current_language)
pdf.set_title(project.name)
pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today)
pdf.add_page
pdf.SetFontStyle('B',11)
pdf.RDMMultiCell(190,5, project.name)
pdf.ln
# Set resize image scale
pdf.set_image_scale(1.6)
pdf.SetFontStyle('',9)
write_page_hierarchy(pdf, pages.group_by(&:parent_id))
pdf.output
end
# Returns a PDF string of a single wiki page
def wiki_page_to_pdf(page, project)
pdf = ITCPDF.new(current_language)
pdf.set_title("#{project} - #{page.title}")
pdf.alias_nb_pages
pdf.footer_date = format_date(Date.today)
pdf.add_page
pdf.SetFontStyle('B',11)
pdf.RDMMultiCell(190,5,
"#{project} - #{page.title} - # #{page.content.version}")
pdf.ln
# Set resize image scale
pdf.set_image_scale(1.6)
pdf.SetFontStyle('',9)
write_wiki_page(pdf, page)
pdf.output
end
def write_page_hierarchy(pdf, pages, node=nil, level=0)
if pages[node]
pages[node].each do |page|
if @new_page
pdf.add_page
else
@new_page = true
end
pdf.bookmark page.title, level
write_wiki_page(pdf, page)
write_page_hierarchy(pdf, pages, page.id, level + 1) if pages[page.id]
end
end
end
def write_wiki_page(pdf, page)
text = textilizable(page.content, :text,
:only_path => false,
:edit_section_links => false,
:headings => false,
:inline_attachments => false
)
pdf.RDMwriteFormattedCell(190,5,'','', text, page.attachments, 0)
if page.attachments.any?
pdf.ln(5)
pdf.SetFontStyle('B',9)
pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
pdf.ln
for attachment in page.attachments
pdf.SetFontStyle('',8)
pdf.RDMCell(80,5, attachment.filename)
pdf.RDMCell(20,5, number_to_human_size(attachment.filesize),0,0,"R")
pdf.RDMCell(25,5, format_date(attachment.created_on),0,0,"R")
pdf.RDMCell(65,5, attachment.author.name,0,0,"R")
pdf.ln
end
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment