Python helpers

transcribe_pdf

Read the text of a PDF from a URL, including scanned pages, so your code can work with it.

transcribe_pdf(url: str) -> str

Downloads a PDF from a public HTTP or HTTPS URL and returns its readable text. Octocom processes the document with OCR, so the helper works with both PDFs that contain selectable text and image-only scans. For example, an action can read a product's assembly manual on demand and give the bot the instructions.

The returned string uses Markdown where the document service can recover useful structure such as headings, lists, and tables. Visual layout, illustrations, and the exact position of text on a page are not preserved.


Parameters

NameTypeDescription
urlstrA public HTTP or HTTPS URL that serves a PDF

Returns

str - the extracted, Markdown-formatted text.

Limits

LimitValueError when exceeded
Pages per PDF50HTTP 413
PDFs per hour60 for each organizationHTTP 429
Processing timeabout 110 seconds per PDFHTTP 504

The helper raises requests.HTTPError when a limit is hit. Split long documents, or link the customer to the relevant section instead.


Example: let a bot read an assembly manual

Create a Python action with a pdfUrl argument:

def execute_action(context):
    pdf_url = context["args"]["pdfUrl"]
    text = transcribe_pdf(pdf_url)

    return {
        "source": pdf_url,
        "text": text,
    }

The action can now receive a product's manual URL, extract the instructions on demand, and return them to the bot as tool context.

PDF transcription calls Octocom's document-processing service and can take several seconds, especially for scans. If the same PDF is likely to be read repeatedly, cache the result in the Organization Store.

The URL must be publicly reachable. Localhost, private-network, file, and other non-HTTP(S) URLs are rejected. Password-protected or corrupt PDFs may not be readable.

On this page