Skip to content

Commit

Permalink
#9383: Re-enable PDF generation (#9973)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudadel54 committed Feb 23, 2024
1 parent feffd53 commit 273103b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ mkdocs==1.5.2
mkdocs-material==9.2.6
jinja2==3.1.3
Markdown==3.4.4
git+https://github.com/geosolutions-it/mkdocs-pdf-export-plugin.git
WeasyPrint==52.5
mkdocs-with-pdf==0.9.3
9 changes: 9 additions & 0 deletions docs/theme/css/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,12 @@ li.md-tabs__item:hover{
float: right;
}

.pdf-icon {
background-image: url(../img/download-pdf-icon.png);
background-size: contain;
width: 20px;
height: 20px;
margin-right: 4px;
background-position: center;
background-repeat: no-repeat;
}
Binary file added docs/theme/img/download-pdf-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/theme/partials/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<a href="https://mapstore.geosolutionsgroup.com/mapstore/docs/api/framework"
class="md-tabs__link" target="_blank">Framework API</a>
</li>
<li class="md-tabs__item pull-right export-pdf-li" style="display:flex;" title="Export PDF"></li>
</ul>
</div>
</div>
Expand Down
17 changes: 14 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,18 @@ nav:
- MapViewer query paramaters: 'developer-guide/map-query-parameters.md'
plugins:
- search
- pdf-export:
combined: true
combined_output_path: pdf/mapstore_documentation.pdf
- with-pdf:
author: GeoSolutionsGroup
copyright: 'MapStore©'
#
#cover: false
#back_cover: true
cover_logo: 'img/mapstore2-logo.png'
cover_title: MapStore Documentation
cover_subtitle: User Guide and Developer Guide
toc_level: 3
output_path: pdf/mapstore_documentation.pdf
enabled_if_env: ENABLE_PDF_EXPORT
debug_html: true
show_anchors: true
verbose: true
40 changes: 40 additions & 0 deletions pdf_event_hook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# It is for mkdocs-with-pdf plugin
# this file is resplosible for rendering the export pdf icon in case ENABLE_EXPORT_PDF = 1 in build environment

import logging

from bs4 import BeautifulSoup
from mkdocs.structure.pages import Page


def inject_link(html: str, href: str,
page: Page, logger: logging) -> str:
"""Adding PDF View button on navigation bar(using material theme)"""
def _icon_tag():
return BeautifulSoup('<span class="pdf-icon"></span>', 'html.parser')

logger.info(f'(hook on inject_link: {page.title})')
soup = BeautifulSoup(html, 'html.parser')
# you can change the icon location by specify the class name of the dom element that you want to append to
# Find the DOM element with class "export-pdf-li"
export_pdf = soup.find(class_='export-pdf-li')
nav = soup.find(class_='md-header-nav')
if export_pdf:
a = soup.new_tag('a', href=href, title='PDF', target="_blank", **{'class': 'md-tabs__link'})
# Append an img tag with a local image source
a.append(_icon_tag())
a.append("Export PDF")
export_pdf.append(a)
return str(soup)
else:
if not nav:
# after 7.x
nav = soup.find('nav', class_='md-header__inner')
if nav:
a = soup.new_tag('a', href=href, title='PDF', target="_blank", **{'class': 'md-header__button md-header-nav__button md-icon'})
a.append(_icon_tag())
a.append("Export PDF")
nav.append(a)
return str(soup)

return html

0 comments on commit 273103b

Please sign in to comment.