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

**URL:** <https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468>\
**Category:** Processing.py\
**Created:** [December 16, 2024, 6:50pm UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468 "2024-12-16T18:50:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LindowMan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lindowman/32/14031_2.png) [@LindowMan](https://discourse.processing.org/u/LindowMan)\
**Post date:** [December 16, 2024, 6:50pm UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468/1 "2024-12-16T18:50:59Z")

</div>

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:

> **[Exporting High-Resolution Images in Processing](https://sighack.com/post/exporting-high-resolution-images-in-processing)**
>
> A tutorial on two simple ways to export high-resolution images of your artwork in Processing.

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)](https://py.processing.org/reference/beginraw)

```auto
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.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [December 17, 2024, 2:13am UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468/2 "2024-12-17T02:13:06Z")

</div>

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.

```auto
# 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:**

 ![pdf](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/3/9/392c5145c3042eecc695503c2dfd9fefe77e618a.png)

---

<div class="post-metadata">

**Author:** ![LindowMan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lindowman/32/14031_2.png) [@LindowMan](https://discourse.processing.org/u/LindowMan)\
**Post date:** [December 17, 2024, 5:29pm UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468/3 "2024-12-17T17:29:29Z")

</div>

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 😩

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [December 17, 2024, 9:49pm UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468/4 "2024-12-17T21:49:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 17, 2024, 9:56pm UTC](https://discourse.processing.org/t/dpi-and-dimensions-print-ready-images-in-processing-py/45468/5 "2024-12-17T21:56:51Z")

</div>

> [@LindowMan](#):
>
> Incidentally, I also got into py5 yesterday. But I can’t get it to run.

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

```auto
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()

```

> **[beginRecord() / Reference](https://processing.org/reference/beginrecord_)**
>
> Opens a new file and all subsequent drawing functions are echoed to this file as well as the display window. The beginRecord() function requires two parameters, the first is the renderer and th…
