TL;DR: Let’s see auto-fill PDF kinds utilizing AI and .NET MAUI PDF Viewer. The weblog covers establishing .NET MAUI, integrating OpenAI, and utilizing AI to intelligently fill out kinds with related information. You’ll discover ways to export type information, map it with AI, and robotically populate the fields in your app. This strategy saves effort and time, particularly for complicated kinds!
Filling out PDF kinds may be tedious and time-consuming, particularly when coping with a number of paperwork. Nevertheless, with the mixing of AI and Syncfusion .NET MAUI PDF Viewer, now you can auto-fill PDF kinds shortly and effectively. This weblog will information you thru establishing and utilizing this characteristic to avoid wasting effort and time.
How does good PDF Type filling work?
Sensible PDF type filling makes use of superior AI fashions to interpret and extract related data from a given textual content content material or paragraphs copied from a clipboard. The extracted information is intelligently mapped to the suitable fields in a PDF type, together with textual content packing containers, checkboxes, record packing containers, combo packing containers, and radio buttons. This considerably reduces the necessity for guide information entry, and it’s notably helpful in situations the place massive volumes of kinds must be stuffed out or the place the kinds are complicated and detailed.
Customers can assessment and confirm the stuffed kinds to make sure accuracy. Minimal corrections is likely to be required relying on the complexity of the kinds, the provided information, and the AI response.
Conditions
Earlier than you start, guarantee you might have the next:
- OpenAI API Key: Go to the OpenAI web site to create an account and acquire your API key.
- .NET MAUI setup: Observe the set up necessities and construct your first .NET MAUI app.
App configuration
Let’s configure the .NET MAUI app by following these steps:
Step 1: Create a brand new .NET MAUI app
Start by establishing a brand new .NET MAUI challenge. This can function the inspiration in your app.
Step 2: Set up the required packages
Subsequent, we have to set up the next two key packages:
Step 3: Configure your app
As soon as the packages are put in, configure your app by following these steps:
- Create an occasion of OpenAIClient to work together with OpenAI’s providers.
OpenAIClient? openAIClient = new OpenAIClient( new Uri("https://yourendpoint.com/"), new AzureKeyCredential("AZURE_OPENAI_API_KEY") );
- Create an occasion of ChatCompletionsOptions to provide chat fashions entry to a listing of messages as enter and return a model-generated message as output.
ChatCompletionsOptions? chatCompletionsOptions = new ChatCompletionsOptions { DeploymentName = "DEPLOYMENT_NAME" };
- Lastly, create an occasion of SfPdfViewer to show PDF recordsdata in your app.
<syncfusion:SfPdfViewer DocumentSource="{Binding PdfFileSource}"/>
Sensible PDF type filling in .NET MAUI PDF Viewer with AI-generated type information
To robotically fill PDF kinds utilizing the .NET MAUI PDF Viewer, you need to use AI to generate XFDF (XML Kinds Information Format) recordsdata containing the required type information. This course of entails a number of steps, from exporting type information to AI for clever information mapping and eventually importing the information again into the PDF type utilizing the .NET MAUI PDF Viewer.
Step 1: Export type information from the PDF
First, export the shape information from the PDF utilizing the .NET MAUI PDF Viewer. If the shape is unfilled, it exports as empty; in any other case, it exports with beforehand stuffed information. Use the exported type information to assist the AI mannequin acknowledge the shape fields and perceive the construction of the XFDF format. This step ensures the AI maps the information to the suitable type fields.
Consult with the next code instance.
utilizing Syncfusion.Maui.PdfViewer; public async Process ExportFormData(SfPdfViewer pdfViewer, Stream xfdfStream) { // Export the shape information. pdfViewer.ExportFormData(xfdfStream, DataFormat.XFdf); }
Step 2: Copy textual content to populate the shape fields
Copy the required textual content data from any supply to your clipboard. This textual content content material ought to comprise all of the related data wanted to populate the shape fields.
Step 3: Generate XFDF content material with AI
Now, present the exported type information and the copied textual content content material to the AI mannequin. Present a immediate to the AI mannequin to supply XFDF textual content content material that merges the exported type information with appropriate type values extracted from the textual content content material. This step entails utilizing AI to intelligently map the extracted information to the shape fields within the XFDF format.
Consult with the next code instance.
utilizing Azure.AI.OpenAI; public async Process<String> GenerateXFDFContent(string exportedFormData, string copiedTextContent, OpenAIClient openAIClient) { // Create a immediate for the AI mannequin. string immediate = $"Merge the copied textual content content material into the XFDF file content material. Trace textual content: {CustomValues}. " + $"Make sure the copied textual content content material matches the suitable area names. " + $"Listed below are the main points: " + $"Copied textual content content material: {copiedTextContent}, " + $"XFDF data: {exportedFormData}. " + $"Present the resultant XFDF straight. " + $"Please comply with these circumstances: " + $"1. The enter information is just not straight supplied as the sphere identify; you have to assume and merge appropriately. " + $"2. When evaluating enter information and area names, ignore case sensitivity. " + $"3. First, decide the perfect match for the sphere identify. If there isn’t an actual match, use the enter information to discover a shut match. " + $"4. Take away ```xml and ``` if they're current within the code."; // Get the AI response. string xfdfContent = await openAIClient.GetChatCompletionsAsync(immediate); return xfdfContent; }
Step 4: Convert XFDF content material to file stream and import within the .NET MAUI PDF Viewer
Convert the generated XFDF content material to an XFDF file stream. This file stream can then be used to fill the PDF type robotically by importing it utilizing the PDF Viewer.
Consult with the next code instance.
utilizing System.IO; utilizing Syncfusion.Maui.PdfViewer; public async void FillPdfForm(SfPdfViewer pdfViewer, string xfdfContent) { utilizing (Stream xfdfStream = new MemoryStream()) { // Create a StreamWriter to put in writing to the XFDF stream. var author = new StreamWriter(xfdfStream, leaveOpen: true); // Write the XFDF content material to the stream. await author.WriteAsync(xfdfContent); // Import the XFDF stream to the PDF Viewer. xfdfStream.Place = 0; pdfViewer.ImportFormData(xfdfStream, DataFormat.XFdf, true); } }
By following these steps, you may create XFDF type contents with AI and robotically fill PDF kinds utilizing the .NET MAUI PDF Viewer.
Consult with the next output picture.
Strive It Free
GitHub reference
For extra particulars, discuss with the AI-driven good PDF type filling within the .NET MAUI PDF Viewer GitHub demo.
Notice: Within the challenge listing, find the AIHelper.cs file. Substitute the default values within the following code snippet together with your particular AI endpoint, deployment identify, and API key to make sure correct performance.
personal string aiEndpoint = "https://yourendpoint.com/"; personal string deploymentName = "DEPLOYMENT_NAME"; personal string apiKey = "AZURE_OPENAI_API_KEY";
Conclusion
Thanks for studying! By leveraging AI and the Syncfusion .NET MAUI PDF Viewer, you may considerably streamline the method of filling out PDF kinds. This not solely saves time but additionally reduces the probability of errors. With minimal setup and configuration, you may automate type filling and deal with extra vital duties.
This characteristic is obtainable within the newest 2024 Quantity 3 launch. You possibly can try all of the options in our Launch Notes and What’s New pages.
You possibly can obtain and take a look at our MAUI demo app from Google Play and the Microsoft Shops.
The present clients can obtain the brand new model of Important Studio on the License and Downloads web page. If you’re not a Syncfusion buyer, attempt our 30-day free trial to take a look at our unimaginable options.
It’s also possible to contact us by our assist discussion board, assist portal, or suggestions portal. We’re all the time joyful to help you!