PDF Auto-Duplexer

The number one request I’ve gotten for graph paper is to add a function that makes 2-page documents that can be easily duplex printed. I haven’t done that because it will further complicate the interface. Also, it isn’t fun to work with a 20-year-old codebase written in a dying language.

The new duplexer is written in python with a JavaScript interface. It doesn’t work well with Firefox, and I’m fine with that. It does work well with Edge, Safari, and Chrome.

# read the file, duplicate the page and write to a new pdf
pdf_writer = PdfWriter()
pdf_reader = PdfReader(file)
page = pdf_reader.pages[0] # get the first page

pdf_writer.add_page(page) # add the page twice

# save to in-memory file
pdf_bytes = io.BytesIO()
pdf_bytes.seek(0) # go to the start of the file

# create response and set custom header
response = make_response(send_file(pdf_bytes, mimetype='application/pdf', as_attachment=True, download_name=new_file_name))
return response