Introduction
We have many libraries available to extract content from PDF files without using AI algorithms. In this post, we will be discussing a library called BitMiracle.Docotic.Pdf to extract content from PDF files using .NET Core 8.
You can learn more about bitmiracle from this URL. https://bitmiracle.com/pdf-library/
I am going to create a Web API project using .NET 8 core.
Create .NET 8 project in Visual Studio 2022.
We can choose Web API template and choose .NET core 8 framework.

We can add our pdf extraction library to this project using NuGet package manager.

We have to add the changes below to Program.cs file.
Program.cs
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.FileProviders;
var builder = WebApplication.CreateBuilder(args);
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.Configure<FormOptions>(o =>
{
o.ValueLengthLimit = int.MaxValue;
o.MultipartBodyLengthLimit = int.MaxValue;
o.MemoryBufferThreshold = int.MaxValue;
});
builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("http://localhost:4200");
});
});
var app = builder.Build();
app.UseHttpsRedirection();
app.UseCors(MyAllowSpecificOrigins);
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Resources")),
RequestPath = new PathString("/Resources")
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
We can create FileUpload service now.
FileUpload.cs
using BitMiracle.Docotic.Pdf;
namespace PDFExtraction.Services;
public static class FileUploadHelper
{
public static InvoiceModel GetPDFContent(string file)
{
using (PdfDocument pdf = new PdfDocument(file))
{
string text = pdf.GetText();
string delimiter = "\r\n";
string[] contents = text.Split(delimiter);
string date = "";
string invoice = "";
string total = "";
foreach (string content in contents)
{
if (content.ToLower().Contains("date"))
{
string delimiter2 = ":";
string[] contents2 = content.Split(delimiter2);
date = contents2[1];
}
if (content.ToLower().Contains("invoice #"))
{
string delimiter2 = "#";
string[] contents2 = content.Split(delimiter2);
invoice = contents2[1];
}
if (content.ToLower().Contains("total"))
{
string delimiter2 = "$";
string[] contents2 = content.Split(delimiter2);
total = contents2[1];
}
}
InvoiceModel model = new InvoiceModel();
model.Date = date;
model.Invoice = invoice;
model.Total = total;
return model;
}
}
}
We can create the FileUplodController now.
FileUplodController.cs





Join the conversation! Your thoughts help the community grow.