Dpi and dimensions: print-ready images in processing.py

Hi everyone

I want to print some things I have made in processing. For this, I need high dpi (It’s a lot of “line art” and fine details). It seems like the ideal image would be a lot larger than my screen could show in one. How would you go about getting processing.py graphics ready for printing?

I read this article here:

Sure enough, it’s for Java, but I thought it might work as a starting point. The place where I want to go for printing wants everything as a PDF, So I went with “Technique #2 - Generate a PDF”.
But I can’t get the PDF library to work. First, I was trying the library in my own code. Then, I was looking at example code in the reference. And the examples don’t work for me, either.

Here’s the example code, taken from beginRaw() \ Language (API)

add_library('pdf')

def setup(): 
    size(400, 400)
    beginRaw(PDF, "raw.pdf")

def draw(): 
    line(pmouseX, pmouseY, mouseX, mouseY)

def keyPressed(): 
    if key == ' ':
        endRaw()
        exit()

This gives me the following:

java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader ‘bootstrap’)
at jycessing.LibraryImporter.addJarToClassLoader(LibraryImporter.java:315)
at jycessing.LibraryImporter.recursivelyAddJarsToClasspath(LibraryImporter.java:164)
at jycessing.LibraryImporter.addLibrary(LibraryImporter.java:140)
at jycessing.LibraryImporter$1.call(LibraryImporter.java:82)
at org.python.core.PyObject.call(PyObject.java:480)
at org.python.core.PyObject.call(PyObject.java:484)
at org.python.pycode._pyx11.f$0(PDF_Test.pyde:1)
at org.python.pycode._pyx11.call_function(PDF_Test.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.pycode._pyx10.f$0(C:/Users/LitMe/Documents/Processing/PDF_Test/PDF_Test.pyde:96)
at org.python.pycode._pyx10.call_function(C:/Users/LitMe/Documents/Processing/PDF_Test/PDF_Test.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:276)
at jycessing.PAppletJythonDriver.processSketch(PAppletJythonDriver.java:233)
at jycessing.PAppletJythonDriver.findSketchMethods(PAppletJythonDriver.java:613)
at jycessing.Runner.runSketchBlocking(Runner.java:399)
at jycessing.mode.run.SketchRunner.lambda$2(SketchRunner.java:112)
at java.base/java.lang.Thread.run(Thread.java:833)

I have a rough understanding of what a Class Cast Exception is but I didn’t create the library. The PDF library works fine in Java mode for the Java examples. Can someone run the example code posted above? I don’t know if the problem is on my end, or if the example is broken.
I will try with Technique 1 from the linked webpage, too. But ideally, I’d like to get a PDF straight some processing.
So if you could help me with either getting the PDF library to function, or with me an alternative idea for creating high-resolution graphics ready for printing, then this would make my day.

cheers

EDIT:
Also, I can’t open any of the examples under Examples: Libraries>PDF Export. They immediately glitch out the Processing IDE for me.

The following python source code will run in the Thonny editor using ‘Imported mode for py5’. A file entitled “raw.pdf” was saved in my Python folder. Not sure if this is what you are looking for.

# use Imported mode for py5
# add_library('pdf')

def setup(): 
    size(400, 400)
    begin_record(PDF, "raw.pdf")

def draw(): 
    line(pmouse_x, pmouse_y, mouse_x, mouse_y)

def key_pressed(): 
    if key == 's':
        end_record()
        exit()

Output:

1 Like

Thank you!
I don’t even know yet if this would do what I want… But yes, being able to export a pdf is one of the things to try for my original goal: Exporting my processing sketches as high resolution and high dpi tif files or pdfs. Incidentally, I also got into py5 yesterday. But I can’t get it to run. Some problem with the jvm which is another issue.
Trying to do anything with py5 in thonny gives me a long error. The only thing that seems to point to the problem is this part:

‘jvm version’: (0, 0, 0)

Maybe some env variable trouble.
Unfortunately, what I want to do here just keeps adding new problems. So until I get py5 to work so I can get pdfs to work so I can see if that allows me to get high res images… I can’t tell if this is what I want :weary:

Please go to this website and describe your issue with setting up py5:
https://github.com/py5coding/py5generator/discussions

While you can’t run py5, you can easily convert @svan’s code by renaming snake_case names to lowerUpperCase names:

add_library('pdf')

def setup(): 
    size(400, 400)
    beginRecord(PDF, "raw.pdf")

def draw(): 
    line(pmouseX, pmouseY, mouseX, mouseY)

def keyPressed(): 
    if key == 's' or key == ' ':
        endRecord()
        exit()