Textbook to Courseware and Exercises with Spire.Agent.Office

2026-10-10 01:20:35 Written by  liu talia
Rate this item
(0 votes)

Lesson preparation usually means doing the same work twice. A textbook lays out concepts, worked examples and exercises chapter by chapter, complete and detailed; a deck has to be reorganised into pages fit for the classroom. Teachers condense the material into a handful of points per slide, add the examples and diagrams, split the exercises into one question per page, and prepare answers for review. None of this is technically hard, but it is time-consuming, and every textbook revision means doing it all again.

The Presentation AI in Spire.Agent.Office hands this step to an AI agent: pass the PDF textbook in as an attachment, describe in natural language how the deck should be organised and presented, and the agent reads the material and generates the slides. It produces either a lecture deck (one page per section, with concepts, examples and speaker notes) or an exercise deck (one question per page, with answers revealed as animations on the page).

Comparison with Traditional SDK API

Traditional Spire.Office for .NET API Spire.Agent.Office
Driving style Walk the PDF pages to extract text and graphics, then create slides and text boxes page by page, coding all the pagination and layout logic yourself Pass the textbook in as an attachment, describe how the deck should be organised and presented in natural language, and let the AI orchestrate the execution path
Code size Usually 200-400 lines of C# (page parsing, slide creation, layout, speaker-note writing) About 10 lines of calling code + 1 natural-language instruction
Content extraction Rewrite long passages into points by hand and pick the examples and redraw the diagrams yourself The AI reads the textbook and extracts content under a "points + examples + diagrams" rule
Layout and notes Set the layout, font sizes, master and speaker notes of each new slide by hand The AI applies one consistent layout and writes the teaching notes into the notes pane
Requirement change Change the page count or level of detail → change code → compile → redeploy Modify the instruction and it takes effect immediately

This article shows how to use Spire.Agent.Office to generate PowerPoint decks from a PDF textbook. Two cases demonstrate the two typical uses — "generating a lecture deck from a textbook" and "generating an exercise deck from a textbook":

For product installation and SpireToken configuration, please refer to Integrating Spire.Agent.Office in a .NET Project. The examples below assume that Spire.Agent.Office has been installed and SpireToken has been configured.


Case 1: Generate a lecture deck from a textbook

A textbook is complete and logically coherent, but it cannot be projected as it is — a whole paragraph becomes a wall of small text on screen, and the hierarchy that the textbook conveys through layout has to be rebuilt with pages. What a teacher needs to do is reorganise it section by section: keep that section's core concepts, formulas and typical worked examples, rewrite long passages into points that read well in class, and carry over the textbook's diagrams. Each page must hold enough to support a full lesson without copying whole paragraphs, or it becomes too dense to read. The deck as a whole then uses one consistent layout: a light colour theme, page-by-page animations and a few supporting images, with body text no smaller than 24 pt.

How the examples are presented matters most. A textbook usually derives a formula or theorem before stating the conclusion; if the deck only carries the conclusion across, students cannot see where it comes from, so the instruction requires examples to keep their full derivation. What the teacher needs to be reminded of while teaching — the emphasis on that page, the common mistakes and the pacing — goes into the speaker notes, invisible when projected and shown only in Presenter View. The example below passes the PDF textbook in as an attachment:

using Spire.Agent.Office.AI;
using Spire.Agent.Office.Extensions;
using Spire.Presentation;

// the textbook file passed in as an attachment
string[] attachmentPaths = new string[]
{
    @"E:\textbook\Proportion.pdf"
};

// PPT-related configuration
string inputPath = null;  // the deck is generated from scratch, so no input PPT is needed
string savePath = @"E:\textbook\Proportion.ppt";  // result path
string key = "**************************";  // SpireToken key
string instruction =
    "Read the attached PDF textbook and generate a lecture deck as follows:" +
    "1. Follow the textbook's original chapter order and omit nothing;" +
    "2. Make each page substantial: list the chapter's core concepts and formulas, together with the textbook's typical worked examples;" +
    "3. Worked examples must show the full derivation steps, not just the conclusion;" +
    "4. Keep the diagrams, tables and data from the textbook and use them to support the explanation so that students can follow;" +
    "5. Write speaker notes for each page covering the key points, common mistakes and pacing;" +
    "6. Apply one consistent layout to every page, use a light colour theme, add appropriate animations and images, and keep body text at 24 pt or larger;" +
    "Save the final result as a PPT file";

// Call the PPT document processing function
AIResult result = ExecuteDemoPpt(instruction, inputPath, savePath, key, attachmentPaths);

// Execute the PPT AI processing
static AIResult ExecuteDemoPpt(string instruction, string inputPath, string savePath, string key, string[] attachmentPaths)
{
    // Create the AIOptions configuration object
    AIOptions options = new AIOptions();
    options.SpireToken = key;  // set the SpireToken key

    // Process the PPT document with a Presentation object
    using (Presentation ppt = new Presentation())
    {
        // Load the PPT document from file (not needed when generating a deck from scratch)
        if (!string.IsNullOrEmpty(inputPath) && File.Exists(inputPath))
        {
            ppt.LoadFromFile(inputPath);
        }
        // Create the AI document processor
        AIDocumentProcessor processor = ppt.AI(options);

        // Execute the AI instruction
        return processor.ExecuteInstruction(ppt, instruction, savePath, attachmentPaths);
    }
}

A lecture deck generated from the textbook

A lecture deck generated from the textbook


Case 2: Generate an exercise deck from a textbook

The exercise set is after-class practice: students work through it on their own, and the teacher walks through it question by question in the next lesson. On slides the exercises need one question per page, with the answer built as an animation that only appears when the teacher reaches that question, so students judge for themselves first and then check their reasoning against the walkthrough.

Moving a set of exercises onto slides, however, is a fair amount of work: the exercises run as a continuous sequence of numbered items packed several to a page, so each one has to be picked out and re-laid-out one question per page; the tables and diagrams inside the questions must be carried over too, or students cannot read the question; and the answers needed for the walkthrough have to be worked out one by one and built as animations. This case treats the exercise deck as a standalone deliverable: pass the PDF of the after-class exercises in as an attachment, and the AI extracts and lays out each question, with the question always on the page and the answer revealed as an animation when the teacher triggers it:

using Spire.Agent.Office.AI;
using Spire.Agent.Office.Extensions;
using Spire.Presentation;

// the textbook's exercise section passed in as an attachment
string[] attachmentPaths = new string[]
{
    @"E:\textbook\ProportionExercises.pdf"
};

// PPT-related configuration
string inputPath = null;  // the deck is generated from scratch, so no input PPT is needed
string savePath = @"E:\textbook\ProportionExercises.ppt";  // result path
string key = "**************************";  // SpireToken key
string instruction =
    "Read the attached PDF textbook exercises and generate an exercise deck as follows:" +
    "1. Follow the textbook's original question order, one question per page, omitting and merging nothing;" +
    "2. Keep the full question text, options and diagrams so that students can answer directly;" +
    "3. Show the answers as animations;" +
    "4. Apply one consistent layout to every page, use a light colour theme, add appropriate animations and images, and keep body text at 24 pt or larger;" +
    "Save the final result as a PPT file";

// Call the PPT document processing function
AIResult result = ExecuteDemoPpt(instruction, inputPath, savePath, key, attachmentPaths);

// Execute the PPT AI processing
static AIResult ExecuteDemoPpt(string instruction, string inputPath, string savePath, string key, string[] attachmentPaths)
{
    // Create the AIOptions configuration object
    AIOptions options = new AIOptions();
    options.SpireToken = key;  // set the SpireToken key

    // Process the PPT document with a Presentation object
    using (Presentation ppt = new Presentation())
    {
        // Load the PPT document from file (not needed when generating a deck from scratch)
        if (!string.IsNullOrEmpty(inputPath) && File.Exists(inputPath))
        {
            ppt.LoadFromFile(inputPath);
        }
        // Create the AI document processor
        AIDocumentProcessor processor = ppt.AI(options);

        // Execute the AI instruction
        return processor.ExecuteInstruction(ppt, instruction, savePath, attachmentPaths);
    }
}

An exercise deck generated from the textbook

An exercise deck generated from the textbook


FAQ

The body text is copied straight from the textbook and is too small to project

Cause: The instruction does not say what each page should hold, so the AI carries whole paragraphs onto the page and shrinks the font to fit them in.

Solution: Ask explicitly for each page to list the core concepts and formulas with the typical worked examples, and to keep the textbook's diagrams and tables, rather than copying whole paragraphs across; also set a minimum font size (for example, "keep body text at 24 pt or larger"). Constrain only the font size and the enlarged text overflows the page; constrain only the form of the content with no lower bound and the layout may still be squeezed.

A long textbook takes a very long time, or times out

Cause: Deck generation runs page by page, and the AI repeatedly reads and writes the document, sending the existing content back to the model each time. The more pages there are and the denser the text on each, the faster token use and elapsed time grow.

Solution: Set TimeoutMs (in milliseconds) when creating AIOptions. A full textbook of several dozen pages can be given 10 minutes (600000).

AIOptions options = new AIOptions();
options.TimeoutMs = 600000;  // allow 10 minutes for a long textbook
options.SpireToken = key;

Getting a SpireToken Key

Configure it in your code:

AIOptions options = new AIOptions();
options.SpireToken = key;