I am converting Html file to png using groupdocs convert and below is my code for the same
var tempFile = Path.Combine(tempFilesPath, $"p{i}");
using (var converter = new Converter($"{tempFile}.html"))
{
try
{
var options = new ImageConvertOptions { Format = GroupDocs.Conversion.FileTypes.ImageFileType.Png };
converter.Convert($"{tempFile}.png", options);
File.Delete($"{tempFile}.html");
}
catch (Exception)
{
throw;
}
}
but the problem is quality of the document is getting compromised while converting the document.
sharing the files for the reference
please suggest a way to convert without affecting the quality of the document.
Version is 20.8
Please note text the is highlighted here and when converting to png the same file looks like This
I tried with Aspose.words too but it was more bad
var tempFile = Path.Combine(tempFilesPath, $"p{i}");
//using (var converter = new Converter($"{tempFile}.html"))
//{
// try
// {
// var options = new ImageConvertOptions { Format = GroupDocs.Conversion.FileTypes.ImageFileType.Png };
// converter.Convert($"{tempFile}.png", options);
// File.Delete($"{tempFile}.html");
// }
// catch (Exception)
// {
// throw;
// }
//}
Document doc = new Document($"{tempFile}.html");
// Set the options for saving the document as an image
Aspose.Words.Saving.ImageSaveOptions options = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png)
{
//PageIndex = 0, // Save the first page only (0-based index)
//PageCount = 1, // Number of pages to save
Resolution = 300, // Set the resolution to 300 DPI
//ImageBrightness = 0.5f, // Adjust the image brightness if needed
//ImageContrast = 0.5f // Adjust the image contrast if needed
};
// Save the document as a PNG image
doc.Save($"{tempFile}.png", options);
File.Delete($"{tempFile}.html");
p1.png (119.5 KB)