封筒の印刷などで下側から印刷したいといった要望があるようですね。
封筒の蓋がが引っかかって印刷しづらいとか閉じたままだと厚みが出てしまうからでしょうか?
そこで蓋を開いて下から印刷するわけです。
ところがそう思ってもプリンターに180度回転するオプションがないとどうしようもないわけです。
これはpythonでPDFを使ってあげると簡単に解決できます。
一度印刷用のPDFを作っていただき簡単なスクリプトで180度回転させます。
そののち印刷してください。
以下にソースとpyinstallerでexeにしたものを置いておきます。
使い方:RotatePDF input.pdf output.pdf
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import argparse
from PyPDF2 import PdfReader, PdfWriter
from pathlib import Path
def rotate_pdf(input_path: Path, output_path: Path):
# Check if the file exists
if input_path.exists():
# Read the input PDF file
reader = PdfReader(input_path) # Read the file correctly
writer = PdfWriter() # Create a PdfWriter
# Rotate each page 180 degrees
for page in reader.pages:
page.rotate(180) # Rotate the page
writer.add_page(page)
# Save the rotated PDF as a new file
with open(output_path, "wb") as output_file:
writer.write(output_file) # Close the file at the end
else:
raise FileNotFoundError(f"{input_path} cannot be found")
def main():
# Set up argument parsing
parser = argparse.ArgumentParser(description="Rotate a PDF by 180 degrees.")
parser.add_argument("input", type=str, help="Path to the input PDF file")
parser.add_argument("output", type=str, help="Path to the output PDF file")
args = parser.parse_args()
# Convert string paths to Path objects
input_path = Path(args.input).resolve()
output_path = Path(args.output).resolve()
# Rotate the PDF
rotate_pdf(input_path, output_path)
if __name__ == "__main__":
main()


Commnts