@rchilli,
It all depends on what is the objective. If it is to display to clients. I would not suggest removing images, since they will see a different document compared to the original one. So I really think you should not consider this option.
Code Sample:
private void LogicAlt2()
{
var docWithImages = new Document($"{PartialPath}_input.pdf");
foreach (var page in docWithImages.Pages)
{
for(int imageNumber = 0; imageNumber < page.Resources.Images.Count; imageNumber++)
{
page.Resources.Images.Delete(1);
}
}
var saveOptions = new HtmlSaveOptions();
saveOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
saveOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
docWithImages.Save($"{PartialPath}WithoutImage_output.html", saveOptions);
}
If it is for display only, Maybe a solution can be to transform to images. And display an image in the browser instead. This process also takes time.
I do not know your machine specs, but I will give you a couple of example for you to try.
Code Sample:
private void LogicAlt()
{
var doc = new Document($"{PartialPath}_input.pdf");
using (PdfConverter converter = new PdfConverter())
{
// Set the resolution to 300 DPI
converter.Resolution = new Resolution(300);
// Convert the whole PDF file to an image
converter.BindPdf(doc);
converter.StartPage = 1;
converter.EndPage = doc.Pages.Count;
converter.DoConvert();
// Save the image
converter.SaveAsTIFF($"{PartialPath}_output.tiff");
// Dispose the PdfConverter object
converter.Dispose();
}
}
Another code Sample using PNG:
private void LogicAlt2()
{
var doc = new Document($"{PartialPath}_input.pdf");
Document newDocWithImages = new Document();
int resolution = 300;
PngDevice png = new PngDevice(new Resolution(resolution));
foreach (Page page in doc.Pages)
{
FileStream imageStream = new FileStream($"{PartialPath}_{page.Number}.png", FileMode.OpenOrCreate);
png.Process(page, imageStream);
var newPage = newDocWithImages.Pages.Add(page);
page.Resources.Images.Add(imageStream);
imageStream.Dispose();
File.Delete($"{PartialPath}_{page.Number}.png");
}
newDocWithImages.Save($"{PartialPath}_output.pdf");
var saveOptions = new HtmlSaveOptions();
saveOptions.PartsEmbeddingMode = HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;
saveOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
newDocWithImages.Save($"{PartialPath}AsImage_output.html", saveOptions);
}