//TypeScript SDK

Quick start

The SDK turns a drawing PDF into page images and text on your side. The PDF never leaves the machine; API calls send only the pages you pick.

npm install @readmydraws/sdk

[1]Create an API key

Detection calls are authenticated with a key. Preprocessing below runs locally and needs none.

Create an API key

[2]Preprocess a PDF in the browser

import { loadPdf } from "@readmydraws/sdk";

const input = document.querySelector("input")!;

input.addEventListener("change", async () => {
  const file = input.files?.[0];
  if (!file) return;
  // A File, Blob, ArrayBuffer, or Uint8Array
  const doc = await loadPdf(file);
  console.log(doc.pageCount, doc.docRef); // 10 "sha256:95ae…"

  // Renders only these pages, one at a time
  for await (const page of doc.pages([1, 3, 7])) {
    page.image.data; // PNG bytes
    page.text?.items; // [{ text: "A-101", bbox }, …]
  }
  await doc.close();
});

// Images only, no text extraction: loadPdf(file, { text: false })

Rendering runs in a Web Worker, so the page stays responsive. Vite, webpack 5, and Next.js pick up the worker and pdfium.wasm (4.6 MB) as is. With other bundlers, servedist/browser/worker.standalone.js and pdfium.wasm yourself and pass loadPdf(file, { workerUrl, wasmUrl }).

[3]Or in Node.js

import { loadPdf } from "@readmydraws/sdk";

// A file path, or bytes
const doc = await loadPdf("A-sheets.pdf");
const page = await doc.page(1);

// The request body: one Page payload, with the image as base64
const body = JSON.stringify({ pages: [page] });
await doc.close();

[4]What you get per page

FieldMeaning
docRefsha256: of the PDF bytes. Never the file name.
pageIndex1-based page number in the PDF.
pageWidth and height in PDF points as displayed, and the PDF's rotation.
imagePNG, 5000 px on the long edge by default (targetLongEdge, 1–10000), with effective DPI and scale (pixels per point). Scans are never upscaled.
textText runs with boxes in points, origin top-left. hasTextLayer is false for scans; text: false leaves it out.

[5]Which pages to send

Send each endpoint only the pages it reads. To find construction notes, classify the set first and keep the pages with keyed notes: Find construction notes in a drawing set walks through it.

[6]Errors

loadPdf, page, and pages reject with a PreprocessError whose code is one of:

codeWhen
invalid_pdfNot a PDF, truncated, or corrupt.
password_requiredEncrypted; pass { password }.
wrong_passwordEncrypted and the password is wrong.
empty_documentThe PDF has no pages.
page_out_of_rangePage index outside 1 to pageCount.
page_render_failedThat page only; pageIndex is set.
document_closedCalled after close().
engine_load_failedThe worker or pdfium.wasm could not load, or the page isn't on HTTPS.

[7]Requirements

  • The latest two versions of Chrome, Edge, Firefox, and Safari on a page served over HTTPS (or localhost), or Node.js 22+.
  • 16 GB RAM recommended. One page renders at a time and needs about 70 MB at 5000 px.
  • About 0.8 s per page on a recent laptop core; a 100-page set takes 1.5 minutes. Lower targetLongEdge on slow machines.