Hi Team,
I am converting a file into PDF from Word using Aspose.Word in .NET but the output file is quite larger than Microsoft Interop. This is happening only when the Word file contains images.
CODE:
program.cs
// --- Configuration ---
builder.Configuration
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
Config.Config.Data = builder.Configuration;
// --- Services ---
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
// Swagger Setup (optional)
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// --- Middleware Setup ---
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
// --- Routing Setup ---
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.Run();
convert code
private static void ConvertDOCXToPDF(string inputPath, string outputPath)
{
try
{
var doc = new Aspose.Words.Document(inputPath);
doc.Save(outputPath, SaveFormat.Pdf);
}
catch (Exception ex)
{
LoggerUtility.Logger.LogException(ex, "Aspose Conversion Error");
throw;
}
}
Template Test 0409_MS_Interop.pdf (562.6 KB)
Template Test 0409_Aspose.pdf (1.7 MB)
Template Test 0409.docx (1.8 MB)
