Feature #91
openShipping Bill PDF Extractor Wizard
Description
Shipping Bill PDF Extractor Wizard¶
Frappe-based document extraction wizard for converting Shipping Bill PDFs into structured, application-ready JSON.
๐ Project Overview¶
The Shipping Bill PDF Extractor Wizard is a Frappe-based document-processing application developed to reduce the manual effort involved in reading Shipping Bill PDFs and entering their information into the application.
A user uploads a Shipping Bill PDF through the wizard. The system then analyzes the PDF, extracts the available document information, identifies the required Shipping Bill fields, normalizes the extracted values, and generates a structured JSON response.
The most important design requirement is that the extractor should work with different Shipping Bill PDFs containing different values. The extraction logic should therefore identify values from the document structure, labels, layout, text positions, and coordinates, rather than depending on fixed values from one sample PDF.
๐ฏ Objectives¶
The project was developed with the following objectives:
- Automate Shipping Bill information extraction from PDF documents.
- Reduce manual data entry and document reading.
- Provide a simple guided wizard for users.
- Analyze multi-page Shipping Bill PDFs.
- Dynamically identify Shipping Bill fields.
- Associate labels with their corresponding values.
- Use document layout and coordinates where required.
- Normalize extracted values into application-friendly formats.
- Generate structured Shipping Bill JSON.
- Provide extraction information useful for validation and debugging.
- Create a reusable foundation that can process different Shipping Bill PDFs.
๐ข Business Problem¶
Shipping Bills contain a large amount of structured information, but that information is stored inside PDF documents.
In a manual process, a user would typically:
- Open the Shipping Bill PDF.
- Search for each required field.
- Read the value associated with that field.
- Enter the value into the application.
- Repeat the process for every Shipping Bill.
- Prepare the information in the required structured format.
This becomes inefficient when multiple Shipping Bills need to be processed.
Problems with the manual approach¶
- Repetitive data entry.
- Increased processing time.
- Higher possibility of human error.
- Difficult to maintain consistency.
- Time spent searching through multi-page documents.
- Additional effort required to convert extracted information into JSON or application fields.
The Shipping Bill Extractor Wizard was created to automate this document-to-data conversion.
๐ก Solution¶
The solution introduces a guided wizard that acts as the entry point for Shipping Bill PDF processing.
Shipping Bill PDF
โ
โผ
Upload in Wizard
โ
โผ
PDF Validation
โ
โผ
PDF Analysis
โ
โผ
Text / Layout Information
โ
โผ
Shipping Bill Field Detection
โ
โผ
Value Extraction
โ
โผ
Normalization
โ
โผ
Structured JSON Output
โ
โผ
Review / Downstream Use
The wizard separates the user interaction from the document-processing logic, making the solution easier to maintain and improve.
๐งญ Wizard Workflow¶
Step 1 โ Upload Shipping Bill PDF¶
The user uploads a Shipping Bill PDF through the Frappe wizard.
The uploaded document becomes the input to the extraction pipeline.
The wizard is designed around the document rather than a specific sample file.
For example, the system should not assume that every document contains:
Shipping Bill No = 5632009
Port Code = INBOM4
Gross Weight = 1143
Those are values from one document and must be discovered dynamically from the uploaded PDF.
Step 2 โ Validate the PDF¶
Before extraction begins, the input document is validated.
The processing layer checks that:
- A file has been provided.
- The document is available for processing.
- The input is a PDF.
- The PDF can be passed into the analysis pipeline.
The API layer controls the processing flow and passes the validated document to the PDF analyzer.
๐ PDF Analysis¶
The PDF Analyzer is responsible for inspecting the uploaded PDF before the Shipping Bill parser attempts to extract fields.
The analysis provides information such as:
- Total number of pages.
- Page-level information.
- Extractable text.
- Text-based pages.
- Image-based pages.
- Content required by the parser.
Example test result¶
The extractor was tested using a multi-page Shipping Bill PDF:
Total Pages : 6
Text Pages : 6
Image Pages : 0
This confirms that the tested document contained extractable text across all six pages.
๐งฉ Shipping Bill Parsing¶
Once the PDF has been analyzed, the extracted document information is passed to the Shipping Bill Parser.
The parser is responsible for identifying the required Shipping Bill fields and their corresponding values.
The parser considers relationships between:
- Field labels.
- Extracted values.
- Text positions.
- Coordinates.
- Page information.
- Document layout.
- Nearby document elements.
The purpose is to determine which value belongs to which field, rather than simply searching the PDF for a value that happens to look correct.
๐ง Dynamic Field Extraction¶
Dynamic extraction is one of the most important requirements of this project.
A hardcoded implementation would look like:
Shipping Bill Number โ 5632009
Port Code โ INBOM4
Gross Weight โ 1143
This approach is not acceptable for the final extractor because the next Shipping Bill can contain completely different values.
Instead, the system should work like:
Shipping Bill A
โ
โผ
Read document structure
โ
โผ
Identify labels
โ
โผ
Locate corresponding values
โ
โผ
Generate structured output
and:
Shipping Bill B
โ
โผ
Read document structure
โ
โผ
Identify labels
โ
โผ
Locate corresponding values
โ
โผ
Generate structured output
The extraction logic remains the same while the document values change.
๐ Label, Layout & Coordinate-Based Extraction¶
Shipping Bills can contain multiple values with similar formats.
For example, several numbers may appear on the same page. A simple search for a number is therefore not enough to determine which field it belongs to.
The parser uses the relationship between:
Label
+
Position
+
Coordinates
+
Nearby Value
+
Page Layout
to determine the correct field/value relationship.
Example¶
Field Extracted Value
------------------------------------------------
Port Code INBOM4
Shipping Bill No 5632009
Shipping Bill Date 2026-08-04
IEC 0300014953
CB Code AAACM6824HCH032
Packages 2
Gross Weight 1143 KGS
The values shown above represent data extracted during testing. They are not hardcoded extraction values.
๐ Target Shipping Bill Information¶
The parser is intended to extract the fields required by the Shipping Bill structure.
Examples include:
Header Information¶
- Port Code
- Shipping Bill Number
- Shipping Bill Date
- IEC
- CB Code
- Port of Loading
- Destination
- Package Count
- Gross Weight
- Weight Unit
Transaction / Invoice Information¶
- Invoice information
- Invoice-related references
- Item information
Item Information¶
- Product/item details
- Quantities
- Relevant Shipping Bill item fields
The exact values depend on the uploaded document.
๐ Data Normalization¶
Raw PDF text is not always immediately suitable for application use.
After extraction, the parser normalizes the values into the expected application format.
Normalization can include:
- Date formatting.
- Numeric conversion.
- Weight handling.
- Package count conversion.
- Text cleanup.
- Empty-value handling.
- Field formatting.
For example:
Raw PDF Value
โ
โผ
Extracted Value
โ
โผ
Normalized Value
โ
โผ
Application JSON
This ensures that downstream processing receives predictable data types and formats.
๐ฆ Shipping Bill JSON Generation¶
After parsing and normalization, the extracted information is converted into structured JSON.
A representative output structure is:
{
"shipping_bill_json": {
"doctype": "Shipping Bill",
"port_code": "...",
"gwt": 0,
"inv": 0,
"shipping_bill_no": "...",
"port_of_loading": "...",
"shipping_bill_date": "...",
"iec": "...",
"cb_code": "...",
"packages": 0
}
}
The actual values are dynamically populated from the uploaded Shipping Bill PDF.
The JSON structure provides a consistent interface between the PDF extraction layer and downstream application processing.
๐ Extraction Trace¶
The extraction process also maintains extraction trace information.
The trace is useful when reviewing how a field was detected.
It can help with:
- Debugging incorrect extraction.
- Reviewing field detection.
- Understanding label/value relationships.
- Identifying incorrect neighboring values.
- Improving parser rules.
- Testing new Shipping Bill layouts.
This is particularly important because Shipping Bill PDFs may contain complex layouts where a nearby value can otherwise be incorrectly associated with a label.
๐๏ธ Application Architecture¶
The implementation separates the major responsibilities into different layers.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill Wizard โ
โ JavaScript / HTML / CSS โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ API Layer โ
โ File handling / orchestration โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PDF Validation โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PDF Analyzer โ
โ Pages / Text / PDF Structure โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill Parser โ
โ Labels / Values / Layout / Coords โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโดโโโโโโโโโ
โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Normalization โ โ Extraction Traceโ
โโโโโโโโโโฌโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill JSON โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Architectural Principle¶
The UI does not contain the complete extraction logic.
Instead:
- The Wizard handles user interaction.
- The API coordinates processing.
- The PDF Analyzer understands the PDF structure.
- The Shipping Bill Parser extracts fields.
- Normalization prepares the values.
- JSON generation produces application-ready output.
This separation allows each component to be improved independently.
๐ Project Structure¶
The current implementation includes the following core files:
shipping_bill_extractor/
โ
โโโ shipping_bill_extrac.js
โโโ shipping_bill_extrac.css
โโโ shipping_bill_extrac.json
โ
โโโ pdf_analyzer.py
โโโ shipping_bill_parser.py
File Responsibilities¶
| File | Responsibility |
|---|---|
shipping_bill_extrac.js |
Wizard UI and frontend interaction |
shipping_bill_extrac.css |
Wizard styling and layout |
shipping_bill_extrac.json |
Frappe page configuration |
pdf_analyzer.py |
PDF analysis and document-level information |
shipping_bill_parser.py |
Shipping Bill field extraction and parsing |
The current project baseline treats these files as the core implementation components.
๐ฅ๏ธ Wizard User Interface¶
The frontend is implemented using:
- JavaScript
- HTML
- CSS
- Frappe Page API
The UI is responsible for providing a simple workflow for the user.
Main responsibilities¶
- Display the wizard.
- Accept the Shipping Bill PDF.
- Start document analysis.
- Display processing results.
- Present extracted information.
- Display structured output for further use.
The intention is to keep the user experience simple while the backend performs the complex document-processing work.
๐ API Processing Pipeline¶
The backend processing flow can be summarized as:
PDF Upload
โ
โผ
File Validation
โ
โผ
PDF Analyzer
โ
โผ
Shipping Bill Parser
โ
โผ
Value Normalization
โ
โผ
Shipping Bill JSON
โ
โผ
Extraction Trace
The API coordinates these stages without placing all processing responsibilities into a single function or the frontend.
๐ก๏ธ Validation & Error Handling¶
Validation is performed throughout the processing pipeline.
The implementation considers:
- File availability.
- PDF validity.
- PDF structure.
- Extractable content.
- Required Shipping Bill fields.
- Parsed values.
- Normalized values.
- Label/value relationships.
The extraction trace provides additional information when the parser produces an unexpected mapping.
๐งช Testing¶
The extractor was tested using an actual multi-page Shipping Bill PDF.
PDF Analysis Result¶
Total Pages : 6
Text Pages : 6
Image Pages : 0
Extracted Test Values¶
The parser was tested against values including:
Port Code : INBOM4
Shipping Bill No : 5632009
Shipping Bill Date : 2026-08-04
IEC : 0300014953
CB Code : AAACM6824HCH032
Packages : 2
Gross Weight : 1143 KGS
These values were used to verify the extraction pipeline against the sample document.
They should not be treated as constants in the parser.
โ ๏ธ Extraction Challenge Identified During Testing¶
Testing revealed an important challenge with Shipping Bill extraction.
Some labels can appear close to other labels or values on the same page. If extraction is based only on raw text matching, the parser may associate a field with the wrong neighboring value.
For example:
Label A Value A Label B Value B
A basic text-search implementation may incorrectly associate:
Label A โ Value B
instead of:
Label A โ Value A
This is why the project requires layout- and coordinate-aware extraction.
The parser must understand not only what text exists, but also where that text exists in relation to other document elements.
๐ซ Avoiding Hardcoded Document Values¶
One of the core project rules is:
Do not hardcode values from the sample Shipping Bill into the extraction logic.
For example, the parser should never contain business values such as:
shipping_bill_no = "5632009"
port_code = "INBOM4"
gross_weight = 1143
Instead, the parser should discover these values from the uploaded document.
Correct Approach¶
Uploaded PDF
โ
โผ
Identify Label
โ
โผ
Find Related Value
โ
โผ
Validate Value
โ
โผ
Normalize Value
โ
โผ
Return Field
This makes the implementation reusable across different Shipping Bills.
๐ Reusability Requirement¶
The same extraction pipeline should be capable of processing:
Shipping Bill A
โ
โโโ Different Port
โโโ Different Number
โโโ Different Date
โโโ Different Weight
โโโ Different Items
โ
โผ
Same Extraction Engine
and:
Shipping Bill B
โ
โโโ Different Port
โโโ Different Number
โโโ Different Date
โโโ Different Weight
โโโ Different Items
โ
โผ
Same Extraction Engine
The document values change; the extraction logic remains reusable.
๐ Current Processing Capabilities¶
The current implementation establishes the following processing capabilities:
- Shipping Bill PDF upload.
- PDF validation.
- Multi-page PDF analysis.
- Text-page identification.
- Shipping Bill parsing.
- Dynamic field extraction approach.
- Label/value relationship handling.
- Layout and coordinate-aware extraction approach.
- Value normalization.
- Structured JSON generation.
- Extraction trace generation.
- Frappe wizard-based user interface.
๐ฎ Future Improvements¶
The extraction engine can be further enhanced to improve reliability across more Shipping Bill layouts.
Potential improvements include:
1. Improved Label-to-Value Matching¶
Strengthen the logic used to determine which value belongs to each label.
2. Coordinate-Based Field Boundaries¶
Define field regions using PDF coordinates instead of relying only on nearby text.
3. Multi-Column Layout Handling¶
Improve extraction for documents where multiple fields are arranged horizontally or across columns.
4. Table Extraction¶
Improve extraction of invoice and item-level tabular information.
5. Repeated Field Handling¶
Handle fields that appear multiple times across different pages or sections.
6. Confidence Scoring¶
Assign confidence levels to extracted fields so uncertain values can be reviewed.
7. Field Validation¶
Validate extracted values against expected formats such as:
- Dates
- Numeric values
- Package counts
- Weight values
- Shipping Bill numbers
- Codes
8. Additional Shipping Bill Layout Support¶
Extend the parser to handle additional document layouts while keeping the same extraction architecture.
๐ Benefits¶
The Shipping Bill PDF Extractor Wizard provides several operational benefits:
- Reduced manual effort โ Users do not need to manually read and enter every field.
- Faster processing โ PDF information is processed automatically.
- Improved consistency โ Extracted values are normalized into a standard structure.
- Reusable extraction logic โ The parser is designed for different Shipping Bills.
- Better traceability โ Extraction trace information supports debugging and validation.
- Scalable architecture โ UI, API, PDF analysis, and parsing are separated.
- Application-ready output โ Extracted information is returned as structured JSON.
- Better user experience โ Users interact through a guided Frappe wizard.
๐ ๏ธ Technology Stack¶
| Technology | Purpose |
|---|---|
| Frappe Framework | Application and wizard platform |
| Python | PDF analysis and document parsing |
| JavaScript | Wizard frontend and user interaction |
| HTML | Wizard structure |
| CSS | Wizard styling |
| PDF Processing | Text and document structure extraction |
| JSON | Structured Shipping Bill output |
๐ Design Principles¶
The project follows these core principles:
1. Document-Driven Extraction¶
The uploaded PDF is the source of truth for extracted values.
2. No Sample-Value Hardcoding¶
Values from a test document must not become constants in the parser.
3. Separation of Responsibilities¶
UI, API, PDF analysis, parsing, and normalization are handled separately.
4. Reusable Processing¶
The extraction engine should work across different Shipping Bill documents.
5. Structured Output¶
The final result must be predictable and suitable for downstream application processing.
6. Debuggable Extraction¶
Extraction trace information should make incorrect field mappings easier to investigate.
๐ End-to-End Architecture¶
โโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill PDF โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Wizard Interface โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ API Layer โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ PDF Analyzer โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill Parserโ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโโโโโโดโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ Normalization โ โ Extraction Trace โ
โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Shipping Bill JSON โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Downstream Processingโ
โโโโโโโโโโโโโโโโโโโโโโโ
๐ Project Outcome¶
The project establishes a reusable Frappe-based framework for converting Shipping Bill PDF documents into structured application data.
The implementation moves the process from:
Manual PDF Reading
โ
Manual Data Entry
โ
Manual Formatting
to:
PDF Upload
โ
Automatic Analysis
โ
Dynamic Extraction
โ
Normalization
โ
Structured JSON
The key achievement is not simply extracting values from one Shipping Bill. The core objective is to build an extraction engine that can understand the document structure and dynamically extract the correct values from different Shipping Bill PDFs.
๐ Conclusion¶
The Shipping Bill PDF Extractor Wizard provides the foundation for automating Shipping Bill document processing within Frappe.
It combines a guided user interface with a backend processing pipeline consisting of:
- PDF validation
- PDF analysis
- Text and layout processing
- Shipping Bill field detection
- Dynamic value extraction
- Label/value relationship handling
- Coordinate and layout awareness
- Data normalization
- Structured JSON generation
- Extraction tracing
The architecture is designed to be reusable and maintainable, with the most important requirement being that the system should extract values dynamically from the uploaded Shipping Bill rather than relying on hardcoded values from a sample document.
This provides a strong foundation for integrating Shipping Bill PDF extraction into larger Frappe-based business automation workflows.
Files