Open
Description
Following up on issue #9, I tried to implement a chain_renderer. Here it is:
#!/usr/bin/python3
# Since all available 3rd party renderer tools for remarkable have issues, it is useful to run them in a chain.
#
# In the configuration, renderer commands can be defined that will be used in the order they are listed. Each command must be able to be called as "command infile outfile"
import sys
import os.path
import subprocess
renderer_list = ["./render_rmrl.py", "./render_maxio.py", "./render_fail.py"] # Add all renderers in the order in which they should be employed. render_fail.py will output a PDF with an error message; it can be added to the list to make sure further documents are being processed.
if __name__ == "__main__":
args = sys.argv[1:]
assert len(args) == 2, "usage: render_chain.py infile outfile"
infile = args[0]
outfile = args[1]
for command in renderer_list:
status, _ = subprocess.getstatusoutput(f"{command} \"{infile}\" \"{outfile}\"")
if status == 0:
break
exit(status)
I also wrote a dummy renderer (render_fail.py) that is called last in the chain to make sure further documents are being processed. Here it is:
#!/usr/bin/python3
# This is a dummy renderer. It creates a pdf file with an error message. It can be used to make sure that other files get processed after an error.
import sys
import os.path
import subprocess
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import A4
def generate_pdf(outfile):
c = canvas.Canvas(outfile, pagesize=A4)
c.drawString(50, 750, "This file could not be rendered.")
c.showPage()
c.save()
if __name__ == "__main__":
args = sys.argv[1:]
assert len(args) == 2, "usage: render_fail.py infile outfile"
infile = args[0]
outfile = args[1]
status = generate_pdf(outfile)
exit(status)
For completeness, here is render_rmrl.py again:
#!/usr/bin/python3
# This method uses the third-party renderer rmrl to render reMarkable documents locally on the computer.
# It downloads the raw reMarkable files to the computer and renders them locally.
#
# It requires the python module rmrl (https://github.com/rschroll/rmrl/) and SSH access to the reMarkable (to download the raw files), but no USB connection.
#
# It fails in some cases.
#
# To use a different third-party renderer, wrap it in a script with call signature like this one!
import sys
import os.path
import subprocess
from rmrl import render
def render_rmrl(input, output):
stream = render(input)
with open(output, "wb") as out_file:
out_file.write(stream.read())
if __name__ == "__main__":
args = sys.argv[1:]
assert len(args) == 2, "usage: render_rmrl.py infile outfile"
infile = args[0]
outfile = args[1]
status = render_rmrl(infile, outfile)
exit(status)
Metadata
Metadata
Assignees
Labels
No labels