- Overview
- Project Structure
- Key Components
- PDF Processing
- User Interface
- Data Handling
- Features Implementation
- Cross-Check Functionality
- Customization Guide
- Troubleshooting
This web application allows BRAC University students to create a personalized exam routine by selecting their courses and sections. The app extracts relevant exam information from the official PDF schedule and presents it in a user-friendly format. Key features include:
- Course and section selection
- Interactive table generation
- Screenshot functionality
- PDF cross-check verification with highlighted sections
- Mobile-friendly responsive design
exam-routine/
├── index.html # Main HTML file
├── css/
│ └── styles.css # Main stylesheet
├── js/
│ ├── data.js # Course data and cache management
│ ├── dropdown.js # Custom dropdown functionality
│ ├── main.js # Application initialization
│ ├── pdf-debug.js # Debug tools for PDF processing
│ ├── pdf-helper.js # PDF rendering and processing
│ ├── pdf-screenshot-helper.js # PDF screenshot and cropping utilities
│ ├── pdf-viewer.js # PDF display functionality
│ ├── ui.js # UI management (toasts, interactions)
│ └── utils.js # Utility functions
├── convert_schedule.py # Deprecated legacy converter (not used)
├── pdf_converter.py # Main PDF conversion script
├── exam_data.json # Processed exam data
├── examData.pdf # Source PDF file
└── README.md # General readme file
- main.js: Entry point of the application that initializes all components.
- data.js: Manages course data, sections, and caching mechanisms.
- ui.js: Handles all user interface interactions, toast notifications, and dynamic content generation.
- pdf-helper.js: Core PDF processing functionality for rendering and highlighting.
- pdf-screenshot-helper.js: Manages screenshot capturing and PDF cropping.
- PDF.js: Used for rendering and manipulating PDF files in the browser.
- TailwindCSS: Utility-first CSS framework for styling.
- html2canvas: For capturing screenshots of HTML elements.
- FontAwesome: For icons throughout the interface.
The application uses PDF.js to render and process PDF documents. Key functions:
fetchPdfDocument(): Fetches the PDF from the server.renderExamPage(page, canvas, searchText): Renders a PDF page to canvas with highlighting.findTextInPage(page, searchText): Locates specific text on a PDF page.highlightFoundText(canvas, textItems): Adds highlighting to found text.
Functions for processing PDF screenshots and crops:
cropPdfScreenshot(canvasData, cropPercentages): Crops PDF canvas based on percentage values.cropImageFromUrl(imageUrl): Creates a cropped version of an image from URL.
Text highlighting in the PDF uses semi-transparent red rectangles:
- Text is first located using PDF.js text extraction.
- Rectangles are drawn using Canvas API with:
- Fill style:
rgba(255, 0, 0, 0.25)(semi-transparent red) - Expanded width: 4% wider than the actual text (2% on each side)
- Fill style:
PDF screenshots in the cross-check functionality are cropped asymmetrically:
- 9% from left and right sides
- 2% from top and bottom
// Cropping is applied after highlighting, ONLY for cross-check PDF screenshots
const cropPercentages = {
left: 9,
right: 9,
top: 2,
bottom: 2
};Note: The regular table screenshot functionality should NOT apply any cropping. This cropping is specifically for the cross-check PDF screenshots to focus on the relevant exam information.
- Course Input Fields: Dynamic input fields for course codes and sections.
- Schedule Table: Displays the generated exam schedule.
- Action Buttons: "Screenshot" and "Cross Check" buttons.
- Cross Check Modal: PDF viewer for verification with highlighted sections.
- Toast Notifications: Feedback messages for user actions.
The UI is built dynamically using JavaScript. Key functions:
initUI(): Initializes all UI components and event listeners.showToast(message, type): Displays toast notifications.addScheduleRow(data): Adds a row to the schedule table.updateStatusMessage(message): Updates status messages.
The application is designed to be responsive on various devices:
- Uses Flexbox and responsive units for layout
- Applies specific optimizations for small screens via media queries
- Ensures touch-friendly button sizes (min 44px height) on mobile
- Implements horizontal scrolling for tables on small screens
Exam data is stored in JSON format:
{
"courseCode": {
"sectionName": {
"date": "YYYY-MM-DD",
"time": "HH:MM AM/PM",
"room": "Room Name",
"pdfPageIndex": 0 // Index of page in PDF
}
}
}- PDF is converted to JSON using
pdf_converter.py(main script). - JSON data is loaded at runtime.
- When a user selects courses, relevant data is filtered and displayed.
Course selection uses a custom autocomplete/dropdown:
- Input fields monitor user input for matching course codes
- Custom dropdown shows available options
- Section numbers are validated against available sections
The schedule table is populated based on selected courses:
- Event listeners on "Add" buttons capture input values
- Course data is validated against the main data source
- Valid entries are added to the schedule table
- Duplicate entries are rejected with a toast notification
The application has two separate screenshot features:
-
Table Screenshot: Takes a screenshot of the exam schedule table without any cropping
- Uses the html2canvas library to capture the table
- The file is downloaded as "Spring25-Exam-Schedule.png"
-
Cross-Check PDF Screenshots: Shows PDF screenshots with highlighting and cropping
- Applies 9% cropping from sides, 2% from top/bottom
- Uses semi-transparent red highlighting
- Shows the relevant exam details on the original PDF
The table screenshot functionality works as follows:
takeScreenshot(options)creates a temporary container with styled content- Takes an optional options object with configurable settings: -
cellPaddingTop,cellPaddingRight,cellPaddingBottom,cellPaddingLeft: Controls individual paddings for table cells (default: '5px') headerPaddingTop,headerPaddingRight,headerPaddingBottom,headerPaddingLeft: Controls individual paddings for table headers (default: '5px')scale: Controls the screenshot quality (default: 3)
- Takes an optional options object with configurable settings: -
- The container width is set to match the original table width to prevent scaling issues
- The container has
overflow: visibleand extra margin to prevent content from being cut off - Cell padding is applied according to configurable settings
html2canvas()captures this container with scale set to 3 for high-quality screenshots- A slight delay (100ms) is added before capture to ensure proper rendering
- The container height is explicitly set with extra padding to prevent bottom rows from being cut off
- No cropping is applied to the table screenshot (important!)
- A download link is created with the screenshot data
- The file is automatically downloaded as "Spring25-Exam-Schedule.png"
The PDF cross-check functionality works differently:
- PDF pages are rendered with transparent red highlighting
- The highlighted pages are cropped (9% sides, 2% top/bottom)
- The cropped screenshots are displayed in a modal for verification
Both features include robust error handling and user feedback via toast notifications.
The screenshot functionality now accepts configuration options:
takeScreenshot({
// Cell padding for each side independently
cellPaddingTop: '5px',
cellPaddingRight: '5px',
cellPaddingBottom: '5px',
cellPaddingLeft: '5px',
// Header padding for each side independently
headerPaddingTop: '5px',
headerPaddingRight: '5px',
headerPaddingBottom: '5px',
headerPaddingLeft: '5px',
scale: 3 // Controls screenshot quality (1-4)
});Cell Padding Adjustment:
- You can customize padding for all four sides independently:
- Top, right, bottom, and left sides for both headers and cells
- Values are specified in CSS units (pixels recommended)
- These settings affect the visual spacing in the final screenshot
- Adjust individual sides to improve readability or create custom layouts
- Fine-tune vertical spacing by adjusting top/bottom padding separately
- Control horizontal alignment by adjusting left/right padding
Screenshot Scale/Quality:
- Scale affects the resolution of the captured image
- Higher values (3-4) produce sharper images for printing or zooming
- Lower values (1-2) produce smaller file sizes and faster processing
- Default value is 3 for a good balance of quality and performance
Test Environment:
- Use test-screenshot.html to experiment with different settings
- Features UI sliders to adjust padding for all sides individually:
- Separate controls for top, right, bottom, and left padding
- Independent settings for header and data cells
- Includes scale slider to control output quality (1-4x)
- Real-time preview shows how padding changes will affect screenshot
- All settings are applied immediately when taking a screenshot
The cross-check feature allows users to verify their schedule against the original PDF:
-
Initialization:
document.getElementById('cross-check-btn').addEventListener('click', showCrossCheckModal);
-
PDF Processing Flow:
- Modal is displayed with loading indicator
- PDF is fetched and loaded using PDF.js
- For each course in the schedule:
- The corresponding PDF page is located
- Text matching the course/section is found
- Highlighting is applied to the found text
- Canvas is rendered with highlighting
- Cropping is applied to focus on relevant areas (9% from sides, 2% from top/bottom)
- Rendered pages are displayed in the modal
-
Key Functions:
showCrossCheckModal(): Opens the modal and initiates PDF processingrenderExamPage(): Renders a PDF page with highlightingcropPdfScreenshot(): Crops the rendered canvas
- Text is located using PDF.js text extraction
- Canvas context is set to semi-transparent red:
rgba(255, 0, 0, 0.25) - Extra width is added to highlight:
extraWidth = highlightWidth * 0.04 - Rectangle is drawn around found text
- Cropping is applied to the final canvas
To update the source PDF for a new semester:
- Replace
examData.pdfwith the new file (keep the same name) - Run the conversion script:
python pdf_converter.py examData.pdf exam_data.json - Verify the generated
exam_data.jsonhas correct data - Update the title in
index.htmlto reflect the new semester
To change the UI appearance:
- Colors: Update background colors and text colors in
index.htmlandstyles.css - Layout: Modify the flex containers and grid layouts in HTML
- Responsive Breakpoints: Adjust media queries in the CSS section
To modify PDF highlighting or cropping:
-
Highlight Color: Change the
fillStyleinpdf-helper.jscontext.fillStyle = 'rgba(255, 0, 0, 0.25)'; // Change to desired color/opacity
-
Highlight Width: Adjust the expansion factor
const extraWidth = highlightWidth * 0.04; // Change the multiplier as needed
-
Cropping Percentages: Update values in
pdf-screenshot-helper.jsconst cropPercentages = { left: 9, // Adjust as needed right: 9, // Adjust as needed top: 2, // Adjust as needed bottom: 2 // Adjust as needed };
-
PDF Not Rendering:
- Check console for PDF.js errors
- Verify PDF.js worker is properly loaded
- Ensure PDF file path is correct
-
Course Data Not Loading:
- Check browser console for JSON parsing errors
- Verify
exam_data.jsonexists and is properly formatted
-
Highlighting Not Working:
- Ensure text search terms match exactly what's in the PDF
- Check if PDF text extraction is working correctly
- Try adjusting the search algorithm in
findTextInPage()
-
Screenshot Functionality Not Working:
- Verify html2canvas library is properly loaded in the browser console
- Check if PDF_SCREENSHOT_HELPER_LOADED is true in the console
- Look for error messages about cropping or canvas manipulation
- Try disabling browser extensions that might interfere with canvas operations
- Check if the browser supports canvas operations and downloading files
-
Responsive Layout Issues:
- Test with different viewport sizes in browser dev tools
- Verify media queries are correctly applied
- Check for overflow issues in flexbox containers
If you encounter issues with screenshots:
-
Bottom Row Cutting Off:
- The application has been fixed to prevent bottom row cutting by:
- Setting explicit container overflow to visible
- Adding extra margin and padding at the bottom
- Using configurable padding for all cells
- Setting explicit container height with extra space
- Adding a rendering delay before capture
- Using the onclone callback to ensure proper styling
- The application has been fixed to prevent bottom row cutting by:
-
Screenshot Quality and Zoom Issues:
scale: 3is set by default in html2canvas options for high-quality output- Can be configured with the
scaleoption in the takeScreenshot function - Set explicit width on the container to match the original table
- Test-screenshot.html has UI controls to adjust scale between 1-4x
-
Missing Elements in Screenshots:
- Check that all elements have explicit colors set (especially text)
- Ensure container is properly attached to the document before capture
-
Testing Screenshots:
- Use the test-screenshot.html file to test in isolation
- Compare with the PDF cross-check functionality
- Verify both features function with different screen sizes
- Use
pdf-debug.jsfor debugging PDF processing issues - Add
console.log()statements to trace data flow - Monitor network requests to ensure PDF and JSON files are loading
- Test PDF text extraction with
page.getTextContent()in browser console
Potential areas for future development:
- Conflict Detection: Warning for overlapping exam times
- Dark/Light Mode Toggle: Support for different color schemes
- User Preferences: Save and restore course selections
This documentation was created on May 17, 2025. Please update as necessary when making significant changes to the codebase.