I am looking to export images, change image quality and format, and then replace the image. I have been able to write a method with limited functionality to export the images. I've also been able to change the images from /FlateDecode to /DCTDecode.
But if I export the image, convert it to a PNG or even a BMP, the PDF document is not useable.
What other parameters do I need to set? I've tried :
-adjusting the image.Elements.SetInteger(PdfImage.Keys.Length, (int)buffer.GetLength())
-setting the BitsPerComponent
-setting the ColorSpace to Indexed8
is this an issue where i need to define a color palette? Is this do-able or should I explore trying to delete and then redraw the images?
Code:
public void ReplaceImage(PdfDictionary image, Bitmap optimizedImage)
{
using (var ms = new MemoryStream())
{
optimizedImage.Save(ms, ImageFormat.Bmp);
image.Stream.Value = ms.GetBuffer();
}
}