# PDF Wizard (Standard Forms)

<div><figure><img src="https://2707432902-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGZA5kgM4oTQMrpISbVT3%2Fuploads%2FWhzJW0tU74ehsXHdHrzq%2F149.jpg?alt=media&#x26;token=5a416ec3-ffe4-47c1-983c-47112fd30e8c" alt=""><figcaption><p>PDF Wizard (w/o Edit Step)</p></figcaption></figure> <figure><img src="https://2707432902-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGZA5kgM4oTQMrpISbVT3%2Fuploads%2FC4bffTC51HPl5jotdJIA%2F147.jpg?alt=media&#x26;token=41407087-0e8e-4bce-988f-2d0225764e10" alt=""><figcaption><p>PDF Wizard (w/ Edit Step)</p></figcaption></figure></div>

In order to copy the **Generate PDF** UI Action for standard forms:

1. Copy the wizard formatter
   1. Visit **System UI -> Formatters** in the left nav. Open the formatter titled 'PDF Generator'.
   2. Change the **Table** to match the table where you wish to place the button that will open the wizard. Insert-and-Stay a new copy of the formatter.
   3. Visit the table where you placed the formatter.
   4. Right-click the form header and select **Configure -> Form Layout**. Add the 'PDF Generator' formatter to the form (it is not visible, so you can add it anywhere you like)
2. Copy the wizard button
   1. Visit **Yansa PDF Generator -> General Settings** in the left nav.
   2. Right-click the form header and select **Configure -> UI Actions**.
   3. Select & open the UI Action titled 'Generate PDF (Sample).
   4. Update the **Name** and **Table** fields to match the table where you wish to place the button that will open the wizard. Following the instructions in the **Script** field, update code values to accommodate your needs (see below for details on available customizations). Insert and Stay to create a new copy of the UI Action.
3. Visit the standard form view for a record on the specified table. Click the button to open the **Generate PDF** wizard.

### Customization Options

By default, the **Generate PDF** UI Action will have a **Script** similar to below:

```javascript
function renderModal() {
    var pdfModal = new YansaPDFUI();
    pdfModal.setSourceTable('sys_user');
    pdfModal.render();
}
```

There are a number of methods on the **YansaPDFUI** object (in this example, 'pdfModal') that you may use to customize the behavior of the wizard.

Customize the **Select Template** step:

* **pdfModal.setSelectStepDisplay(flag: boolean):** Show/hide the first 'Select template' step. Otherwise, template must be pre-set *\[default: true]*
* **pdfModal.setPDFTemplate(sysId: string)**: Preset the selected template
* **pdfModal.setPDFTemplateReadOnly(flag: boolean):** Display the 'Select template' step, but enable/disable it as read-only *\[default: false]*
* **pdfModal.setPDFTemplateDisplay(flag: boolean):** Display the 'Select template' step, but show/hide the select box *\[default: true]*

Customize the **Merge Data** step:

* **pdfModal.setMergeStepDisplay(flag: boolean):** Show/hide the second 'Merge data into PDF' step. Otherwise, data source/record must be pre-set *\[default: true]*
* **pdfModal.setSourceTable(tableName: string, includeExtensions: boolean):** Set the source table for merge data
* **pdfModal.setSourceRecord(tableName: string, sysId: string):** Set the source table & record for merge data
* **pdfModal.setMergeReadOnly(flag: boolean):** Enable/disable the 'Merge data into PDF' step as read-only *\[default: false]*
* **pdfModal.setPDFDataSource(sysId: string):** Set data source for merge data. *(Note: Only applies to label printing)*

Customize the **Edit PDF** step:

{% hint style="info" %}
An optional 'Edit' step can be enabled wherein the content of the merged PDF document can be changed prior to the save/download step. This can be useful for situations where customization of the merged template is needed prior to finalization.
{% endhint %}

* **pdfModal.enableEdit():** Enable editing the merged PDF document prior to save/download *\[default: false]*

Customize the **Save PDF** step:

* **pdfModal.setSaveStepDisplay(flag: boolean):** Show/hide the third 'Save PDF' step *\[default: true]*
* **pdfModal.disableDownload():** Disable the 'Download' option *\[default: false]*
* **pdfModal.enableSaveToCurrent(tableName?: string, sysId?: string):** Enable the 'Attach to current' option. If you provide a table/sysId, it will save to that target record. Otherwise, it saves to current record *\[default: false]*

To reload form on-close of the wizard (to display new attachments, for example), include the following at the bottom of your UI Action script:
