[Python] Turning Letter sized pdfs into B size

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make "A"-sized (8.5" x 11") pdfs into "B"-sized (11" x 17") pdfs. Because of their dimensions, I should be able to fit two "A"-sized papers into a single "B"-sized paper. I want the A sized output to be on the right side of the page and left side of the B sized paper to be blank.

    I'm updating a program I wrote to put information onto a pdf and want it to convert the A sized papers to B sized as well. Currently, I'm using separate steps to first merge information into an "A"-sized pdf, and then another step to try to merge a blank "B"-sized paper with the "A"-sized paper. Proabably could do this in a single step, but I'm just trying to make this work. Any help would be appreciated.

    # Makes a temporary pdf to put text into and merge into another pdf later
    c = canvas.Canvas("temp.pdf", pagesize=Pagesize_Canvas)
    c.setFont(Font, Font_size)
    c.setFillColorRGB(1, 0, 0) # Red color
    c.drawString(LABEL_ONE_position_width, LABEL_ONE_position_height, LABEL_ONE) #sets position of LABEL_ONE on back of paper.
    c.drawString(LABEL_TWO_position_width, LABEL_TWO_position_height, LABEL_TWO) #sets position of LABEL_TWO on back of paper.
    c.save()

    temp_pdf = PdfReader(open("temp.pdf", "rb"))
    temp_page = temp_pdf.pages[0]


    # Merge step
    Final_output_pdf = PdfWriter()
    for page_num, page in enumerate(existing_pdf.pages):
    if page_num >= 0:
    page.merge_page(temp_page)
    Final_output_pdf.add_page(page)


    # Save the output PDF to a file

    with open(f"{newpath}\{ROW}_{PART_NUMBER:.0f}_{SHEETCOUNT}.pdf", "wb") as output_file:
    Final_output_pdf.write(output_file)

    temptwo_pdf = PdfReader(open(f"C:\\Users\\{USERNAME}\\Desktop\\blank_B_size.pdf", "rb"))

    # Merge step
    Finaltwo_output_pdf = PdfWriter()
    for page_num, page in enumerate(Final_output_pdf.pages):
    if page_num >= 0:

    page.merge_page(temptwo_pdf)
    Finaltwo_output_pdf.add_page(page)

    with open(f"{newpath}\{ROW}_{PART_NUMBER:.0f}_{SHEETCOUNT}.pdf", "wb") as output_file:
    Final_output_pdf.write(output_file)


    temptwo_pdf.stream.close()
    temp_pdf.stream.close()
    os.remove("temp.pdf")

    Continue reading...

Compartilhe esta Página