# Generate PDF — HTML 2 PDF

> Creates a PDF from a URL or HTML string. See the documentation

- Key: `html_2_pdf-generate-pdf`
- Type: Action (Write)
- Version: 0.0.3
- App: HTML 2 PDF (`html_2_pdf`) — https://pipedream.com/apps/html-2-pdf.md
- This page (HTML): https://pipedream.com/apps/html-2-pdf/actions/generate-pdf
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/html_2_pdf/actions/generate-pdf/generate-pdf.mjs

## Description

Creates a PDF from a URL or HTML string. [See the documentation](https://www.html2pdf.co.uk/api-documentation)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | No | The URL you want to convert to PDF. |
| `html` | `string` | No | The HTML you want to convert to PDF. |
| `header` | `string` | No | Header in HTML format. |
| `footer` | `string` | No | Footer in HTML format. |
| `pageOffset` | `integer` | No | Number to offset your page number |
| `pageSize` | `string` | No | The standard page formats. |
| `orientation` | `string` | No | The page orientation. |
| `width` | `string` | No | Custom width (overrides 'Page Size'). |
| `height` | `string` | No | Custom height (overrides 'Page Size'). |
| `top` | `string` | No | You need one if you want to display a header. |
| `bottom` | `string` | No | You need one if you want to display a footer. |
| `left` | `string` | No | Left margin. |
| `right` | `string` | No | Right margin. |
| `unit` | `string` | No | Unit for the custom width, height and margins. |
| `cssMediaType` | `string` | No | The layout CSS media type. |
| `optimizeLayout` | `boolean` | No | Set this to true if you want us to auto-optimize your layout. This helps static items on your page to only show up once, instead of on every page. |
| `lazyLoad` | `boolean` | No | Set this to true if you want our software to wait for content to lazy load. |
| `waitTime` | `integer` | No | Time in milliseconds that you want our software to wait after the page is loaded. You typically use this when you have long running JavaScript for graphs and tables. |
| `css` | `string` | No | Use custom CSS to overwrite the default styles of your page. |
| `syncDir` | `dir` | Yes | SyncDir |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "html_2_pdf",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "html_2_pdf-generate-pdf",
  arguments: {
    url: "URL",
    html: "HTML",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "html_2_pdf-generate-pdf",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    html_2_pdf: { authProvisionId: "apn_xxxxxxx" },
    url: "URL",
    html: "HTML",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "html_2_pdf-generate-pdf",
    "configured_props": {
      "html_2_pdf": { "authProvisionId": "apn_xxxxxxx" },
      "url": "URL",
      "html": "HTML"
    }
  }'
```

---

- App: https://pipedream.com/apps/html-2-pdf.md · All apps: https://pipedream.com/apps
