# PDF: Create

Create an HTML container with ID to render the graphical context element

```
<div id="myPdf"> </div>
```

### Create PDF renderer

To create the PDF, invoke **pdfLayer** method with ContainerID "#myCanvas". It returns the Canvas2D renderer instance. For more details on **canvasLayer** please refer: **API Reference -> Layers -> Canvas Layer** Page.&#x20;

```
let renderer = i2d.pdfLayer('#myPdf', {
                                    # Config
                                     height: 800,
                                     width: 500,
                                     info: { 
                                           title: "I2Djs Pdf",
                                           author: "I2Djs" },
                                     margin: 5,
                                     defaultFont: "Helvetica" 
                                }, { 
                                    # Layer Config
                                     onUpdate: () => {} 
                                });
```

### **Create Page**

**renderer.addPage()** api creates pdf Page and returns the page handler.&#x20;

```
let pageHandler = renderer.addPage({})
```

### **Create elements:**

**pageHandler.createEl()** API creates Element of type '**el**' with '**attr'** attributes and '**style'** properties. In the below example we are creating **Circle** with attributes specified in the **attr** object and styles in the **style** object.

```
let circle = pageHandler.createEl({
    el: 'circle',
    attr: {
        r: 50,
        cx: renderer.width / 2,
        cy: renderer.height / 2
    },
    style: {
        fillStyle: '#ff0000'
    }
})
```

To create multiple circles based on Data array - call **createEls(DataArray, ElementConfig)**

```
let circle = pageHandler.createEls([1,2,3,4], {
    el: 'circle',
    attr: {
        r: 50,
        cx: function (d) { return d * 100 },
        cy: function (d) { return d * 100 }
    },
    style: {
        fillStyle: '#ff0000'
    }
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nswamy14.gitbook.io/i2djs-v5/tutorial-point/pdf-create.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
