PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Image replacement
http://forum.pdfsharp.com/viewtopic.php?f=2&t=2715
Page 1 of 1

Author:  scotte [ Thu Jan 23, 2014 10:53 pm ]
Post subject:  Image replacement

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();
            }
        }

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/