Skip to content

Instantly share code, notes, and snippets.

@zupo zupo/export.py
Last active Apr 21, 2019

Embed
What would you like to do?
Export Plone site into a directory tree of PDFs.
# spin up a local instance
# portal_workflows, allow everything for Anonymous, click update portal security
# bin/instance debug
# >>> for brain in app.Plone.portal_catalog():
# >>> print brain.getURL().split('http://nohost/Plone/')[1]
# Paste paths into paths.txt
# More info on https://blog.niteo.co/export-plone-to-pdfs/
from subprocess import check_output
import os.path
f = open("paths.txt", "r")
for path in f.readlines():
path = path[:-1] # remove \n
filename = path.split("/")[-1]
folder = "/".join(path.split("/")[:-1])
if os.path.isfile(f"output/{folder}/{filename}") or os.path.isfile(
f"output/{folder}/{filename}.pdf"
):
print(f"skipping: {folder}/{filename}")
continue
else:
print(f"processing: {path}")
cmd = f"mkdir -p output/{folder}"
output = check_output(cmd, shell=True).decode()
if filename.endswith(("pdf", "jpg", "jpeg", "png")):
cmd = f"wget http://localhost:8080/Plone/{path}"
else:
cmd = (
"/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome "
"--headless --disable-gpu --no-margins --run-all-compositor-stages-before-draw "
f"--print-to-pdf={filename}.pdf "
f"http://localhost:8080/Plone/{path}"
)
check_output(cmd, shell=True, cwd=f"output/{folder}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.