# Convert HTML to PDF — PDFCrowd

> Convert URL or HTML to PDF. See docs

- Key: `pdfcrowd-html-to-pdf`
- Type: Action (Write)
- Version: 0.1.0
- App: PDFCrowd (`pdfcrowd`) — https://pipedream.com/apps/pdfcrowd.md
- This page (HTML): https://pipedream.com/apps/pdfcrowd/actions/html-to-pdf
- Hints: open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/pdfcrowd/actions/html-to-pdf/html-to-pdf.mjs

## Description

Convert URL or HTML to PDF. [See docs](https://pdfcrowd.com/api/)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `url` | `string` | No | The URL to convert. Must be publicly accessible. |
| `htmlString` | `string` | No | Raw HTML content to convert to PDF. |
| `outputFilename` | `string` | No | The filename for the generated PDF. |
| `pageSize` | `string` | No | Set the output page size using standard formats (A4, Letter, A3, etc.).... |
| `pageWidth` | `string` | No | Set custom page dimensions when standard sizes don't fit your needs.... |
| `pageHeight` | `string` | No | Set custom page height for specific formats like receipts, banners, or... |
| `orientation` | `string` | No | Set the output page orientation to portrait or landscape. Use landscape... |
| `marginTop` | `string` | No | Control white space at the top of the page. Increase for header space,... |
| `marginRight` | `string` | No | Control white space on the right edge of the page. Increase for... |
| `marginBottom` | `string` | No | Control white space at the bottom of the page. Increase for footer... |
| `marginLeft` | `string` | No | Control white space on the left edge of the page. Increase for... |
| `contentViewportWidth` | `string` | No | Set the viewport width for formatting the HTML content when generating... |
| `customCss` | `string` | No | Apply custom CSS to the input HTML document to modify the visual... |
| `customJavascript` | `string` | No | Run a custom JavaScript after the document is loaded and ready to... |
| `elementToConvert` | `string` | No | Convert only the specified element from the main document and its... |
| `showExpertOptions` | `boolean` | No | Enable to show advanced conversion options |
| `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": "pdfcrowd",
      },
    },
  },
)

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: "pdfcrowd-html-to-pdf",
  arguments: {
    url: "URL",
    htmlString: "HTML Content",
  },
})
```

**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: "pdfcrowd-html-to-pdf",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    pdfcrowd: { authProvisionId: "apn_xxxxxxx" },
    url: "URL",
    htmlString: "HTML Content",
  },
})

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": "pdfcrowd-html-to-pdf",
    "configured_props": {
      "pdfcrowd": { "authProvisionId": "apn_xxxxxxx" },
      "url": "URL",
      "htmlString": "HTML Content"
    }
  }'
```

---

- App: https://pipedream.com/apps/pdfcrowd.md · All apps: https://pipedream.com/apps
