convert itextsharp.text.image to byte RRS feed

  • Question

  • iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(copiedPage);

    image to byte convert 

    How to do it? Anyone know please answer.

    Thanks in advanced.

    Thursday, March 28, 2019 6:58 AM

All replies

  • Hi

    Thank you for posting here.

    For your question, you want to convert itextsharp.text.image to byte.

    You could try the following code.

    static void Main(string[] args)
                BaseColor baseColor = new BaseColor(1, 2, 3);
                System.Drawing.Image img = System.Drawing.Image.FromFile(@"D:\pic\6.jpg");
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(img, baseColor);
                byte[] t = ObjectToByteArray(image);
            private static byte[] ObjectToByteArray(iTextSharp.text.Image obj)//passed iTextSharp document as object
                if (obj == null)
                    return null;
                BinaryFormatter bf = new BinaryFormatter();
                MemoryStream ms = new MemoryStream();
                bf.Serialize(ms, obj);
                return ms.ToArray();

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Friday, March 29, 2019 5:21 AM