# Creating multi-page PDFs in Python mode

**URL:** https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447
**Category:** Processing.py
**Created:** [August 7, 2018, 5:17pm UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447 "2018-08-07T17:17:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pxlmnkeee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pxlmnkeee/32/864_2.png) [@pxlmnkeee](https://discourse.processing.org/u/pxlmnkeee)
#### Post date: [August 7, 2018, 5:17pm UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447/1 "2018-08-07T17:17:41Z")

</div>

Hello there intrepid Processing community!

I have a question about creating multi-page PDFs in Processing:

I’ve tried to modify the code from the Java implementation with limited success. I’ve created an empty PDF file with the code below, and a mostly blank PDF by using size(400,400,PDF,‘output.pdf’)

```auto
add_library('pdf')

pdf = createGraphics(100, 100, PDF, 'simple.pdf')
    

pdf.beginDraw()
pdf.background(100)
for index in range(1,10):
    pdf.beginDraw()
    pdf.stroke(255)
    pdf.line(5,5, index * .5, height-index)
    pdf.endDraw()
    pdf.nextPage()

```

I am able to create single page PDF files by declaring the PDF renderer in size(), but I want to create multi-page PDFs. I guess I’m not sure how to reference the pdf to call nextPage() if I don’t declare it explicitly like in this example.

Thanks for any insight you marvelous people might have!

---

<div class="post-metadata">

### Author: ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)
#### Post date: [August 8, 2018, 7:03am UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447/2 "2018-08-08T07:03:48Z")

</div>

This worked for me:

```python
add_library('pdf')

pdf = beginRecord(PDF, 'simple.pdf')
    
for index in range(1,10):
    background(100)
    stroke(255)
    line(5,5, index * .5, height-index)
    if index < 9:
        pdf.nextPage()
    
endRecord()

```

I added that if statement to avoid a blank page. Maybe there’s a better solution.

---

<div class="post-metadata">

### Author: ![pxlmnkeee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pxlmnkeee/32/864_2.png) [@pxlmnkeee](https://discourse.processing.org/u/pxlmnkeee)
#### Post date: [August 8, 2018, 5:59pm UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447/3 "2018-08-08T17:59:11Z")

</div>

NICE! I missed the importance of including the begin and endRecord functions. Works like a charm. Thanks hamoid, definitely going to check out some of your tutorial videos as well!

An additional question: If I wanted to poke around in the source for the PDF library to see what other methods were available, where would I find that?

Thanks again!

---

<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: [August 8, 2018, 6:18pm UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447/4 "2018-08-08T18:18:41Z")

</div>

> [@pxlmnkeee](#):
>
> … where would I find that?

> <https://github.com/processing/processing/blob/master/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java#L50>

> <https://github.com/processing/processing/blob/master/core/src/processing/awt/PGraphicsJava2D.java#L52>

---

<div class="post-metadata">

### Author: ![pxlmnkeee](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pxlmnkeee/32/864_2.png) [@pxlmnkeee](https://discourse.processing.org/u/pxlmnkeee)
#### Post date: [August 8, 2018, 6:26pm UTC](https://discourse.processing.org/t/creating-multi-page-pdfs-in-python-mode/2447/5 "2018-08-08T18:26:03Z")

</div>

GoToLoop dropping the knowledge again!

Thank you.
