> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pdf.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Convert

> This section covers the conversion of PDF files to various formats, including text, images, and more.

export const CTAButton = ({href, text, download}) => {
  return <a href={href} download={download} target="_blank" rel="noopener noreferrer" className="text-[20px] font-medium p-5 bg-[#ff4848] text-white rounded-[5px] block w-fit mb-4">
      <span>{text}</span>
    </a>;
};

# [PDF from HTML](/api-reference/pdf-from-html/convert)

## I want to Prevent Images from Breaking Across Pages in HTML to PDF

You want to generate a PDF from HTML without having images split awkwardly across pages.

### Why This Happens

When converting HTML to PDF, especially in long documents, browsers or PDF renderers may automatically break content (like images or `<div>`s) across pages. This results in visual issues where a single image may appear partially on one page and continue on the next.

### How to Keep Images (or Elements) Intact

To prevent this, you'll use a CSS style that instructs the PDF renderer not to break certain elements across pages.

### Step-by-Step Fix

Use the `break-inside:avoid` CSS Rule: Add a `<style>` tag in the HTML head with a rule that prevents elements (like `<div>`, `<p>`, or `<img>`) from splitting.
Inject the CSS Using Profiles: Use the `profiles` parameter to inject the style into your HTML during conversion.

### Example: Preventing Breaks in Zapier or Make

Zapier or Integromat/Make Users:
Set the `Profiles` field to:

```json theme={null}
{"HTMLCodeHeadInject":"<style> @media print { div,p { break-inside: avoid !important; } } </style>"}
```

This will inject the appropriate CSS when converting from HTML.

### For Developers (API)

When using the [/pdf/convert/from/html](/api-reference/pdf-from-html/convert) or [/pdf/convert/from/url](/api-reference/pdf-from-url) endpoints, include the `profiles` parameter like this:

```json theme={null}
{
  "profiles": "{'HTMLCodeHeadInject':'<style> @media print { div,p { break-inside: avoid !important; } } </style>'}"
}
```

This ensures the CSS rule is applied during PDF generation.

### Applies To:

* [/pdf/convert/from/html](/api-reference/pdf-from-html/convert)
* [/pdf/convert/from/url](/api-reference/pdf-from-url)

### Helpful Tips

* Always test the final PDF to confirm formatting appears as expected.
* Combine this method with margin settings or custom page breaks for better layout control.

## How to Convert HTML to PDF with a Custom Page Size

You want to generate a PDF from HTML with a specific page size—such as **4 inches by 6 inches**—instead of the default A4.

### How to Set a Custom PDF Page Size

To generate a PDF at a custom size, use the `paperSize` parameter in your API call or integration.

Example: to create a **4x6 inch** PDF, set:

```json theme={null}
"paperSize": "4in 6in"
```

You can also use other units:

* `px` → `200px 300px`
* `mm` → `100mm 150mm`
* `cm` → `10cm 15cm`
* `in` → `4in 6in`

### API Example

Here’s a sample API request to convert HTML to a **4x6 inch** PDF:

```
POST /v1/pdf/convert/from/html HTTP/1.1
Host: api.pdf.co
x-api-key: YOUR_API_KEY
Content-Type: application/json

{
    "html": "<h1>Hello World!</h1><a href='https://pdf.co'>Go to PDF.co</a>",
    "name": "newDocument.pdf",
    "mediaType": "print",
    "margins": "0",
    "paperSize": "4in 6in",
    "orientation": "Portrait",
    "printBackground": false
}
```

### Zapier

In the HTML to PDF Converter action:

1. Find **Page Size Override**
2. Enter `4in 6in`

### Make / Integromat

In the PDF.co Convert HTML to PDF module:

1. Set **Paper Size** → **Custom**
2. Enter `4in 6in` in the size field

### Helpful Tips

* Always include the unit (e.g., `in`, `mm`, `px`) in `paperSize`
* Use `margins`: `0` for full-page layouts
* Use `printBackground`: `true` if your HTML needs background styles

## How to Keep Form Controls When Converting HTML to PDF

When you convert an HTML page to PDF, **form controls like input fields, checkboxes, and dropdowns appear as static visuals but are not interactive.**

### Why This Happens

The PDF format doesn’t automatically convert HTML form elements into interactive form fields. They’re rendered as plain graphics rather than fillable fields.

### How to Make PDF Forms Fillable

To add interactive form controls, you need to **create form fields in the PDF after converting from HTML.**

**2-Step Workflow:**

1. Convert the HTML to PDF
   Use the [/pdf/convert/from/html](/api-reference/pdf-from-html/convert) API or your preferred HTML-to-PDF tool to generate the static PDF.

2. Add Form Fields to the PDF
   Use the [/pdf/edit/add](/api-reference/pdf-add) API endpoint to insert form fields like textboxes, checkboxes, and dropdowns into the PDF.

### Platform-Specific Guides

* Zapier: Follow this step-by-step guide → [Create Fillable Forms with PDF.co in Zapier](https://pdf.co/create-fillable-form-using-pdf-co-and-zapier)
* Make/Integromat: Follow this tutorial → [Create Fillable Forms with PDF.co in Make](https://pdf.co/create-fillable-forms-integromat)

### Helpful Tips

* Use PDF.co's built-in [PDF Inspector Tool](https://app.pdf.co/pdf-edit-add-helper) to visually test field placement.
* Use exact coordinates for better precision when placing fields.

## I Want to Create Navigation Links Inside a PDF When Using HTML to PDF

### The Issue

You want to add clickable navigation links inside a PDF—such as a table of contents that jumps to a section, or internal links between parts of a long document—but the links aren’t working as expected.

### Why This Happens

When converting HTML to PDF, some users may not realize that internal anchor links (`#marker`) require properly placed markers (`<a name="...">`) in the HTML for the PDF converter to recognize them. Without these, the links won't work in the output file.

### How to Create Navigation Links

To add internal navigation links to your PDF:

1. Add a Marker Where You Want to Jump

Use this in your HTML:

```html theme={null}
<a name="marker1"></a>
```

2. Add a Link to That Marker

Use this in your HTML:

```html theme={null}
<a href="#marker1">Jump to Marker 1</a>
```

### Example: Create a Table of Contents

Here’s a sample HTML that adds navigation to two sections:

```html theme={null}
<!-- Navigation links at the top -->
Navigation:
<a href="#section1">Section 1</a> |
<a href="#section2">Section 2</a>

<!-- Target sections -->
<a name="section1"></a>
<h1>Section 1</h1>
<p>Content for section 1...</p>

<a name="section2"></a>
<h2>Section 2</h2>
<p>Content for section 2...</p>
```

### What Happens in the PDF

Once converted using the HTML to PDF tool, the output PDF will preserve these internal links. Clicking on “Section 1” or “Section 2” in the navigation will jump directly to the respective areas—just like in the original HTML document.

### Helpful Tips

Double-check that both the link (`href="#..."`) and the marker (`name="..."`) match exactly.

* Ensure correct HTML syntax—mismatched quotes or missing closing tags can break links.
* Test in a browser first to confirm links are functioning before converting.

## I Want to Avoid Page Breaks in My PDF

You may be experiencing unwanted page breaks in your generated PDF—such as a section of text or a table being split across two pages.

### Why This Happens

By default, PDFs are set to render in A4. When your content exceeds the default page height, it causes automatic page breaks.

### How to Avoid Page Breaks

To prevent this, you can customize the page size using the paperSize parameter. This ensures the page is long enough to hold all your content without forcing a break.

### Example: Use a Custom Page Size

To avoid page breaks and allow more vertical space, increase the page length.
Set the `paperSize` like this:

```json theme={null}
{
  "paperSize": "6in 15in"
}
```

This sets the page width to 6 inches and the height to 15 inches—enough space for taller content like long tables or paragraphs.

### Helpful Tips

* Adjust `paperSize` according to your content length.
* Use longer page heights to accommodate full content without breaks.
* If using `async: true`, monitor job status for large files.

## I Want to Force a New Page in the Output PDF

You want to make sure that certain content in your PDF always starts on a **new page**, but currently, everything appears continuously without page breaks.

### Why It Happens

When you're generating PDFs from HTML or HTML templates, content flows naturally like a webpage—**without automatic page breaks**—unless you explicitly tell it where to break using specific CSS rules.

### How to Force a New Page

To force a page break in your PDF output, use the following **CSS property** in your HTML:

```css theme={null}
page-break-after: always;
```

This ensures that any element it's applied to will **force the next content to start on a new page**.

### Examples

#### Example 1 — Using a `<div>` tag:

```html theme={null}
<div style="display:block; clear:both; page-break-after:always;"></div>
```

#### Example 2 — Using a `<p>` tag:

```html theme={null}
<p style="display:block; clear:both; page-break-after:always;"></p>
```

These tags act as **"invisible" page breaks** in your layout, ensuring that whatever comes next starts on a new page in the final PDF.

### Helpful Tips

* Apply the style to a `<div>` or `<p>` between sections you want to separate.
* Combine with layout styles like `clear:both` to prevent content from overlapping.

## I Want to Insert a Link into a PDF Created from HTML

You're trying to add a clickable link (like a URL or email address) inside a PDF that was originally generated from HTML.

### Why This Happens

When you convert HTML to PDF, the PDF is generated as a static document. If the original HTML didn't include the link as an anchor tag (`<a>`), or if you want to place a new link in a specific position after conversion, it won't exist in the PDF by default. That's why adding the link requires a second step after conversion.

### How to Insert a Link

To insert a link, you'll use two steps:

1. Convert HTML to PDF

Use the [/pdf/convert/from/html](/api-reference/pdf-from-html/convert) endpoint to generate the PDF from your HTML content.
2\. Add the Link to the PDF

Once the PDF is generated, use the [/pdf/edit/add](/api-reference/pdf-add) endpoint to insert the clickable link.
You'll need to specify the x and y coordinates on the PDF where the link should appear.

### Tip:

Use the [PDF Inspector Tool](https://app.pdf.co/pdf-edit-add-helper) to visually identify the coordinates (x, y) of where you want to place the link.

### Example Workflow

Let's say you want to generate a PDF from HTML and then place a clickable link at the bottom right of the first page:

1. Convert HTML to PDF

Call [/pdf/convert/from/html](/api-reference/pdf-from-html/convert) with your raw HTML or a URL.

2. Add the Link

Call [/pdf/edit/add](/api-reference/pdf-add) with:

* The URL of the newly created PDF.
* The coordinates where you want the link.
* The link itself (e.g., "link": "[https://yourwebsite.com](https://yourwebsite.com)").
* The target page number (e.g., page 1).

### Platform-Specific Related Resources

* Zapier:
  * [How to Add Text and Images with Links to a PDF using Zapier](https://pdf.co/tutorials/add-text-and-images-with-links-to-a-pdf-using-zapier)
  * [How to Process Large HTML to PDF or URL to PDF Conversions in Zapier](https://pdf.co/tutorials/process-large-html-to-pdf-or-url-to-pdf)

* Make/Integromat:
  * [Convert HTML to PDF with PDF.co using Make](https://pdf.co/tutorials#:~:text=Convert%20HTML%20to%20PDF%20with%20PDF.co%20using%20Make)

* Other Integrations: [Contact us](https://pdf.co/support/request?subject=Knowledgebase%20-%20I%20need%20help%20with%20PDF.co) for guidance on specific platforms.

### Helpful Tips

* You can add multiple links in one request by using an array of annotations.
* Use `async: true` for large PDFs to avoid timeout.
* Make sure the coordinates you select fall within the content area of the page.

# [PDF from CSV](/api-reference/pdf-from-document/csv)

## How to Convert a Specific Google Sheets Worksheet to PDF

### You’re Trying to Convert Just One Worksheet

You want to export **only one worksheet** from a Google Sheets document as a PDF file—not the entire spreadsheet.

### How to Convert a Specific Worksheet

To convert a single worksheet from Google Sheets to PDF, you’ll need to construct a custom download URL.

Use the following format:

```
https://docs.google.com/spreadsheets/d/[spreadsheet_id]/export?format=[file_format]&gid=[worksheet_id]
```

Where:

* `[spreadsheet_id]`: The unique ID of your Google Sheets document (found in the URL).
* `[file_format]`: The format you want to export to — in this case, use "pdf".
* `[worksheet_id]`: The specific gid (worksheet ID) of the tab you want to export.

### Example

If you want to download a worksheet with:

* Spreadsheet ID: `12345`
* Worksheet ID (gid): `6789`

Your URL will look like this:

```
https://docs.google.com/spreadsheets/d/12345/export?format=pdf&gid=6789
```

Opening this link in a browser or using it in a PDF.co task will generate a PDF of just that worksheet.

### Platform-Specific Related Resources

* Zapier: [Convert Specific Excel Worksheet to PDF using PDF.co and Zapier](https://pdf.co/tutorials/convert-specific-excel-worksheet-to-pdf-zapier)
* Make: [Convert Specific Excel Worksheet to PDF using PDF.co and Make](https://pdf.co/tutorials/convert-specific-excel-worksheet-to-pdf-make)

### Helpful Tips

* Make sure the Google Sheet is **shared publicly or with anyone with the link** so the system can access it.
* To automate this in workflows, pass the export link dynamically using spreadsheet/worksheet metadata.

## I Want to Convert Google Sheets/Excel to PDF

You're trying to convert a Google Sheet or Excel file into a PDF—possibly to share, archive, or prepare a report. However, you're not sure how to get it formatted correctly, or how to convert specific sheets or orientation (landscape vs portrait).

### How to Convert Google Sheets/Excel to PDF

To convert a spreadsheet to a PDF, you’ll typically follow one of two methods:

* Use an automation platform like Zapier or Make
* Use a direct download link or API call

### Zapier

Use these step-by-step guides to set up automated spreadsheet-to-PDF conversions:

* [Convert Google Sheets/Excel to PDF in Landscape](https://pdf.co/save-excel-as-pdf-landscape-zapier)
* [Convert a Specific Worksheet in Excel to PDF](https://pdf.co/convert-specific-excel-worksheet-to-pdf-zapier)
* [Convert Google Form Responses (via Sheets) to PDF](https://pdf.co/tutorials/how-to-convert-google-forms-to-pdf-using-zapier)

### Integromat / Make

If you're using Make (formerly Integromat), follow this resource:

* [Convert a Specific Excel Worksheet to PDF in Make](https://pdf.co/convert-specific-excel-worksheet-to-pdf-make)

### Web API Code Samples

If you're working with the PDF.co API directly, these code samples will help:

* [JavaScript, Python, cURL Examples](https://github.com/pdfdotco/pdf-co-api-samples/tree/master)

### Alternative Method: Use Google Sheet Direct Download Link

You can also convert Google Sheets to PDF using a simple direct link:

```
https://docs.google.com/spreadsheets/d/INSERT_FILE_ID/export?format=pdf&portrait=false
```

Replace `INSERT_FILE_ID` with your sheet's actual ID.
To force landscape, add `&portrait=false` to the URL.

### Helpful Tips

* Use Zapier/Make to automate recurring conversions.
* In API mode, control page size, margins, and orientation.
* Make sure your spreadsheet is publicly accessible or properly authenticated if you're using a URL.

# [PDF to JSON](/api-reference/pdf-to-json/basic)

## How to Extract Hyperlinks and URLs from a PDF

You can use the `/v1/pdf/convert/to/json2` endpoint with the `profiles` parameter to return only hyperlink elements from the PDF.

### Request Configuration

```json theme={null}
{
  "url": "https://example.com/your-file.pdf",
  "inline": true,
  "profiles": "{ \"OutputStructure\": \"OnlyLinks\", \"OutputTransformation\": \"$..text\" }"
}
```

### cURL Example

```bash theme={null}
curl --location --request POST "https://api.pdf.co/v1/pdf/convert/to/json2" \
--header "Content-Type: application/json" \
--header "x-api-key: YOUR_API_KEY" \
--data-raw '{
  "url": "https://example.com/your-file.pdf",
  "inline": true,
  "profiles": "{ \"OutputStructure\": \"OnlyLinks\", \"OutputTransformation\": \"$..text\" }"
}'
```
