notebook
An AI-powered web application built with React and TypeScript that converts static PDF files into interactive, editable study notebooks using the Google Gemini API. It features real-time Markdown streaming, intelligent content summarization, on-demand content expansion, searching, and custom quiz generation based on saved material, all managed client-side using local storage.
Building the AI PDF Notebook: Transforming Static Documents into Interactive Study Guides
Static documents, especially lengthy PDFs, are a major bottleneck in the study process. They are hard to annotate, impossible to reorganize, and lack dynamic intelligence. The AI PDF Notebook project was created to solve this, leveraging the power of modern web technologies and the Google Gemini API to transform rigid PDFs into flexible, editable, and AI-enhanced study materials.
This application is a feature-rich Single Page Application (SPA) focusing heavily on client-side processing, real-time feedback, and structured AI output.
Core Features: Interactivity Meets Intelligence
1. PDF Conversion and Streaming Summarization
When a user uploads a PDF, the application doesn't upload the file to a traditional backend server. Instead, it converts the PDF file locally into a base64-encoded part and sends it directly to the Gemini API (gemini-2.5-flash) via the client-side services layer.
The AI is prompted to generate a comprehensive, structured lesson in Markdown format. Critically, this generation is streamed back to the frontend. This provides a highly responsive user experience, where the notebook content appears block-by-block, reducing perceived latency during the summarization phase. The App.tsx handles this streaming update by managing a temporary streamingId content block until the stream is complete and the full Markdown can be reliably parsed.
2. Dynamic Content Structure and Editing
The notebook uses Markdown as its source-of-truth. However, for interactive editing and navigation, the raw Markdown text is broken down into an array of ContentBlock objects using marked.lexer.
- Dynamic Table of Contents (ToC): The
parseMarkdownfunction generates a structured ToC from heading tokens (#and##). This ToC is used in theSidebarfor easy navigation, augmented by anIntersectionObserverto highlight the active section as the user scrolls, mirroring modern documentation sites. - In-Place Editing: Users can double-click any block (
NotebookBlock.tsx) to enter edit mode. Changes are saved back to the block'srawproperty, and the entirerawMarkdownstate is regenerated (regenerateMarkdown) and re-parsed, ensuring data consistency and maintaining Markdown structure.
3. AI-Powered Study Tools
The core value proposition lies in the AI-enhanced actions available on every content block:
- Smart Expansion (
handleExpand): Clicking the sparkle icon sends a small chunk of text (or an entire section if it's a heading) back to Gemini, asking it to provide a more detailed, expanded explanation. This is essential for converting brief notes into deep dives. - Custom Prompting (
handleCustomPrompt): Users can ask a direct question about a specific text block or section. This allows for targeted Q&A, leveraging the context of the user's notes for highly relevant answers.
Both expansion and custom prompting utilize the streaming infrastructure to update the UI efficiently.
4. Structured Quiz Generation
A major feature is the ability to generate quizzes from one or more saved notebooks. This is achieved through a sophisticated use of Gemini's structured output capabilities (responseSchema):
- The user selects notebooks and the desired number of questions in the
QuizSetupModal. - The combined content is sent to Gemini with a request to generate a multiple-choice quiz.
- The
quizSchemaenforces that the AI returns a valid JSON array matching theQuizQuestioninterface (question, 4 options, and a correct answer field). - The generated quiz is then saved to local storage and presented in the
QuizView, allowing users to test their knowledge and track their results over multiple attempts (QuizHistoryView).
Technical Implementation Details
Frontend Stack
The application is built using React and TypeScript managed by Vite. Styling is handled primarily through Tailwind CSS (via custom variables defined in index.html and utility classes), ensuring a clean, modern, and responsive interface.
Client-Side Persistence
Notebooks and quiz history are persisted using the browser's Local Storage.
- Current notebook content is saved under
'ai-pdf-notebook-content'. - Saved versions are timestamped (e.g.,
'ai-pdf-notebook-{timestamp}'), allowing for a view of past versions and enabling quiz generation across multiple documents.
This architecture keeps user data private and avoids the need for a persistent backend database, simplifying deployment and enhancing user privacy.
UI State Management
The App.tsx acts as the main state controller, managing view modes (ViewMode), content blocks, search results, and quiz state. The use of React.useCallback and React.useMemo ensures high performance, particularly during the intensive Markdown parsing steps triggered by content changes or streaming completions.
Code Rendering and Highlighting
The NotebookBlock.tsx uses marked.parse for rendering Markdown to HTML. Since the code needs to support highlighting in the editor, the application integrates highlight.js, configuring marked globally via marked.setOptions({ langPrefix: 'hljs language-' }) to ensure proper syntax highlighting for any code blocks output by the AI or manually entered by the user.
Built with
Related work
- verilookieVerilookie is a full-stack web application that provides unified deepfake and AI-generated media detection…
- portfolioA sophisticated, self-updating portfolio platform built on Next.js and TypeScript…
- lead-generationA high-performance B2B lead generation engine built on FastAPI and Google Gemini (GenAI SDK).