Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# It is used to create an easily distributable and printable PDF
# version of a specification document written in markdown (3MF-style).

# (outdated) Documentation:
# https://github.com/3MFConsortium/spec_conventions/blob/master/generatePDFs/generatePDFs.md

on: [pull_request, workflow_dispatch]
name: Build
jobs:
build-linux:
runs-on: ubuntu-latest
env:
SPECNAME: "3MF Toolpath Extension"
steps:
- uses: actions/checkout@v4
with:
submodules: true
- run: pip install wheel
- run: pip install grip
- run: ./markdownToPDF/install_wkhtmltopdf.sh
- run: ./markdownToPDF/mdToPDF.sh "$SPECNAME"
Comment on lines +20 to +21
- name: Upload PDF
uses: actions/upload-artifact@v4
with:
name: ${{ env.SPECNAME }}.pdf
path: ${{ env.SPECNAME }}.pdf
29 changes: 29 additions & 0 deletions markdownToPDF/install_wkhtmltopdf.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2019 3MF Consortium
# All rights reserved.

Comment on lines +1 to +3
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#!/bin/bash

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar vxf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
cp wkhtmltox/bin/wkhtmltopdf .
chmod a+x wkhtmltopdf
78 changes: 78 additions & 0 deletions markdownToPDF/mdToPDF.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2019 3MF Consortium
# All rights reserved.

Comment on lines +1 to +3
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#!/bin/bash

mkdir -p ~/.grip
echo "PASSWORD = '${GITHUB_API_KEY}'" > ~/.grip/settings.py

FILE="$1"
TMPFILE="temp.html"

grip "$FILE.md" --export "$FILE.html"
Comment on lines +26 to +32
sed "s|readme boxed-group clearfix announce instapaper_body md||g" "$FILE.html" > "$TMPFILE"
sed -i "s|.md$||g" "$TMPFILE"
sed -i 's|<a href="images/3mf_logo_50px.png"|<a|g' "$TMPFILE"

sed -i 's|<a href="#|<a href="@|g' "$TMPFILE"
sed -i 's|href="#|name="|g' "$TMPFILE"
sed -i 's|<a href="@|<a href="#|g' "$TMPFILE"
sed -i 's|<pre|<code style="white-space: pre-wrap; page-break-inside: avoid !important; display: block;"|g' "$TMPFILE"
sed -i 's|</pre|</code|g' "$TMPFILE"
# Font size is controlled via print.css; do not inject a global font-size here

MARGIN_TOP=21
MARGIN_RIGHT=21
MARGIN_BOTTOM=21
MARGIN_LEFT=21

# Deprecated: original rendering without print overrides
# ./wkhtmltopdf --title "$FILE" --footer-left "[section]" --footer-right "[page]/[topage]" --footer-font-size 7 --footer-spacing 4 \
# --margin-top $MARGIN --margin-left $MARGIN --margin-right $MARGIN --margin-bottom $MARGIN \
# "$TMPFILE" "$FILE.pdf"

# Re-render with print stylesheet and safer flags to avoid left clipping
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
WKHTMLTOPDF_BIN="./wkhtmltopdf"
if [ ! -x "$WKHTMLTOPDF_BIN" ]; then
WKHTMLTOPDF_BIN="wkhtmltopdf"
fi

"$WKHTMLTOPDF_BIN" \
--title "$FILE" \
--footer-left "[section]" \
--footer-right "[page]/[topage]" \
--footer-font-size 7 \
--footer-spacing 4 \
--page-size A4 \
--margin-top $MARGIN_TOP \
--margin-left $MARGIN_LEFT \
--margin-right $MARGIN_RIGHT \
--margin-bottom $MARGIN_BOTTOM \
--user-style-sheet "$SCRIPT_DIR/print.css" \
--print-media-type \
--viewport-size 1280x2000 \
--dpi 96 \
--disable-smart-shrinking \
--zoom 1.0 \
"$TMPFILE" "$FILE.pdf"
90 changes: 90 additions & 0 deletions markdownToPDF/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/* Print overrides for wkhtmltopdf to avoid left-side clipping and enforce full-width layout */
html, body {
margin: 0 !important;
padding: 0 !important;
}

/* GitHub/Grip typically wraps content in .markdown-body with fixed padding and max-width */
.markdown-body, .container, .container-lg, .clearfix, .boxed-group, #readme, .readme {
box-sizing: border-box !important;
width: 100% !important;
max-width: none !important;
margin: 0 !important;
padding: 0 !important;
}

/* Remove GitHub "Box" borders/shadows around README containers */
#readme, .readme, .Box, .Box-body, .Box-header, .container-lg, .markdown-body {
border: none !important;
box-shadow: none !important;
background: transparent !important;
}

/* Images and SVGs scale to page width */
img, svg, video, canvas {
max-width: 100% !important;
height: auto !important;
}

/* Ensure code blocks wrap and don't overflow page width */
pre, code, pre code {
white-space: pre-wrap !important;
word-wrap: break-word !important;
}

/* Tables shouldn't overflow the page */
table {
width: 100% !important;
table-layout: auto !important; /* allow natural column widths to reduce wrapping */
word-break: normal !important; /* avoid breaking inside words globally */
}

/* More compact table typography for print */
.markdown-body table, table {
font-size: 10px !important;
line-height: 1.25 !important;
}
.markdown-body table th, table th {
font-size: 10.5px !important;
font-weight: 600 !important;
}
.markdown-body table td, .markdown-body table th, table td, table th {
padding: 4px 6px !important; /* tighter padding */
}
.markdown-body table code, table code {
font-size: 10px !important;
}

/* Reduce wrapping while keeping current font size */
.markdown-body table td, .markdown-body table th, table td, table th {
vertical-align: top !important;
/* keep padding as defined above */
}


/* Let the last column (e.g., Annotation) wrap as needed */
.markdown-body table th:last-child,
.markdown-body table td:last-child,
table th:last-child,
table td:last-child {
white-space: normal !important;
word-break: break-word !important;
overflow-wrap: anywhere !important;
hyphens: auto !important;
}


h1, h2, h3, h4, h5, h6 {
page-break-after: avoid;
}

/* Body font size (target .markdown-body to override GitHub styles) */
body, .markdown-body { font-size: 12px !important; }
/* Optional: keep paragraphs readable after size change */
.markdown-body p, .markdown-body li { line-height: 1.4 !important; }

/* Remove horizontal rules if any theme injects them */
hr {
border: 0 !important;
height: 0 !important;
}
Loading