//Use case
Find construction notes in a drawing set
Classify the set, keep the sheets with keyed notes, and get every note with the callouts that point to it.
Keyed notes are numbered lists, such as CONSTRUCTION NOTES or KEYED NOTES, whose entries callout symbols on the drawing point to. General notes apply to the whole sheet or set; no callout points to them, and they are not returned.
Classifying first is optional: it only saves sending pages that would return no notes. You can send any pages to POST /v1/notes directly.
[1]Create a key and check it
Create an API key in the Console and set it as READMYDRAWS_API_KEY. This call returns the key's name, prefix, expiry, and limits.
curl https://api.dev.readmydraws.ai/v1/key \
-H "Authorization: Bearer $READMYDRAWS_API_KEY"GET /v1/key in the API reference: every field of its request and response.
[2]Preprocess the PDF
The SDK renders each page and extracts its text on your machine; the PDF never leaves it. Each page becomes a Page payload you can send.
import { loadPdf } from "@readmydraws/sdk";
const doc = await loadPdf("drawings.pdf");
const pages = [];
for await (const page of doc.pages()) pages.push(page);
await doc.close();[3]Classify the pages
Each request is a Job: the API answers 202 with a jobId at once, and you poll the Job until it is completed. Send at most 50 pages and 32 MB per request; split a larger set over several requests.
const headers = {
Authorization: `Bearer ${process.env.READMYDRAWS_API_KEY}`,
"Content-Type": "application/json",
};
async function submitAndPoll(url, pages) {
const res = await fetch(url, { method: "POST", headers, body: JSON.stringify({ pages }) });
const { jobId } = await res.json();
for (;;) {
const poll = await fetch(`https://api.dev.readmydraws.ai/v1/jobs/${jobId}`, { headers });
const job = await poll.json();
if (job.status !== "queued" && job.status !== "running") return job;
const seconds = Number(poll.headers.get("retry-after") ?? 2);
await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}
}
const classified = await submitAndPoll("https://api.dev.readmydraws.ai/v1/classify", pages);POST /v1/classify in the API reference: every field of its request and response.
[4]Keep the pages with keyed notes
A page with hasKeyedNotes: true shows a keyed note list, such as CONSTRUCTION NOTES or KEYED NOTES, whatever its category. The others would return no notes.
const keyed = new Set(
classified.pages
.filter((result) => result.status === "ok" && result.hasKeyedNotes)
.map((result) => result.pageIndex),
);
const toSend = pages.filter((page) => keyed.has(page.pageIndex));[5]Find the notes on them
Each ok page lists its keyed notes in notes and every note callout on the drawing in callouts, each with a box in PDF points.
const found = await submitAndPoll("https://api.dev.readmydraws.ai/v1/notes", toSend);POST /v1/notes in the API reference: every field of its request and response.
[6]Read each callout's note
A callout's noteId names the note on the same page that it points to, or is null when that note is on another sheet: join those by label yourself.
for (const page of found.pages) {
if (page.status !== "ok") continue;
for (const callout of page.callouts) {
const note = page.notes.find((n) => n.id === callout.noteId);
console.log(page.pageIndex, callout.label, note?.text ?? "(on another sheet)");
}
}Building Page payloads in the browser instead of Node.js? See the quick start.