@Anonymous , Welcome to Microsoft Q&A, you could try to convert your cell value to bitmap then you could print it successfully.
Here is a code example you could refer to.
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Image", typeof(byte[]));
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
Image im = Image.FromFile("C:\\Users\\Administrator\\Desktop\\cat.jfif");
var arr = ImageToByteArray(im);
dt.Rows.Add(arr, 1001, "test1");
dataGridView1.DataSource = dt;
}
public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new MemoryStream())
{
imageIn.Save(ms, imageIn.RawFormat);
return ms.ToArray();
}
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
byte[] arr = (byte[])dataGridView1.Rows[0].Cells[0].Value;
var image = byteArrayToImage(arr);
e.Graphics.DrawImage(image, 620, 55, 120, 120);
}
private void button1_Click(object sender, EventArgs e)
{
printDocument1.Print();
}
Result in pdf:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.