Friday, October 3, 2025
HomeC#Combine AI Assistant into Blazor PDF Viewer to Enhance Productiveness 

Combine AI Assistant into Blazor PDF Viewer to Enhance Productiveness 


TL;DR: Let’s see the best way to combine AI Assistant into the Blazor PDF Viewer for smarter doc dealing with. Leverage AI-powered summarization, redaction, and form-filling to automate tedious duties. Enhance productiveness and simplify PDF administration in your Blazor apps!

In at present’s fast-paced digital atmosphere, environment friendly doc administration is important. PDFs play a vital position in contracts, varieties, analysis papers, and different paperwork; nevertheless, enhancing and managing them can usually be difficult and time-consuming. That is the place the PDF Viewer with AI Assistant is available in, providing a wise, environment friendly resolution to streamline workflows, save time, and simplify working with PDFs.

By harnessing the ability of synthetic intelligence, Syncfusion Blazor PDF Viewer goes past commonplace doc show. It helps clever options corresponding to good summarizer, good redact, and good type fill, reworking person expertise, automating guide duties, and boosting productiveness.

Let’s see the best way to combine AI Assistant within the Blazor PDF viewer to ease the PDF dealing with course of.

Be aware: Earlier than continuing, seek advice from the getting began with Blazor PDF Viewer documentation.

Conditions

Azure OpenAI API key: Go to the Azure OpenAI web site, create an account, and acquire your API key. Within the Program.cs file, enter your AI key for the service, alongside together with your endpoint and deployment title.

// Azure OpenAI Service
string apiKey = "your-api-key";
string deploymentName = "your-deployment-name";
// your-azure-endpoint-url
string endpoint = "";

Sensible doc summarizer in Blazor PDF Viewer: Streamlining data within the digital age

In at present’s digital age, the explosion of data has made it important to effectively and rapidly course of huge quantities of textual content. The AI-powered doc summarizer in Blazor PDF Viewer gives a strong resolution to those trendy doc administration challenges.

This superior instrument analyzes and condenses prolonged paperwork into temporary, centered summaries. By highlighting the doc’s key factors, it saves time and makes it straightforward to understand important data with out studying each element. Moreover, the doc summarizer permits customers to navigate on to reference pages, offering fast entry to the unique context of summarized content material. Customers may also ask questions associated to the doc, and it’ll present correct solutions, providing a extra interactive option to discover and perceive the content material. This makes it even simpler to dive deeper into particular particulars when wanted, making it a crucial help for navigating massive volumes of data rapidly and successfully. 

Initialize the Blazor PDF Viewer

This part units up the Blazor PDF Viewer part, specifying the DocumentPath and zoom mode for displaying the PDF file. It additionally attaches occasion handlers (DocumentLoaded, DocumentUnloaded) to handle the doc’s lifecycle.

Check with the next code instance.

<SfPdfViewer2 @ref="sfPdfViewer2" DocumentPath="https://cdn.syncfusion.com/content material/pdf/pdf-succinctly.pdf" ZoomMode="ZoomMode.FitToPage">
  <PdfViewerEvents DocumentLoaded="DocumentLoaded" DocumentUnloaded="DocumentUnLoaded"></PdfViewerEvents>
</SfPdfViewer2>

Integrating AI service into Blazor PDF Viewer

The SummaryPDF perform checks if the doc has been loaded into the AI service. If not, it fetches the PDF doc as a byte array, masses it into the AI-powered summarizer, after which generates a concise abstract based mostly on the AI service’s response.

Check with the next code instance.

personal async Process<string> SummaryPDF()
{
   string systemPrompt = "You're a useful assistant. Your job is to investigate the supplied textual content and generate a brief abstract.";
   if (!isDocumentLoadedInAI)
   {
      byte[] bytes = await sfPdfViewer2.GetDocumentAsync();
      documentStream = new MemoryStream(bytes);
      await summarizer.LoadDocument(documentStream, "software/pdf");
      isDocumentLoadedInAI = true;
   }
   //Get the abstract of the PDF
   return await summarizer.FetchResponseFromAIService(systemPrompt);
}

Summarizing the PDF content material

This half processes the AI response by splitting the consequence into two components: 

It assigns the suitable part to the args.Response property and shops the extra strategies individually for additional use.

Check with the next code instance.

var response = await summarizer.GetAnswer(args.Immediate);
// Cut up by "strategies"
string[] responseArray = response.Cut up(new[] { "strategies" }, StringSplitOptions.None);
if (responseArray.Size > 1)
{
   args.Response = responseArray[0];
   strategies = responseArray[1];
}

Check with the next output picture.

Summarizing the PDF content using AI and Blazor PDF Viewer
Summarizing the PDF content material utilizing AI and Blazor PDF Viewer

We’ve utilized the Blazor AI AssistView part to design the good summarize demo. For extra particulars, seek advice from its documentation and demo.

Be aware: Additionally, seek advice from the good summarizer in Blazor PDF Viewer demos on the net and GitHub.

Sensible redact in Blazor PDF Viewer: Safeguarding delicate data with AI 

Redaction entails eradicating or obscuring delicate data in a doc to make sure privateness and confidentiality.

With Blazor PDF Viewer’s good redaction function, customers can select particular patterns, corresponding to emails or names, to determine them as delicate data inside a doc. The AI then detects and highlights this content material. If any recognized particulars aren’t delicate, customers have the choice to assessment and deselect them earlier than making use of the redaction. This method ensures a streamlined and correct course of for safeguarding personal information.

Guide redaction

For many who choose a hands-on method, guide redaction permits customers to pick particular content material to be hid straight. This function gives exact management over the parts in a PDF doc that should be redacted, making it an ideal complement to the AI’s automated detection. By offering further customization choices, it ensures that solely the specified delicate data is protected.

Initializing the Blazor PDF Viewer

Let’s initialize the Blazor PDF Viewer with superior settings. It hyperlinks doc lifecycle occasions (DocumentLoaded, DocumentUnLoaded) and different interplay occasions like AnnotationAdded, AnnotationRemoved, and ZoomChanged to deal with person interactions and state modifications.

Check with the next code instance.

<SfPdfViewer2 @ref="sfPdfViewer2" DocumentPath="@documentPath" Width="100%" Peak="calc(100% - 40px)" rectangleSettings="@rectangleSettings" EnableToolbar="false" EnableAnnotationToolbar="false" DownloadFileName="SmartRedaction.pdf" ZoomMode="ZoomMode.FitToPage">
  <PdfViewerEvents DocumentLoaded="DocumentLoaded" DocumentUnloaded="DocumentUnLoaded" AnnotationAdded="OnAddAnnotation" AnnotationRemoved="OnRemoveAnnotation" ZoomChanged="OnZoomChanged"></PdfViewerEvents>
  <PdfViewerContextMenuSettings ContextMenuItems="contextMenuItems"></PdfViewerContextMenuSettings>
</SfPdfViewer2>

Integrating AI service into Blazor PDF Viewer

The LoadDocument technique masses the PDF doc into the AI service for processing. It retrieves the doc as a byte array from the SfPdfViewer2 part, converts it right into a stream, and sends it to the AI-powered redaction instrument (Sensible redaction). The instrument extracts delicate textual content from the doc and returns it as a listing for additional processing.

Check with the next code instance.

personal async Process<Checklist<string>> LoadDocument()
{
  Checklist<string> extractedTextList = new Checklist<string>();
  if (sfPdfViewer2 != null && smartRedaction != null)
  {
     //Load the doc to the AI and get the extracted textual content
     byte[] bytes = await sfPdfViewer2.GetDocumentAsync();
     documentStream = new MemoryStream(bytes);
     extractedTextList = await smartRedaction.LoadDocument(documentStream, "software/pdf");
  }
  return extractedTextList;
}

Redacting delicate data in a PDF

Let’s set up the extracted textual content right into a hierarchical construction, grouping delicate textual content nodes by pageNumber to symbolize the web page they seem on. The grouped nodes are used to construct a TreeItem construction for simple navigation. A Choose All possibility is included to use actions to all delicate data without delay, with an up to date isDataRendered flag indicating when the info is prepared for rendering within the PDF Viewer.

Check with the next code instance.

// Group childNodes by pageNumber
var groupedByPage = childNodes.GroupBy(node => node.pageNumber)
    .Choose(group => new TreeItem
    {
       NodeId = group.Key.ToString(),
       NodeText = "Web page " + (group.Key + 1),
       pageNumber = group.Key,
       Expanded = true,
       Youngster = group.ToList(),
       IsChecked = true
    })
    .ToList();
sensitiveInfo.Add(new TreeItem
{
    NodeId = "Choose All",
    NodeText = $"Choose All ({this.textBoundsCount})",
    Expanded = true,
    Youngster = groupedByPage
});
isDataRendered = true;

Check with the next output picture.

Redacting sensitive information in a PDF using AI and Blazor PDF Viewer
Redacting delicate data in a PDF utilizing AI and Blazor PDF Viewer

Be aware: For extra particulars, seek advice from the good redaction in Blazor PDF Viewer demos on the net and GitHub.

Sensible type fill in Blazor PDF Viewer: Enhancing information entry with AI

Sensible type fill is an AI-powered instrument designed to simplify and enhance how data is entered into varieties. Leveraging superior expertise, it streamlines information entry by making it quicker and extra correct via auto-completion in PDF varieties.

This function makes use of AI to reinforce the method of filling out varieties. It may well analyze the content material from the clipboard, robotically populate associated fields based mostly on context, validate information for accuracy, and provide strategies for corrections. This function considerably reduces guide effort and enhances information consistency in doc administration.

Initialize the Blazor PDF Viewer

Let’s arrange the Blazor PDF Viewer part inside a scrollable division with a customized peak (ViewerHeight). Occasion handlers and context menu settings are additionally connected to deal with document-loading occasions and management the viewer’s context menu.

Check with the next code instance.

<div fashion="overflow:auto;peak:@ViewerHeight;">
  <SfPdfViewer2 @ref="sfPdfViewer2" DocumentPath="@documentPath" Width="100%" Peak="100%" EnableToolbar="false" EnableAnnotationToolbar="false" DownloadFileName="SmartFill.pdf" ZoomMode="ZoomMode.FitToPage">
    <PdfViewerEvents DocumentLoaded="DocumentLoaded"></PdfViewerEvents>
    <PdfViewerContextMenuSettings ContextMenuItems="contextMenuItems"></PdfViewerContextMenuSettings>
  </SfPdfViewer2>
</div>

Integrating AI service into Blazor PDF Viewer

The GetCompletionAsync technique sends a immediate to the AI service, requesting it to course of and return the consequence as an XFDF (XML Varieties Knowledge Format) string. This string represents type subject information that may be straight imported into the PDF Viewer.

Check with the next code instance.

// Reuest to AI
string resultantXfdfFile = await openAIService.GetCompletionAsync(mergePrompt, false);

Sensible type filling utilizing Blazor PDF Viewer

Let’s course of the XFDF information returned by the AI service. Then, convert the string right into a MemoryStream and import it into the Blazor PDF Viewer utilizing the ImportFormFieldsAsync API. This enables the shape subject information to be populated within the PDF Viewer, updating the doc with AI-generated content material.

Check with the next code instance.

// Convert the string on to a MemoryStream
utilizing (MemoryStream inputFileStream = new MemoryStream(Encoding.UTF8.GetBytes(resultantXfdfFile)))
{
   // Import the shape subject information as XFDF
   if (sfPdfViewer2 != null)
   {
      await sfPdfViewer2.ImportFormFieldsAsync(inputFileStream, FormFieldDataFormat.Xfdf);
   }
}

Check with the next output picture.

Smartly filling form fields in a PDF using Blazor PDF Viewer and AI
Well filling type fields in a PDF utilizing Blazor PDF Viewer and AI

Be aware: For extra particulars, seek advice from the good type filling in Blazor PDF Viewer demos on the net and GitHub.

Syncfusion Blazor parts could be reworked into gorgeous and environment friendly net apps.

Strive It Free

Conclusion

Thanks for studying! Syncfusion Blazor PDF Viewer with AI Assistant exemplifies how expertise can improve productiveness by automating guide duties and remodeling our method to managing useful data. From summarizing intricate paperwork to redacting delicate data and automating type entries, these clever options provide a streamlined and seamless person expertise.

Embrace the way forward for doc administration with AI-powered Blazor PDF Viewer, the place innovation and ease come collectively to create smarter workflows.

Our present prospects can obtain the newest model from the license and downloads web page. In case you are not a Syncfusion buyer, strive our 30-day free trial to take a look at our latest options. 

You can too contact us via our help discussion boardhelp portal, or suggestions portal.  We’re all the time comfortable to help you! 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments