# Create from Script

Include the code below in any area where server-side scripting is allowed in order to generate & attach a PDF file.

```javascript
var pdfHelper = new x_yala_pdf.PDFGenerator();
var resultData = pdfHelper.generateFromHTMLWithSourceAndAttach(pdfTemplate, fileName, sourceRecord, attachRecord);
```

* **pdfTemplate**: GlideRecord of the **HTML to PDF Merge Template** to use
* **fileName**: File name of the resulting attachment
* **sourceRecord**: Source GlideRecord from which to derive any dynamic data in the PDF
* **attachRecord**: Target GlideRecord where the PDF file should be attached


---

# 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://docs.yansalabs.com/pdf-generator/technical-docs/generating-a-pdf-document/create-from-script.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.
