I am using your c# pdf library to process PDF document. Sometimes I need to add an image which is not a file but in "byte array" or "binary" format. I do not want to convert it into an actual image file, and then insert it to PDF document.So, what is the preferred method of adding image in binary to PDF? Can anybody help me out?
This article on XsPDF.com is what are you looking for, check out: Add image on PDF in C#.
Answers
It works fine if i save the dynamic image to a temporary local file, then add it to PDF, and later delete this image file. However, this process is not so convenient and even cause an exception sometimes. Just like you, i am looking for an easy and cleaner way to add such images to PDF document. Hope to hear soon. Thanks in advance.
It is not so hard to achieve this. I am using XsPDF library in my c# programming. I found it to be a very simple way to have an AddImage overload that took a stream and a name instead of a filepath. This may be the way to solve your image adding in binary issue. But if you need my sample code, just let me know.
This is what i did in my project. Hope it will be helpful for your case.
// byte[] jpegdata contains the jpeg image using (MemoryStream ms = new MemoryStream(jpegdata)) { using (Image img = Image.FromStream(ms)) { using (var xi = XImage.FromGdiPlusImage(img)) { _pdfGfx.DrawImage(xi, ip.dx, ip.dy, ip.dw, ip.dh); } } }
