apyhub
Back
▣ DOCUMENT INTELLIGENCE KIT · OUTPUT KIT

Convert HTML to Arabic RTL PDF API

What it does

The Arabic HTML to PDF API turns your HTML and CSS into a PDF with right-to-left layout and Arabic fonts. Send the page as html and get the PDF back as base64 in JSON, or as a binary file.

Pick a font with font: naskh (default), kufi, sans or amiri. Set the page size with format: A4 (default), A5, Letter, Legal, receipt-80mm or receipt-58mm. Use direction for text flow. The default auto switches to right to left when the content has Arabic, and rtl or ltr force one way. Add styles with css, page margins with margin_mm (0 to 40), and wide pages with landscape. header_html and footer_html add a header and footer, and page_numbers adds page numbers. With output set to binary, filename names the downloaded file.

Teams use the Arabic HTML to PDF API to print bilingual invoices from their own templates, make receipts for 80 mm and 58 mm printers, and export Arabic reports and letters. It also works as a plain HTML to PDF API for English or mixed content.

Scripts in your HTML do not run, so build the final page before you send it.

After rendering, stamp a "PAID" or "DRAFT" mark with the PDF Watermark API, or join several documents into one file with the Merge Files to PDF API.

POST
HTML to PDF
https://api.eu.apyhub.com/odelyo/convert-html-to-arabic-pdf/documents

QUICKSTART

GUIDE

Quickstart

Send a short Arabic HTML snippet and get back an A4 PDF as base64.

curl -X POST "https://api.eu.apyhub.com/odelyo/convert-html-to-arabic-pdf/documents" \
  -H "apy-token: $APY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>مرحبا بالعالم</h1><p>هذا مستند تجريبي. Invoice ١٢٣</p>"}'

What you'll get back

Returns a JSON object with data (the PDF as base64, its size in bytes and its page count) and meta (request ID and API version).

{
  "data": {
    "pdf_base64": "JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9DcmVhdG9y...",
    "bytes": 19387,
    "pages": 1
  },
  "meta": {
    "request_id": "req_434ed7a6101436fa",
    "version": "v1"
  }
}
TRY ITLIVE · 10 ATOMS
Loading your default key…
The full key is used to call the gateway and stays in this tab — never sent to orbit or saved.
body*
The HTML to render. A fragment or a full document.
Extra CSS applied to the page.
Arabic font family.
Page size.

About this endpoint

What it does

Renders the HTML you send into a PDF, with right-to-left layout and Arabic fonts. Returns the PDF as base64 inside JSON, or as raw application/pdf bytes.

Request Body

ParameterTypeDescription
htmlStringRequired. The HTML to render. A fragment or a full document. Length: 1 to 3,000,000 characters.
cssStringExtra CSS applied to the page. Length: 1 to 500,000 characters.
fontENUMArabic font family. Allowed values: naskh, kufi, sans, amiri. Default: naskh.
formatENUMPage size. Allowed values: A4, A5, Letter, Legal, receipt-80mm, receipt-58mm. Default: A4.
directionENUMText direction. Allowed values: auto, rtl, ltr. Default: auto, which uses rtl when the content has Arabic.
landscapeBooleanRender the page in landscape orientation. Default: false.
margin_mmNumberPage margin in millimetres. Range: 0 to 40.
header_htmlStringHTML for the page header. Length: 1 to 20,000 characters.
footer_htmlStringHTML for the page footer. Length: 1 to 20,000 characters.
page_numbersBooleanAdd page numbers. Default: false.
outputENUMResponse format. Allowed values: base64, binary. Default: base64. binary returns the PDF bytes with Content-Type: application/pdf.
filenameStringDownload name sent in the Content-Disposition header when output is binary. Must match ^[\w.\- ]{1,100}$. Default: document.pdf. Ignored for base64.

Response

Returns a JSON object with data (the PDF and its size) and meta (request details). With output set to binary, the body is the PDF file instead.

ParameterTypeDescription
data.pdf_base64StringThe PDF file, base64 encoded. Starts with JVBERi (%PDF).
data.bytesIntegerSize of the PDF in bytes, before base64 encoding.
data.pagesIntegerNumber of pages in the PDF.
meta.request_idStringRequest identifier, for example req_434ed7a6101436fa. Quote it in support requests.
meta.versionStringAPI version. Currently v1.

Errors return a JSON object with error and meta.request_id.

ParameterTypeDescription
error.codeStringvalidation_error when the input does not match the schema, render_failed when the page could not be rendered.
error.messageStringShort human-readable summary.
error.fieldStringThe request field that failed validation. Present for validation_error only.
error.detailStringWhat exactly was wrong, for example body/html must NOT have fewer than 1 characters.
error.docsStringLink to the provider's documentation for this error.

Notes

  • Success returns HTTP 201 for base64 and HTTP 200 for binary. Validation and render errors return HTTP 422.
  • Scripts in the HTML do not run. Send the final, already-built page.
  • Embed images as data: URIs so the PDF does not depend on outside servers.
  • Large pages take longer. In testing, 100,000 characters of text rendered in about 3.4 seconds (24 pages). Pages of 250,000 characters and more timed out or returned render_failed.
  • Extra fields are rejected with validation_error.
▣ COMMON ERRORS

Errors any endpoint can return

400bad_request

Required parameter missing or malformed body.

401unauthorized

API key missing, revoked, or not authorized for this service.

429rate_limited

Your plan's per-second rate exceeded. Retry with exponential backoff.

503upstream_busy

Backend temporarily unavailable. Try again in a few seconds.