# Html2Pdf MCP

> Html2Pdf converts any public website URL or raw HTML code into professional, pixel-perfect PDF documents using your AI agent. It handles complex layouts, JavaScript execution, and adds security passwords so you can turn web content or formatted reports into shareable files with total layout control.

## Overview
- **Category:** productivity
- **Price:** Free
- **Tags:** pdf-generation, html-to-pdf, web-to-pdf, document-automation, reporting

## Description

Need to take a webpage or a block of code and make it a permanent document? This MCP lets your agent generate professional PDFs on the fly. You don't have to manually copy, paste, and format everything just because you need a report for a client or an article for an archive. Whether you provide a public web link or raw HTML strings—like those used for invoices or resumes—the system captures it exactly how it looks online, down to the precise margins and orientation. It even executes JavaScript on the page before generating the PDF, making sure dynamic content shows up correctly. When your agent calls this through Vinkius, you get a powerful tool that lets you control everything, from setting A4 or Letter size to adding user passwords and restricting printing rights. The result is clean, stable, print-ready documentation every single time.

## Tools

### generate_pdf
Converts either an entire web URL or raw HTML code into a PDF document and returns the result payload.

## Prompt Examples

**Prompt:** 
```
Convert https://google.com to a PDF in A4 format and landscape orientation.
```

**Response:** 
```
I've initiated the PDF generation for Google.com with landscape orientation. The document is being processed and will be returned as a base64 encoded string.
```

**Prompt:** 
```
Generate a PDF from this HTML code: '<h1>Invoice #123</h1><p>Total: $50</p>' and name the file 'invoice.pdf'.
```

**Response:** 
```
Processing your HTML invoice... I've generated the PDF with the filename 'invoice.pdf'. You can now access the document payload.
```

**Prompt:** 
```
Create a password-protected PDF of https://example.com using 'secret123' as the password.
```

**Response:** 
```
Securing your document... I've generated a password-protected PDF for the requested URL. The file is encrypted and will require 'secret123' to be opened.
```

## Capabilities

### Convert Web Links to PDFs
Captures a public website URL as a pixel-perfect PDF snapshot.

### Build Documents from Raw HTML
Generates custom documents like invoices or certificates using raw HTML code strings.

### Control Layout and Security
Allows setting specific page formats, orientations, and adding password protection to the resulting file.

## Use Cases

### Archiving a Web Article
A content creator needs to archive an entire web article before it gets updated. Instead of printing the page (which often misses headers or footers), they ask their agent to use `generate_pdf` with just the public URL, guaranteeing a clean, permanent PDF snapshot.

### Creating Client Invoices
A developer needs to generate 50 invoices nightly. Rather than writing code to handle all the styling and layout changes for every single one, they use `generate_pdf` with the raw HTML template, specifying the client's name and total amount.

### Securing a Business Proposal
A business analyst finishes a proposal online but needs it to be secure before emailing it. They ask their agent to use `generate_pdf` on the source URL, adding both a user and owner password so only authorized people can open or print it.

### Converting Dynamic Dashboards
A BA has a dashboard that relies heavily on JavaScript for data visualization. They send the URL to `generate_pdf`, which executes the necessary JS, ensuring the PDF contains the *live* visual state of the data.

## Benefits

- Don't worry about JavaScript breaking your report. The tool executes JS before generating the PDF, ensuring dynamic content (like charts or pop-up data) appears correctly.
- Stop manually reformatting documents. You can send raw HTML and control every detail—from font size to page orientation—to build professional invoices or resumes automatically.
- Protect your sensitive reports by adding user passwords and owner passwords directly during the `generate_pdf` call, keeping unauthorized printing or copying at bay.
- Handle massive jobs in the background. If you're generating a large batch of documents, the MCP supports async callbacks so your agent doesn't time out.
- Achieve perfect print fidelity by specifying exact page formats (A4, Letter) and precise margins for guaranteed professional output.

## How It Works

The bottom line is you give it the source material and tell it how you want the final document to look; it handles the rest of the conversion process.

1. You instruct your agent to convert a source—either a public URL or raw HTML code—and specify desired parameters like size (A4) or orientation.
2. The MCP processes the request, handling tasks like executing JavaScript and rendering complex styles before packaging the content.
3. Your agent receives the final PDF document payload as a base64 encoded string, ready for use.

## Frequently Asked Questions

**How do I use Html2Pdf to convert a public website URL?**
You pass the full, public URL directly to `generate_pdf`. The MCP captures a pixel-perfect snapshot of that webpage as if you printed it professionally.

**Can Html2Pdf handle invoices from raw HTML code?**
Yes. You provide the raw HTML string for your invoice template to `generate_pdf`. This allows you to generate custom documents with full control over styling and layout without needing a separate design tool.

**Does Html2Pdf support password protection?**
Absolutely. When calling `generate_pdf`, you can pass owner passwords and user passwords, making the resulting PDF file encrypted for added security.

**What if my webpage has JavaScript that changes content?**
The MCP handles this by executing JavaScript before generating the PDF. This means dynamic elements or client-side scripts will render correctly in your final document payload.