Skip to content

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

PDF Drawing Validation – R3, R4 & R6

About the Project

This project is a small PDF drawing validation tool for the QUADE Innoventure 2026 workflow.

The scripts check different pieces of information inside engineering drawing PDFs. Instead of manually going through every page, the scripts read the PDF, look for the required information, validate it, and generate a JSON report.

The current rules are:

  • R3 – Sheet Number Validation
  • R4 – Drawing ID and Title Completeness
  • R6 – Architectural Reference Check

Each rule has its own validation logic and produces a machine-readable JSON report.


Rules

R3 – Sheet Number Validation

R3 checks the sheet number on every page of the PDF.

The script:

  1. Opens the PDF.
  2. Processes every page.
  3. Extracts the text from the page.
  4. Searches the extracted text from bottom to top.
  5. Looks for possible sheet-number formats using regular expressions.
  6. Validates the extracted sheet number.
  7. Checks whether the same sheet number has already appeared on another page.
  8. Marks the result as PASS or FAIL.
  9. Creates r3_report.json.

Example

If the PDF contains:

Page 1 → 3.1
Page 2 → 3.2
Page 3 → 3.3

the sheet numbers are unique, so the validation passes.

If the PDF contains:

Page 1 → 3.1
Page 2 → 3.2
Page 3 → 3.1

3.1 is duplicated, so the validation fails.

R3 approach

The current R3 implementation uses:

PyMuPDF
   ↓
PDF text extraction
   ↓
Regular expressions
   ↓
Bottom-to-top text search
   ↓
Sheet number validation
   ↓
Duplicate detection
   ↓
JSON report

Note: The current implementation searches the extracted text from bottom to top. It does not currently use the actual X/Y coordinates of the sheet number. It also contains some project-specific exclusion rules for equipment schedules.


R4 – Drawing ID and Title Completeness

R4 checks whether drawing views found on a PDF page have both:

  • a Drawing ID
  • a Drawing Title

The purpose is to make sure a drawing view is not missing either of these pieces of information.

How R4 works

For each PDF page, the script:

  1. Opens the page.
  2. Extracts the page text using PyMuPDF.
  3. Searches for possible drawing IDs.
  4. Searches for titles near the detected drawing IDs.
  5. Checks ARCH REF patterns such as 1/A2.11.
  6. Checks labels such as:
    • PLAN
    • SECTION
    • DETAIL
    • ELEVATION
    • VIEW
  7. Removes duplicate drawing IDs.
  8. Checks whether each detected view has both an ID and a title.
  9. Marks the page as PASS or FAIL.
  10. Creates r4_report.json.

The R4 code defines several drawing-ID patterns, including numeric IDs, labels such as View, Section, Detail, Plan, and Elevation, and IDs extracted from ARCH REF values. fileciteturn2file0L77-L90

R4 extraction approach

The basic flow is:

PDF
 ↓
Extract page text
 ↓
Find possible Drawing IDs
 ↓
Find nearby titles
 ↓
Check ARCH REF patterns
 ↓
Check PLAN / SECTION / DETAIL / ELEVATION / VIEW labels
 ↓
Remove duplicate IDs
 ↓
Validate ID + Title
 ↓
PASS / FAIL
 ↓
JSON report

Example

A valid drawing view might look conceptually like:

1
FLOOR PLAN

The script can identify:

Drawing ID   → 1
Drawing Title → FLOOR PLAN
Status       → PASS

If it finds:

2

but cannot find a title nearby, it reports:

Drawing ID → 2
Title     → Missing
Status    → FAIL

The R4 implementation explicitly marks a view with an ID but no title as FAIL, and also marks a title without an ID as FAIL. fileciteturn2file0L243-L273

Duplicate IDs

R4 also checks for duplicate drawing IDs on the same page.

If the same ID occurs more than once, the page is marked as FAIL and the duplicate IDs are included in the result. fileciteturn2file0L247-L290


R6 – Architectural Reference Check

R6 checks the ARCH REF (Architectural Reference) information in the PDF.

The script goes through every page and tries to find and validate architectural references.

The extraction process is more flexible than R3 because it can use multiple methods, including OCR when needed.

R6 approach

PDF
 ↓
Extract normal PDF text
 ↓
Extract word-level text
 ↓
Use OCR when required
 ↓
Find ARCH REF
 ↓
Validate reference
 ↓
PASS / FAIL / REVIEW
 ↓
JSON report

The R6 validator uses PyMuPDF for PDF text extraction and can use Tesseract OCR for pages where normal text extraction is not sufficient.


Technologies Used

Python

The validation scripts are written in Python.

PyMuPDF

Used for:

  • Opening PDF files
  • Reading pages
  • Extracting text
  • Reading word-level text
  • Rendering pages when OCR is required

Install:

pip install PyMuPDF

Imported in Python as:

import fitz

Regular Expressions

Python's re module is used to find and validate patterns such as:

3.1
A-1
1-A
A.1

and architectural reference patterns.

JSON

The json module is used to generate the final reports.

pathlib

Used for PDF file and path handling.

datetime

Used to add timestamps to the reports.

Tesseract OCR

R6 can use Tesseract OCR as a fallback when normal PDF text extraction is not enough.

Install the Python packages:

pip install pytesseract Pillow

Tesseract OCR itself must also be installed separately on the system.


Project Structure

A typical project folder can look like this:

project/
│
├── r3_sheet_number_validation.py
├── r4_drawing_id_title_completeness.py
├── r6_architectural_reference_check.py
│
├── Testcase_1.pdf
├── Testcase_2.pdf
│
├── r3_report.json
├── r4_report.json
├── r6_report.json
│
└── README.md

Installation

1. Create a virtual environment

Windows

python -m venv venv
venv\Scripts\activate

Linux / macOS

python3 -m venv venv
source venv/bin/activate

2. Install dependencies

For R3 and R4:

pip install PyMuPDF

For R6:

pip install PyMuPDF pytesseract Pillow

Running the Rules

Run R3

python r3_sheet_number_validation.py

The script processes the PDF and creates:

r3_report.json

Run R4

python r4_drawing_id_title_completeness.py

The script processes all pages and creates:

r4_report.json

Run R6

python r6_architectural_reference_check.py

The script checks the architectural references and creates:

r6_report.json

Use the actual Python filenames from your project if they are different from the examples above.


R4 Result

The R4 report contains information such as:

  • Rule ID
  • Rule name
  • PDF file name
  • Number of pages
  • Overall status
  • Page-by-page results
  • Number of views found
  • Drawing IDs
  • Drawing titles
  • Duplicate IDs
  • Validation messages
  • Confidence values
  • Summary
  • Timestamp

A simplified result looks like:

{
  "rule_id": "R4",
  "rule_name": "Drawing ID and Title Completeness",
  "file": "Testcase_1.pdf",
  "total_pages": 3,
  "overall_status": "PASS",
  "summary": {
    "passed": 3,
    "failed": 0,
    "review": 0
  }
}

R3 Result

A simplified R3 report looks like:

{
  "rule_id": "R3",
  "rule_name": "Sheet Number Validation",
  "file": "Testcase_2.pdf",
  "total_pages": 3,
  "overall_status": "PASS",
  "duplicate_sheets": [],
  "summary": {
    "passed": 3,
    "failed": 0,
    "review": 0
  }
}

The page-level results contain the extracted sheet number, validation status, message, confidence, and source information.


R6 Result

A simplified R6 report looks like:

{
  "rule_id": "R6",
  "rule_name": "Architectural Reference Check",
  "file": "Testcase_1.pdf",
  "total_pages": 3,
  "overall_status": "PASS",
  "summary": {
    "total_checks": 3,
    "passed": 3,
    "failed": 0,
    "review": 0
  }
}

Status Meaning

PASS

The required information was found and passed the validation rules.

FAIL

The validation found a problem.

Examples:

R3

  • Sheet number was not found.
  • Sheet number format is invalid.
  • Sheet number is duplicated.

R4

  • No drawing view was found.
  • Drawing ID is missing.
  • Drawing title is missing.
  • Duplicate drawing ID was found.

R6

  • Architectural reference is missing or invalid according to the rule.

REVIEW

The result could not be confidently classified.

R6 supports the REVIEW status. R4 keeps the REVIEW count in its report structure, although its current page-level logic mainly produces PASS and FAIL.


Confidence

The scripts include confidence values with their validation results.

These are rule-based confidence scores. They are not machine-learning probabilities.

For example, R4 gives a high confidence when a drawing ID and title are both clearly detected:

ID + Title found → 95%

When a drawing ID is found but the title is missing, the confidence is lower:

ID found, title missing → 70%

These values are simply indicators of how confidently the rule classified the result.


Overall Validation Flow

The three rules can be viewed as one larger PDF validation process:

                    PDF Drawing
                         │
                         ▼
                  Read every page
                         │
          ┌──────────────┼──────────────┐
          │              │              │
          ▼              ▼              ▼
         R3             R4             R6
    Sheet Number     Drawing ID      ARCH REF
          │           + Title            │
          │              │               │
          ▼              ▼               ▼
      Extract          Extract         Extract
          │              │               │
          ▼              ▼               ▼
      Validate         Validate        Validate
          │              │               │
          ▼              ▼               ▼
      Duplicate       Missing ID/     Reference
        Check          Title Check      Check
          │              │               │
          └──────────────┼───────────────┘
                         ▼
                  PASS / FAIL / REVIEW
                         │
                         ▼
                    JSON Reports

Important Notes

R3

R3 currently relies on PDF text extraction and regular expressions.

It does not use computer vision or an AI model.

The current implementation searches the extracted text from bottom to top. It does not directly use the physical X/Y coordinates of the sheet number.

There are also some project-specific rules for ignoring equipment-schedule-related values.

R4

R4 is based on text extraction and pattern matching.

It looks for drawing IDs using several patterns and then searches nearby lines for a possible title. It also checks ARCH REF patterns and drawing labels such as PLAN, SECTION, DETAIL, ELEVATION, and VIEW. fileciteturn2file0L92-L100

The title validation rejects very short titles and titles containing words such as schedule, materials, hardware, notes, plumbing, and equipment. fileciteturn2file0L48-L60

R6

R6 has a broader extraction strategy because it can use normal PDF text extraction, word-level extraction, and optional OCR.

This is useful for drawings where some pages are scanned or contain image-based text.


Troubleshooting

PDF not found

Make sure the PDF is in the folder where the script is being executed.

The scripts also contain fallback logic that looks for PDF files in the current directory.

R3 cannot find a sheet number

Possible reasons:

  • The PDF does not contain a text layer.
  • The sheet number is part of an image.
  • The sheet number format is not supported.
  • The PDF text extraction order is unusual.

R4 cannot find a drawing view

Possible reasons:

  • The drawing ID is stored as an image.
  • The ID format is different from the patterns in the script.
  • The title is not close enough to the detected ID.
  • The page does not contain extractable text.

R6 cannot find ARCH REF

Possible reasons:

  • The reference is inside an image.
  • OCR is not installed.
  • The reference format is different from the current patterns.
  • The PDF text extraction did not preserve the expected structure.

OCR is not working

Install:

pip install pytesseract Pillow

You also need to install the Tesseract OCR application separately and make sure it is available through the system PATH.


Current Rule Summary

Rule What it checks Main approach Output
R3 Sheet Number PyMuPDF + Regex + duplicate check r3_report.json
R4 Drawing ID + Title PyMuPDF + Regex + nearby-line matching r4_report.json
R6 ARCH REF PyMuPDF + Regex + optional OCR r6_report.json

In Short

The project is a PDF validation pipeline for engineering drawings.

Each rule focuses on a different part of the drawing:

R3 → Is the Sheet Number valid and unique?
R4 → Does each Drawing View have an ID and Title?
R6 → Is the Architectural Reference valid?

The scripts process the PDF page by page and generate JSON reports that can be used by another application, automated testing system, or larger drawing-validation workflow.

The current implementation is rule-based and uses PDF text extraction, regular expressions, and OCR where required. It can be extended later with coordinate-based extraction, image processing, or computer-vision methods if the drawing layouts require them.

Releases

Packages

Contributors

Languages