> For the complete documentation index, see [llms.txt](https://jona-projects.gitbook.io/kiwicalc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jona-projects.gitbook.io/kiwicalc/pdf-worksheets/creating-pdfs.md).

# Creating PDFs

#### PDFWorksheet

```python
class PDFWorksheet:
                    
```

The `PDFWorksheet` class represents the whole PDF document.

**Properties**

* `pages` - a list of the pages in the document of type `PDFPage`.
* `num_of_pages` - the number of pages in the document (including the solutions)
* `current_page` - the current page that we're working on, of type `PDFPage`

**Create a new `PDFWorksheet` object**

You can create a new `PDFWorksheet` object via the `__init__()` method. Here are the parameters of the method:

* `title` - a string for the title of the first page. Default is `"Worksheet"`.
* `ordered` - whether to number the exercises and the solutions. Default is `True`.

Just pay attention that when you create a new document, the first page is created automatically as well, so you don't have to add the first page.

**`add_exercise()`**

The method accepts an exercise of type `PDFExercise` or one of its subclasses, and adds it to the current page.

**`end_page()`**

Ending the current page. This will make sure to add a page of solutions if needed

**`next_page()`**

Add a new page, and move to the new page. After calling it, a new blank page is added and we can add exercises to it.

**`create()`**

creates the PDF file in the given path. If the path is not given, the PDF file will be generated in a random path in the current working directory.

#### PDFPage

```python
class PDFPage:
                    
```

This class represents a single page in the PDF document. Usually, you won't have to access it and modify it directly.

**Properties**

* `exercises` - a list of the exercises in the page.
* `title` - the title of the page

**Create a new `PDFPage`**

Parameters to the constructor:

* `title` - the title of the page. Default is `"Worksheet"`
* `exercises` - a list of exercises in the page. Default is `None`

**Iterate on the page**

You can iterate on the list of the exercises in the page directly. For instance:

```python
for exercise in page:
    ....
                    
```

#### PDFExercise

```python
class PDFExercise:
                    
```

This class represents an exercise in a PDF page.

**Properties:**

* `exercise` - A string that represents the exercise.
* `number` - The serial number of the exercise in the document.
* `dtype`- The datatype of the exercise (of type str)
* `solution` - A string that represents the solution of the exercise.
* `has_solution` - Whether the exercise comes with a solution or not.
* `lang` - the language of the exercise and the solution ( if there is one).

**Creating a new exercise**

Usually, you'll be creating new exercises via the subclasses. Here are the available exercises as for this version:

* `PDFLinearFunction` - Analyze a linear function. Here is the signature of the constructor:

  ```python
  def __init__(self, with_solution: bool = True, lang: str = 'en'):
                              
  ```

  For instance:

  ```python
  exercise = PDFLinearFunction()
                              
  ```

* `PDFLinearIntersection` - Find intersection between two linear functions. Here is the signature of the constructor:

  ```python
  def __init__(self, with_solution=True, lang='en'):
  ```

* `PDFLinearSystem` - Solve a linear system of equations. Here is the signature of the constructor:

  ```python
  def __init__(self, with_solution=True, lang='en', num_of_equations=None, digits_after: int = 0):
                              
  ```

  For instance:

  ```python
  exercise = exercise = PDFLinearSystem()
                              
  ```

* `PDFLinearFromPoints` - Find a linear function from two points. Here is the signature of the constructor:

  ```python
  def __init__(self, with_solution: bool = True, lang: str = "en"):
                              
  ```

* For instance:

  <pre class="language-python"><code class="lang-python"><strong>exercise = PDFLinearFromPoints()
  </strong>                            
  </code></pre>

* `PDFLinearFromPointSlope` - Find a linear function from a point and a given slope. Here is the signature of the constructor:

  ```python
  def __init__(self, with_solution: bool = True, lang: str = "en"):
                              
  ```

  For instance:

  ```
                                  exercise = PDFLinearFromPointAndSlope()
                              
  ```

* `PDFPolyFunction` - Analyze a polynomial function. Here is the signature of the method:

  ```
                                  def __init__(self, with_solution: bool = True, degree: int = None, lang: str = 'en'):
                              
  ```

  For instance:

  ```
                                  exercise = PDFPolyFunction()
                              
  ```

* `PDFQuadraticFunction` - Analyze a quadratic function. Here is the signature of the method:

  ```
                                  def __init__(self, with_solution: bool = True, lang: str = "en"):
                              
  ```

  For instance:

  ```
                                  exercise = PDFQuadraticFunction()
                              
  ```

* `PDFCubicFunction` - Analyze a cubic function. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution: bool = True, lang: str = "en"):
                              
  ```

  For instance:

  ```
                                  exercise = PDFCubicFunction()
                              
  ```

* `PDFQuarticFunction` - Analyze a quartic function. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution: bool = True, lang: str = "en"):
                              
  ```

  For instance:

  ```
                                  exercise = PDFQuarticFunction()
                              
  ```

* `PDFLinearEquation` - Solve a linear equation. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution=True, number: int = None):
                              
  ```

  For instance:

  ```
                                  exercise = PDFLinearEquation()
                              
  ```

* `PDFQuadraticEquation` - Solve a quadratic equation. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution=True, number: int = None):
                              
  ```

  For instance:

  ```
                                  exercise = PDFQuadraticEquation()
                              
  ```

* `PDFCubicEquation` - Solve a cubic equation. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution=True, number: int = None):
                              
  ```

  For instance:

  ```
                                  exercise = PDFCubicEquation()
                              
  ```

* `PDFQuarticEquation` - Solve a quartic equation. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution=True, number: int = None):
                              
  ```

  For instance:

  ```
                                  exercise = PDFQuarticEquation()
                              
  ```

* `PDFPolyEquation` - Solve a polynomial equation. Here is the signature of the constructor:

  ```
                                  def __init__(self, with_solution=True, number: int = None):
                              
  ```

  For instance:

  ```
                                  exercise = PDFPolyEquation()
                              
  ```

Here is a full example of creating a worksheet.

```python
pdf_worksheet = PDFWorksheet("Functions")

pdf_worksheet.add_exercise(PDFCubicFunction(lang='es'))
pdf_worksheet.add_exercise(PDFQuadraticFunction())
pdf_worksheet.add_exercise(PDFLinearFromPointAndSlope())

pdf_worksheet.end_page()
pdf_worksheet.next_page("Equations")

for _ in range(10):
    pdf_worksheet.add_exercise(PDFLinearEquation())
    pdf_worksheet.add_exercise(PDFQuadraticEquation())
    
pdf_worksheet.end_page()
pdf_worksheet.create("worksheetExample.pdf")
```
