diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index ea9bf8c52..eb197a101 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -456,16 +456,28 @@ module ApplicationHelper
       content << "<ul class=\"pages-hierarchy\">\n"
       pages[node].each do |page|
         content << "<li>"
-        if controller.controller_name == 'wiki' && controller.action_name == 'export'
-          href = "##{page.title}"
-        else
-          href = {:controller => 'wiki', :action => 'show',
-                  :project_id => page.project, :id => page.title, :version => nil}
-        end
+        href = if controller.request.format.pdf?
+                 # absolute link for pdf export of single page or all pages in a single document
+                 options[:target] = '_blank'
+                 options[:rel] = 'noopener'
+                 project_wiki_page_url(project_id: page.project, id: page.title, version: nil)
+               elsif controller.params[:format] == 'html' && controller.action_name == 'export'
+                 # relative link for html export of all pages in a single document
+                 "##{page.title}"
+               elsif controller.params[:format] == 'html'
+                 # absolute for html export of single page
+                 "#{h(page.pretty_title)}.html"
+               else
+                 # link handling for rendering pages in UI
+                 {:controller => 'wiki', :action => 'show',
+                   :project_id => page.project, :id => page.title, :version => nil}
+               end
         content <<
           link_to(
             h(page.pretty_title),
             href,
+            :target => options[:target],
+            :rel => options[:rel],
             :title => (if options[:timestamp] && page.updated_on
                          l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on))
                        else
diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index 70c112732..7275ec97f 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -1816,13 +1816,13 @@ class ApplicationHelperTest < Redmine::HelperTest
         distance_of_time_in_words(Time.now, child_page.updated_on)))
   end
 
-  def test_render_page_hierarchy_when_action_is_export
+  def test_render_page_hierarchy_when_action_is_export_and_format_html
     parent_page = WikiPage.find(1)
     child_page = WikiPage.find_by(parent_id: parent_page.id)
     pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
 
-    # Change controller and action using stub
-    controller.stubs(:controller_name).returns('wiki')
+    # Change action and format using stub
+    controller.stubs(:params).returns({ format: 'html' })
     controller.stubs(:action_name).returns("export")
 
     result = render_page_hierarchy(pages_by_parent_id, nil)
@@ -1830,6 +1830,42 @@ class ApplicationHelperTest < Redmine::HelperTest
     assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "##{child_page.title}"
   end
 
+  def test_render_page_hierarchy_links_when_format_is_html
+    parent_page = WikiPage.find(1)
+    child_page = WikiPage.find_by(parent_id: parent_page.id)
+    pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
+
+    # Change format using stub
+    controller.stubs(:params).returns({ format: 'html' })
+
+    result = render_page_hierarchy(pages_by_parent_id, nil)
+    assert_select_in result, 'ul.pages-hierarchy li a[href=?]', "#{h(parent_page.pretty_title)}.html"
+    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', "#{h(child_page.pretty_title)}.html"
+  end
+
+  def test_render_page_hierarchy_links_when_format_is_pdf
+    parent_page = WikiPage.find(1)
+    child_page = WikiPage.find_by(parent_id: parent_page.id)
+    pages_by_parent_id = {nil => [parent_page], parent_page.id => [child_page]}
+
+    # Change request format using stub
+    format = mock('format')
+    format.stubs(:pdf?).returns(true)
+
+    # Stub the controller's request.format to return the mocked format object
+    controller.request.stubs(:format).returns(format)
+
+    result = render_page_hierarchy(pages_by_parent_id, nil)
+    parent_page_url = project_wiki_page_url(project_id: parent_page.project, id: parent_page.title, version: nil)
+    child_page_url = project_wiki_page_url(project_id: child_page.project, id: child_page.title, version: nil)
+
+    assert_select_in result, 'ul.pages-hierarchy li a[href=?]', parent_page_url
+    assert_select_in result, 'ul.pages-hierarchy li ul.pages-hierarchy a[href=?]', child_page_url
+
+    # Make sure that the pdf? method returns the expected value
+    assert_equal true, controller.request.format.pdf?
+  end
+
   def test_link_to_user
     user = User.find(2)
     result = link_to("John Smith", "/users/2", :class => "user active")
