download(file, template, [preview]) Last updated: 26. Apr 2026
API only function
Produces a file using the specified template (HTML, PDF etc) and initiates the file download in the browser.
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | Absolute path to file. |
| template | string | Name of the template to use to generate this file's download. |
| preview (optional) | bool | Default false, returns a preview and not a download. Meaning it will show / preview in the browser. |
Returns
Starts a file download immidiatelly in the API call and aborts further execution of code in the script.
Example
Code example (JS)
JS is normal JavaScript either running in the browser or on the Docly™ server.// Generate a PDF download for a specific Docly document
docly.download("somefile", "Template name.html.pdf");