//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.AI;usingDsPdfWeb.Demos.Common; namespaceDsPdfWeb.Demos{// This sample uses the PDF AI Assistant (DsPdfAI) to analyze the document content,// generate a summary of the PDF, and insert it as the first page.//// A summary provides a general overview of the document's main points and structure,// offering a broader and more narrative digest than an abstract. // See the AiGetAbstract sample for how to generate an abstract of a PDF.//// To run this sample locally, set your OpenAI credentials// using Util.OpenAIToken. publicclassAiGetSummary {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Wetlands.pdf")); doc.Load(fs);try {var a = newOpenAIDocumentAssistant(Util.OpenAIToken);var task = a.GetSummary(doc); task.Wait();var page = doc.Pages.Insert(0);Util.AddNote("Summary generated using DsPdf AI Assistant\n\n" + task.Result, page); }catch (Exception ex) {// Make sure you have assigned your OpenAI API key to Util.OpenAIToken:Util.CreatePdfError(doc, ex.Message); } doc.Save(stream);return doc.Pages.Count; } }}