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

# PDF from Markdown

> Convert inline Markdown or a hosted Markdown document into a PDF with tables, code, images, and CJK text.

> [!NOTE]
>
> **Try it live:** [PDF from Markdown API Tester](https://developer.pdf.co/api-tester/pdf-from-markdown.md). Submit a conversion request from your browser.

## `POST /v1/pdf/convert/from/md`

Convert one Markdown document into one PDF. Provide the Markdown text directly or a public HTTP(S) URL to a UTF-8 Markdown document. Output uses **Letter portrait** pages, automatic pagination, and a fixed stylesheet.

Conversion costs **25 credits per call**, regardless of the output page count. For Job Check charges, see [Background Job Check](https://developer.pdf.co/api/job-check.md#response-fields). See [Credits per API Function](https://developer.pdf.co/api/credits-per-api-function.md).

## Quick start

A request containing only `url` is enough to start a conversion.

```json Request body theme={null}
{
  "url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md"
}
```

Use the sample URL above or your own publicly accessible Markdown file.

## Asynchronous only

> [!WARNING]
>
> This endpoint has no synchronous mode. Every request runs in the background, and the first response returns a `jobId` rather than the PDF URL.

An accepted job follows these stages unless input inspection or conversion fails:

1. You submit the request, and PDF.co accepts the job and returns its `jobId`.
2. The source Markdown is converted to PDF.
3. The job is finalized, and the PDF link becomes available.

Retrieve the final result by polling the [Background Job Check endpoint](https://developer.pdf.co/api/job-check.md) with the `jobId`, or by supplying a `callback` URL. See [Webhooks & Callbacks](https://developer.pdf.co/api/webhooks.md).

## Request body

> [!NOTE]
>
> Attributes should be inside JSON for POST request. for example: `{ "url": "https://example.com/file1.md" }` There are no query parameters.
>
> To see the request size limits, please refer to the [Request Size Limits](https://developer.pdf.co/api/url-input-and-request-limits.md#pdf-co-request-size).

> [tab] URL input
>
> > [!WARNING]
> >
> > For this endpoint, the downloaded file must contain UTF-8 Markdown and be no larger than **4 MiB (4,194,304 bytes)**. Use a direct HTTP(S) URL without embedded credentials. Do not provide both `url` and `markdown`.
>
> **url** `string`
>
> URL to the source file [`url` attribute](https://developer.pdf.co/api/url-input-and-request-limits#supported-file-sources).

> [tab] Inline Markdown
>
> > [!WARNING]
> >
> > Inline Markdown must be UTF-8 and no larger than **4 MiB (4,194,304 bytes)**. Whitespace-only input is rejected.
> >
> > Use absolute public HTTP(S) URLs or supported base64 data URLs for images. Inline Markdown has no source URL against which relative paths can be resolved.
> >
> > JSON escaping and other request fields can make an inline request exceed transport limits even when its decoded Markdown fits. Use a hosted Markdown URL or split the document when the error recommends it.
>
> **markdown** `string`
>
> Markdown text to convert into a PDF. Preserve meaningful spaces and line breaks in your JSON string.

**callback** `string`

Callback URL notified when the job finishes. Use it instead of polling. See [Webhooks & Callbacks](https://developer.pdf.co/api/webhooks.md).

Use an HTTP(S) URL. URLs with embedded credentials are rejected for this endpoint.

**name** `string`

Output file name. If omitted, the output is named `markdown.pdf`.

**expiration** `integer` (default: 60)

Number of minutes before the temporary output URL expires. After this period, generated files are deleted from [PDF.co Temporary Files Storage](https://developer.pdf.co/api/file-upload/overview.md). The maximum retention depends on your subscription plan and is capped at seven days for Markdown to PDF. Use an integer from `1` to `10080`.

## Responses

HTTP `200` confirms acceptance, not completed conversion. Successful submissions use numeric `status`; error responses can use the string `"error"` and put the numeric code in `errorCode`. The `429` rate-limit response has no `status` field. In all cases, rely on the HTTP status code of the response. Background job states are separate strings. The example IDs, durations, balances, and output URLs on this page are illustrative. Error messages can vary by cause. The `429` example uses an illustrative rate limit; wait for the `Retry-After` interval before retrying.

```json Submission response theme={null}
{
  "error": false,
  "status": 200,
  "duration": 120,
  "jobId": "EXAMPLEJOBID0123456789ABCDEFGHIJ--168-300",
  "credits": 25,
  "remainingCredits": 9975
}
```

| Field | Type | Description |
| - | - | - |
| `error` | boolean | Indicates whether an error occurred (`false` means success). |
| `status` | integer or string | The numeric status code of the operation, or the string `"error"`; when it is `"error"`, the numeric code is in `errorCode`. The `429` rate-limit response has no `status` field. In all cases, rely on the HTTP status code of the response. |
| `errorCode` | integer | Numeric error code when `status` is `"error"`. The `429` rate-limit response omits this field. |
| `message` | string | Error message describing the failure. |
| `duration` | integer | Time taken to accept the request, in milliseconds. It does not include conversion. |
| `jobId` | string | Identifier of the background job. |
| `credits` | integer | Credits consumed by the conversion request. See [Credits per API Function](https://developer.pdf.co/api/credits-per-api-function.md). |
| `remainingCredits` | integer | Credits remaining for the account. |

The initial response has no output `url`, `outputLinkValidTill`, or `pageCount`. Those values are available only when the PDF has been produced.

When conversion completes, [Background Job Check](https://developer.pdf.co/api/job-check.md) and the callback payload return the converted PDF, as shown below. A successful result can contain warnings while still returning a usable PDF. This example shows legacy billing, with a 2-credit Job Check.

```json Final job result theme={null}
{
  "status": "success",
  "message": "Success",
  "pageCount": 2,
  "url": "https://example.com/output/garden-report.pdf",
  "outputLinkValidTill": "2026-11-11T13:00:00Z",
  "warnings": [
    {
      "code": "IMAGE_OMITTED",
      "message": "Image 'embedded image' was omitted from the PDF: The image is corrupt or cannot be decoded safely. Replace it with a valid PNG or JPEG, then convert again."
    }
  ],
  "jobId": "EXAMPLEJOBID0123456789ABCDEFGHIJ--168-300",
  "jobDuration": 2500,
  "duration": 20,
  "credits": 2,
  "remainingCredits": 9973
}
```

| Field | Type | Description |
| - | - | - |
| `status` | string | Job state: `working`, `success`, `failed`, or `aborted`. |
| `message` | string | Job status or failure explanation. |
| `jobId` | string | ID used to check the background job. |
| `url` | string | Temporary PDF download URL, available after successful conversion. |
| `pageCount` | integer | Actual output PDF page count, not a billing multiplier. |
| `outputLinkValidTill` | string | Download-link expiration timestamp, when available. |
| `warnings` | array of objects | Optional notices with `code` and `message`. Job Check omits this field when there are no warnings. |
| `credits`, `remainingCredits` | integer | Credit delta for this request and remaining account balance. The example shows legacy billing with a 2-credit Job Check. |
| `jobDuration`, `duration` | integer | Background processing and Job Check request durations in milliseconds, when available. |

Submission errors and failed jobs are different. HTTP `200` from job-check can contain `status: failed`. Read the job status and message. See [Background Job Check](https://developer.pdf.co/api/job-check.md) for job states and [Response Codes](https://developer.pdf.co/api/response-codes.md) for submission HTTP responses.

If a failed conversion is refunded, the response can show a negative `credits` value. Do not calculate conversion cost from the PDF page count or assume every poll is free. A successful PDF with permitted omissions remains a chargeable conversion.

## Formatting, images, and limitations

The renderer supports headings, paragraphs, emphasis, lists, tables, code blocks, hyperlinks, footnotes, CJK text, and supported passive HTML. Long documents paginate automatically. Supported HTML page breaks can start a new page; code or tables taller than a page may continue onto the next page.

* **Images:** PNG, JPEG, and SVG can use public HTTP(S) URLs or supported base64 data URLs. SVG is rasterized before PDF rendering. Local filesystem paths are not uploaded with the request.
* **Image limit:** Each document can contain **1,000 image occurrences**, including repeated references to the same image. Exceeding this limit fails the conversion. An individual missing, inaccessible, corrupt, unsupported, or oversized image may instead be omitted with a warning.
* **Hosted input:** relative images and hyperlinks use the final downloaded source URL as their base. Keep related assets reachable from that location.
* **Inline input:** unresolved relative images may be omitted with `IMAGE_OMITTED`. Relative hyperlinks retain their visible content but lose clickability, with `LINK_DESTINATION_OMITTED`.
* **Empty links:** empty link destinations preserve their content without a clickable destination. Fragment-only links remain links within the PDF. Browser-only anchor `target` attributes do not control PDF links.
* **HTML and math:** unsupported HTML elements, including `<details>` and `<summary>`, fail the conversion. Replace collapsible sections with Markdown headings and paragraphs. Scripts, active HTML, external stylesheets, and unsafe link destinations are unsupported. TeX expressions such as `$x^2$` remain literal text; mathematical typesetting is not supported.
* **Text fidelity:** some characters can display correctly while copying, searching, or extraction is inaccurate. Review `TEXT_EXTRACTION_UNRELIABLE` warnings and retain the original Markdown when exact text matters.

Page size, orientation, margins, custom CSS, font selection, headers, footers, branding, templates, passwords, and `profiles` are not supported request options. Unsupported fields return `400` before a conversion job is created. Use [HTML to PDF](https://developer.pdf.co/api/pdf-from-html/convert.md) when you need its layout controls.

## Conversion warnings

Warnings are separate from job failure. Each entry has a stable `code` and a human-readable `message`. Read the message for the affected content and next action; do not parse its wording as a machine interface.

| Code | Effect | What to do |
| - | - | - |
| `IMAGE_OMITTED` | An image was left out of the PDF. A warning is recorded for each affected occurrence. | Correct its URL, make it public, or replace it with a valid supported image. For inline Markdown, use an absolute URL or supported data URL. |
| `TEXT_EXTRACTION_UNRELIABLE` | Text may look correct but copy, search, or extract inaccurately. | Check the rendered PDF and use the original Markdown when you need exact text. |
| `LINK_DESTINATION_OMITTED` | Some relative hyperlinks in inline Markdown are no longer clickable; visible content remains. | Use absolute URLs or submit the document through `url`. This warning is reported once per document. |

Review warnings before distributing a PDF. Missing required text, detected overflow, or a job-wide processing failure is not treated as a permitted image omission.

Set `PDFCO_API_KEY` in your environment. The examples use the hosted Markdown sample. Each example submits one request and prints the response. Use its `jobId` with [Background Job Check](https://developer.pdf.co/api/job-check.md) to retrieve the PDF, or supply a `callback` URL.

Node.js requires version 18 or later and uses an ES module. Python uses its standard library, C# targets .NET 8 or later, Java requires version 11 or later, and PHP requires the cURL extension.

**Sample request**

```bash cURL theme={null}
curl --request POST \
  --url 'https://api.pdf.co/v1/pdf/convert/from/md' \
  --header 'Content-Type: application/json' \
  --header "x-api-key: $PDFCO_API_KEY" \
  --data-raw '{"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md"}'
```

```javascript Node.js theme={null}
const response = await fetch("https://api.pdf.co/v1/pdf/convert/from/md", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": process.env.PDFCO_API_KEY,
  },
  body: JSON.stringify({ url: "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md" }),
});

console.log(await response.json());
```

```python Python theme={null}
import json
import os
from urllib.request import Request, urlopen

request = Request(
    "https://api.pdf.co/v1/pdf/convert/from/md",
    headers={
        "Content-Type": "application/json",
        "x-api-key": os.environ["PDFCO_API_KEY"],
    },
    data=json.dumps({"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md"}).encode("utf-8"),
    method="POST",
)

with urlopen(request, timeout=30) as response:
    print(json.load(response))
```

```csharp C# theme={null}
using System;
using System.Net.Http;
using System.Net.Http.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", Environment.GetEnvironmentVariable("PDFCO_API_KEY"));

var response = await client.PostAsJsonAsync(
    "https://api.pdf.co/v1/pdf/convert/from/md",
    new { url = "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md" }
);

Console.WriteLine(await response.Content.ReadAsStringAsync());
```

```java Java theme={null}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class MarkdownToPdf {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder(
                URI.create("https://api.pdf.co/v1/pdf/convert/from/md"))
            .header("Content-Type", "application/json")
            .header("x-api-key", System.getenv("PDFCO_API_KEY"))
            .POST(HttpRequest.BodyPublishers.ofString(
                "{\"url\": \"https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md\"}"))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient().send(
            request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
```

```php PHP theme={null}
<?php
$curl = curl_init("https://api.pdf.co/v1/pdf/convert/from/md");
curl_setopt_array($curl, [
    CURLOPT_HTTPHEADER => [
        "Content-Type: application/json",
        "x-api-key: " . getenv("PDFCO_API_KEY"),
    ],
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => json_encode(["url" => "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-from-markdown/sample.md"]),
]);

echo curl_exec($curl);
curl_close($curl);
```

```json 200 theme={null}
{
  "error": false,
  "status": 200,
  "duration": 120,
  "jobId": "EXAMPLEJOBID0123456789ABCDEFGHIJ--168-300",
  "credits": 25,
  "remainingCredits": 9975
}
```

```json 400 theme={null}
{
  "status": "error",
  "errorCode": 400,
  "error": true,
  "message": "Provide exactly one of markdown or url."
}
```

```json 401 theme={null}
{
  "status": "error",
  "errorCode": 401,
  "error": true,
  "message": "Please provide your API key as \"x-api-key\" header parameter for GET or POST request or as username (\"curl -u <apikey>\") or as url parameter (not recommended). Get your API key at https://app.pdf.co/account"
}
```

```json 402 theme={null}
{
  "status": "error",
  "errorCode": 402,
  "error": true,
  "message": "Not enough credits, subscription expired or metered use is not allowed. Please review credits on your account at https://app.pdf.co/subscriptions"
}
```

```json 403 theme={null}
{
  "status": "error",
  "errorCode": 403,
  "error": true,
  "message": "This API endpoint is not available on your subscription plan."
}
```

```json 404 theme={null}
{
  "status": "error",
  "errorCode": 404,
  "error": true,
  "message": "Endpoint is unavailable."
}
```

```json 413 theme={null}
{
  "status": "error",
  "errorCode": 413,
  "error": true,
  "message": "Markdown exceeds the 4 MiB limit. Split the document or use a smaller source."
}
```

```json 429 theme={null}
{
  "error": true,
  "message": "Too many requests. Your current limit is 100 requests per minute. Please try again later"
}
```

```json 500 theme={null}
{
  "status": "error",
  "errorCode": 500,
  "error": true,
  "message": "internal error"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.