Text

Markdown to PDF

0calls
2 credits / call

When your business system needs to provide "Export as PDF" functionality, there's no need to deploy complex layout engines on the backend. Just send the Markdown text to this endpoint, and you can directly obtain print-quality PDF files.

POST
uapis.cn
/api/v1/text/markdown-to-pdf
Body
text
string
required

Raw Markdown string, maximum size not exceeding 1MB.

theme
string

PDF layout theme. Options: github, minimal, light, dark, default is github.

paper_size
string

PDF paper size. Options: A4 or Letter, default is A4.

Overview

  • Server-side direct generation: The endpoint directly returns PDF file binary stream, frontend can trigger download without any processing, and backend can easily save for archiving.
  • Multiple beautiful themes and paper sizes: Built-in professional layout themes like GitHub, dark mode, etc., and supports standard papers like A4, Letter. With simple configuration, you can generate professional documents that match business scenarios.
  • Public network images can be directly included in PDF: In addition to plain text and standard Markdown syntax, this endpoint can also handle data URI images, or publicly accessible http, https image links. The server will first fetch images through proxy and inline them into the document before rendering, with timeout control.

Request body

Request body uses application/json. text is required, theme and paper_size are optional.

text
stringrequired

Raw Markdown string, maximum size not exceeding 1MB.

theme
stringoptional

PDF layout theme. Options: github, minimal, light, dark, default is github.

paper_size
stringoptional

PDF paper size. Options: A4 or Letter, default is A4.

Response

200 / OK

Conversion successful. Response body is PDF binary file stream.

application/pdf

400 / Bad Request

Request parameters are invalid, or Markdown content contains currently disallowed content.

Format 1Request body format error
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "Request body format is incorrect, please pass standard JSON"
}
Format 2Missing Markdown text
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "text cannot be empty"
}
Format 3Theme parameter error
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "theme only allows light, dark, minimal, github"
}
Format 4Paper size parameter error
JSON
{
  "code": "INVALID_PARAMETER",
  "message": "paper_size only allows A4 or Letter"
}
Format 5Contains raw HTML
JSON
{
  "code": "UNSUPPORTED_MARKDOWN",
  "message": "Raw HTML tags are currently not supported, please use standard Markdown syntax instead"
}
Format 6Image address not supported
JSON
{
  "code": "UNSUPPORTED_MARKDOWN",
  "message": "Markdown images only allow data URI or publicly accessible http, https addresses, local file paths are not supported"
}
Format 7Contains unsafe link protocol
JSON
{
  "code": "UNSUPPORTED_MARKDOWN",
  "message": "Link protocols only support http, https or mailto"
}

413 /

Markdown text, or image resources referenced in Markdown exceed current size limit.

Format 1Markdown text too large
JSON
{
  "code": "TEXT_TOO_LARGE",
  "message": "Markdown content cannot exceed 1MB"
}
Format 2Image resource too large
JSON
{
  "code": "FILE_TOO_LARGE",
  "message": "Image in Markdown is too large, please try with a smaller image"
}

500 / Internal Server Error

PDF generation failed, please try again later.

JSON
{
  "code": "REQUEST_FAILED",
  "message": "Markdown to PDF failed, please try again later"
}

502 / Bad Gateway

Image referenced in Markdown failed to download, or remote returned unrecognizable image content.

JSON
{
  "code": "REQUEST_FAILED",
  "message": "Image in Markdown failed to download, please confirm the image address is accessible"
}

503 / Service Unavailable

PDF rendering service is temporarily unavailable.

Format 1Service not ready
JSON
{
  "code": "SERVICE_TEMPORARILY_UNAVAILABLE",
  "message": "Markdown to PDF service is temporarily unavailable, please try again later"
}
Format 2Renderer temporarily unavailable
JSON
{
  "code": "SERVICE_TEMPORARILY_UNAVAILABLE",
  "message": "PDF rendering service is temporarily unavailable, please try again later"
}

504 / Gateway Timeout

Image referenced in Markdown download timed out.

JSON
{
  "code": "UPSTREAM_TIMEOUT",
  "message": "Image in Markdown download timed out, please try again later"
}