How to use OpenAI for PDF in C# with IronPDF
IronPDF's AI extension enables OpenAI-powered PDF enhancement in C# applications. Add summarization, querying, and memorization features using Microsoft Semantic Kernel with minimal code.
OpenAI is an AI research laboratory that develops advanced artificial intelligence technologies. It provides powerful language models accessible through APIs, enabling developers to integrate AI capabilities into their applications.
The IronPdf.Extensions.AI NuGet package brings OpenAI to PDF processing: summarization, querying, and memorization. Built on Microsoft Semantic Kernel, this SDK simplifies AI service integration in .NET applications. Extract insights, answer questions, and generate summaries from PDF documents automatically.
Key use cases include processing large document volumes, extracting information from reports, creating quick-review summaries, and building intelligent document management systems. The integration supports both one-time summarization and continuous querying for various applications. For more PDF features, explore IronPDF's comprehensive documentation or learn about creating PDFs from HTML.
Quickstart: Summarize PDFs with IronPDF and OpenAIStart integrating OpenAI into your PDF processing workflow with IronPDF in C#. This example demonstrates quick PDF summarization with just a few lines of code.
-
1Install IronPDF with NuGet Package Manager
-
2Copy and run this code snippet.
// Install-Package IronPdf.Extensions.AI await IronPdf.AI.PdfAIEngine.Summarize("input.pdf", "summary.txt", azureEndpoint, azureApiKey);C# -
3Deploy to test on your live environment
Start using IronPDF in your project today with a free trial
Minimal Workflow (5 steps)
- Download the C# library to utilize OpenAI for PDF
- Prepare the Azure Endpoint and API Key for OpenAI
- Import the target PDF document
- Use the
Summarizemethod to generate a summary of the PDF - Use the
Querymethod for continuous querying
Required packages:
Before implementing AI features, set up Azure OpenAI. You need an Azure subscription with Azure OpenAI Service access. The service provides enterprise-grade security and compliance for production applications. See the IronPDF installation overview for detailed instructions.
How Do I Summarize PDFs with OpenAI?
To use OpenAI features, configure the Semantic Kernel with your Azure Endpoint and API Key. Import the PDF document and use the Summarize method to generate summaries.
The summarization feature works with various PDF types:
- Scanned documents (when combined with OCR)
- Complex layouts with multiple columns
- Documents containing images and tables
IronPDF extracts text content and processes it through the AI model. For different formats, see converting DOCX to PDF or converting Markdown to PDF.
SKEXP0001, SKEXP0010, and SKEXP0050 errors because Semantic Kernel methods are experimental. Add this to your .csproj file to suppress them: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NoWarn>$(NoWarn);SKEXP0001,SKEXP0010,SKEXP0050</NoWarn>
</PropertyGroup>
</Project>
Here's how to summarize a PDF using Semantic Kernel in C#:
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
.AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
.AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();
// Setup Memory
var memory_builder = new MemoryBuilder()
// optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
.WithMemoryStore(new VolatileMemoryStore())
.WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();
// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);
License.LicenseKey = "<<enter your IronPdf license key here";
// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Summarize the document
Console.WriteLine("Please wait while I summarize the document...");
string summary = await pdf.Summarize(); // optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}\n\n");Imports Microsoft.VisualBasic
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Connectors.OpenAI
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks
' Setup OpenAI
Private azureEndpoint = "<<enter your azure endpoint here>>"
Private apiKey = "<<enter your azure API key here>>"
Private builder = Kernel.CreateBuilder().AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey).AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey)
Private kernel = builder.Build()
' Setup Memory
Private memory_builder = (New MemoryBuilder()).WithMemoryStore(New VolatileMemoryStore()).WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
Private memory = memory_builder.Build()
' Initialize IronAI
IronDocumentAI.Initialize(kernel, memory)
License.LicenseKey = "<<enter your IronPdf license key here"
' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Summarize the document
Console.WriteLine("Please wait while I summarize the document...")
Dim summary As String = Await pdf.Summarize() ' optionally pass AI instance or use AI instance directly
Console.WriteLine($"Document summary: {summary}" & vbLf & vbLf)The code initializes both Semantic Kernel and memory store. Memory stores maintain context during continuous queries. Choose from:
VolatileMemoryStore: In-memory storage for development and testingChromaMemoryStore: Persistent vector database for production- Other stores: Azure Cognitive Search, Qdrant, and more
For production, implement error handling and custom logging to track AI operations. Explore async and multithreading for processing multiple documents simultaneously.
What Does the Summary Output Look Like?

The summary provides a concise document overview, extracting main topics, important facts, and relevant details. The AI model identifies and prioritizes significant content, enabling quick understanding of lengthy documents.
How Do I Query PDFs Continuously?
Single queries don't suit all scenarios. The IronPdf.Extensions.AI package offers a Query method for continuous queries. Build conversational interfaces, research tools, or document analysis applications where users ask multiple questions about the same document.
Continuous querying maintains conversation context, allowing follow-up questions and clarifications. Ideal for:
- Customer support systems referencing documentation
- Legal document analysis requiring clause interpretation
- Educational applications for studying complex materials
- Research tools extracting specific information
For enhanced processing, consider extracting text and images separately or implementing PDF compression to optimize large documents before AI processing.
using IronPdf;
using IronPdf.AI;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.OpenAI;
using Microsoft.SemanticKernel.Memory;
using System;
using System.Threading.Tasks;
// Setup OpenAI
var azureEndpoint = "<<enter your azure endpoint here>>";
var apiKey = "<<enter your azure API key here>>";
var builder = Kernel.CreateBuilder()
.AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
.AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey);
var kernel = builder.Build();
// Setup Memory
var memory_builder = new MemoryBuilder()
// optionally use new ChromaMemoryStore("http://127.0.0.1:8000") (see https://github.com/microsoft/semantic-kernel/blob/main/dotnet/notebooks/09-memory-with-chroma.ipynb)
.WithMemoryStore(new VolatileMemoryStore())
.WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey);
var memory = memory_builder.Build();
// Initialize IronAI
IronDocumentAI.Initialize(kernel, memory);
License.LicenseKey = "<<enter your IronPdf license key here";
// Import PDF document
PdfDocument pdf = PdfDocument.FromFile("wikipedia.pdf");
// Continuous query
while (true)
{
Console.Write("User Input: ");
var response = await pdf.Query(Console.ReadLine());
Console.WriteLine($"\n{response}");
}Imports Microsoft.VisualBasic
Imports IronPdf
Imports IronPdf.AI
Imports Microsoft.SemanticKernel
Imports Microsoft.SemanticKernel.Connectors.OpenAI
Imports Microsoft.SemanticKernel.Memory
Imports System
Imports System.Threading.Tasks
' Setup OpenAI
Private azureEndpoint = "<<enter your azure endpoint here>>"
Private apiKey = "<<enter your azure API key here>>"
Private builder = Kernel.CreateBuilder().AddAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey).AddAzureOpenAIChatCompletion("oaichat", azureEndpoint, apiKey)
Private kernel = builder.Build()
' Setup Memory
Private memory_builder = (New MemoryBuilder()).WithMemoryStore(New VolatileMemoryStore()).WithAzureOpenAITextEmbeddingGeneration("oaiembed", azureEndpoint, apiKey)
Private memory = memory_builder.Build()
' Initialize IronAI
IronDocumentAI.Initialize(kernel, memory)
License.LicenseKey = "<<enter your IronPdf license key here"
' Import PDF document
Dim pdf As PdfDocument = PdfDocument.FromFile("wikipedia.pdf")
' Continuous query
Do
Console.Write("User Input: ")
Dim response = Await pdf.Query(Console.ReadLine())
Console.WriteLine($vbLf & "{response}")
LoopThe continuous query system uses embeddings to understand question semantics, providing accurate, contextual responses. Each query processes against document content, with AI maintaining conversation history for increasingly relevant answers.
For optimal performance with large documents or concurrent users, implement caching strategies and explore IronPDF's performance optimization techniques. Consider rate limiting and proper license key management for production deployments.
When handling sensitive documents, implement appropriate security measures. IronPDF offers various security and encryption options to protect PDFs before and after AI processing.
Frequently Asked Questions
What features does IronPDF's AI extension provide for PDF processing?
IronPDF's AI extension offers features like summarization, querying, and document insights powered by OpenAI. These capabilities are built on Microsoft's Semantic Kernel, enabling effective AI integration in C# applications.
How can I integrate OpenAI with IronPDF for PDF summarization in C#?
To integrate OpenAI with IronPDF for PDF summarization in C#, use the IronPdf.Extensions.AI NuGet package. You need to configure your Azure Endpoint and API Key, and then utilize the `Summarize` method to generate concise PDF summaries.
What are the prerequisites for using OpenAI features with IronPDF?
Before using OpenAI features with IronPDF, you need an Azure subscription with access to the Azure OpenAI Service. It's also important to install the necessary NuGet packages such as IronPdf.Extensions.AI and configure your project properly.
What types of PDFs can be summarized using IronPDF and OpenAI?
IronPDF and OpenAI can summarize various PDF types, including scanned documents (with OCR), complex layouts, and documents containing images and tables. The AI model processes text content to provide comprehensive summaries.
How does the continuous querying feature in IronPDF work?
Continuous querying in IronPDF allows for ongoing interaction with PDFs. Using the `Query` method, you can ask multiple questions within the same document context, making it ideal for applications like customer support and legal document analysis.
Can I use IronPDF's AI extension for legal document analysis?
Yes, IronPDF's AI extension is suitable for legal document analysis. The continuous querying feature can be particularly useful for interpreting clauses and extracting specific information within legal texts.
What memory options are available for context in continuous querying?
To maintain context during continuous querying, you can choose memory options like `VolatileMemoryStore` for development or `ChromaMemoryStore` for production. These options help manage and store the conversation context effectively.
How does IronPDF ensure security when handling sensitive PDF documents?
IronPDF offers various security and encryption options to protect PDFs, including permissions and password protection. These options help secure documents before and after AI processing, ensuring sensitive information is safeguarded.
What is the role of Microsoft Semantic Kernel in IronPDF's AI extension?
Microsoft Semantic Kernel is the foundation for IronPDF's AI extension, facilitating the integration of AI services in .NET applications. It powers features like summarization and querying by providing structured support for OpenAI capabilities.
How can I optimize performance when using IronPDF's AI features?
For optimal performance with IronPDF's AI features, consider caching strategies, implementing rate limiting, and using optimized deployment configurations. The documentation also suggests techniques for managing performance with large documents and concurrent users.

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.