PDF session/allmypdfsinpostscript.py: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "Not done yet! WIP <syntaxhighlight lang="python"> # mypdfs = open("fivepdfs.txt", "r").readlines() mypdfs = open("fivepdfs.txt", "r").read().split("\n") # mypdfs_file = open("fivepdfs.txt", "r") # mypdfs_string = mypdfs_file.read() # mypdfs_list = mypdfs_string.split("\n") print(mypdfs) psfile = open("allmypdfs.ps", "w") ps_top = """ /Times-Roman findfont 30 scalefont setfont 0.5 0.75 0 setrgbcolor 100 100 moveto """ psfile.write(ps_top) for pdf in mypdfs: fil...")
 
No edit summary
Line 1: Line 1:
Not done yet! WIP
WIP


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import os
import random
# mypdfs = open("fivepdfs.txt", "r").readlines()
# mypdfs = open("fivepdfs.txt", "r").readlines()


Line 15: Line 18:


ps_top = """
ps_top = """
/Times-Roman findfont 30 scalefont setfont
/Times-Roman findfont 15 scalefont setfont
0.5 0.75 0 setrgbcolor
100 100 moveto
"""
"""
psfile.write(ps_top)
psfile.write(ps_top)


for pdf in mypdfs:
for pdf in mypdfs:
     filename = f"(hello) show"
    # position
    x = random.randrange(10, 100, 25)
    y = random.randrange(100, 1000, 25)
    position = f"{ x } { y } moveto"
    psfile.write(position)
    psfile.write("\n")
 
    # color!
    r = random.randrange(0, 100, 1)/100
    g = random.randrange(0, 100, 1)/100
    b = random.randrange(0, 100, 1)/100
    color = f"{ r } { g } { b } setrgbcolor"
    psfile.write(color)
 
    # filenames
     filename = f"({ pdf }) show"
     psfile.write(filename)
     psfile.write(filename)
    psfile.write("\n")


ps_bottom = """
ps_bottom = """
Line 31: Line 48:


psfile.close()
psfile.close()
os.system("ps2pdf allmypdfs.ps")
print("DONE!")


</syntaxhighlight>
</syntaxhighlight>

Revision as of 15:54, 28 January 2025

WIP

import os
import random

# mypdfs = open("fivepdfs.txt", "r").readlines()

mypdfs = open("fivepdfs.txt", "r").read().split("\n")

# mypdfs_file = open("fivepdfs.txt", "r")
# mypdfs_string = mypdfs_file.read()
# mypdfs_list = mypdfs_string.split("\n")

print(mypdfs)

psfile = open("allmypdfs.ps", "w")

ps_top = """
/Times-Roman findfont 15 scalefont setfont
"""
psfile.write(ps_top)

for pdf in mypdfs:
    # position
    x = random.randrange(10, 100, 25)
    y = random.randrange(100, 1000, 25)
    position = f"{ x } { y } moveto"
    psfile.write(position)
    psfile.write("\n")

    # color!
    r = random.randrange(0, 100, 1)/100
    g = random.randrange(0, 100, 1)/100
    b = random.randrange(0, 100, 1)/100
    color = f"{ r } { g } { b } setrgbcolor"
    psfile.write(color)

    # filenames
    filename = f"({ pdf }) show"
    psfile.write(filename)
    psfile.write("\n")

ps_bottom = """
showpage
"""
psfile.write(ps_bottom)

psfile.close()

os.system("ps2pdf allmypdfs.ps")
print("DONE!")