//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem;usingSystem.IO;usingSystem.Collections.Generic;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// and generate an outline tree (bookmarks) based on inferred headings, which is then added to the PDF.//// To run this sample locally, set your OpenAI credentials// using Util.OpenAIToken. publicclassAiBuildOutlines {publicintCreatePDF(Stream stream, int paramsIdx = 0) {returnCreatePDF(stream, GetSampleParamsList()[paramsIdx]); } publicintCreatePDF(Stream stream, string[] sampleParams) {var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", sampleParams[3])); doc.Load(fs);try {var a = newOpenAIDocumentAssistant(Util.OpenAIToken);var task = a.BuildOutlines(doc); task.Wait(); doc.PageMode = PageMode.UseOutlines; }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; } publicstaticList<string[]> GetSampleParamsList() {// Items are: name, description, info, PDF name:returnnewList<string[]>() {newstring[] { "@ai-outlines/Newsletter", "Use DsPdfAI to generate outlines for a newsletter", "","Newsletter.pdf" },newstring[] { "@ai-outlines/Financial Report", "Use DsPdfAI to generate outlines for a financial report", "","FinancialReport.pdf" },newstring[] { "@ai-outlines/Lease Proposal", "Use DsPdfAI to generate outlines for a lease proposal", "","Commercial_Real_Estate_Lease_Proposal.pdf" },newstring[] { "@ai-outlines/Lease Agreement", "Use DsPdfAI to generate outlines for a lease agreement", "","LeaseAgreement.pdf" }, }; } }}