Inserting pictures into table programmatically

Does anyone know how to insert an image into a table programmatically with C#? I was trying to do it with the following:

Aspose.Pdf.Image sig = new Aspose.Pdf.Image();
MemoryStream ms = new MemoryStream();
string tempString = r[“value”].ToString();
int tempInt = Int32.Parse(r[“value”].ToString());
System.Drawing.Image temp = getSignature(tempInt);
temp.Save(ms, ImageFormat.Gif);
sig.ImageInfo.ImageStream = ms;

Cell c = new Cell(row1DetailTable);
c.Paragraphs.Add(sig);
row1DetailTable.Cells.Add©;

Where getSignature(tempInt) returns a System.Drawing.Image. When the code executes, it gets stuck at the line where I save it ( pdf.Save(“mypdf.pdf”, SaveType.OpenInBrowser, Response); ).

I am using Visual Studio .NET 2005.

Thanks,
Caleb

Hi,

I have tested your code and was not able to reproduce the error. Can you please save your image to a file and send it to us so that we can more accurately determine the cause of the problem.

Thanks.

Here is a screenshot of the problem that I am having. To try and elliminate the getSignature method as the problem I hard coded it to return a picture from a file. Even after this change, the problem still occurs. My getSignature method now looks like this:

private System.Drawing.Image getSignature(int pictureID)
{
System.Drawing.Image sig;

sig = System.Drawing.Image.FromFile(Server.MapPath(“blue.gif”));
return sig;

}

The file blue.gif exists and is a valid gif file.

Thanks,
Caleb

Hi,

I have not been able to reproduce the error. Please send us the image file so that we can test it.

Thanks.

Attached is the image file that I am trying to load.

Hi,

I have tested it with the image that you provided and still didn't get any problem. I am testing with Aspose.Pdf v 3.6.0.0, which version are you using.

Thanks.

Hi Adeel,

I am using Aspose.Pdf v3.5.5.0. If you want, I can send you the code that generates my PDF for you to test. Just let me know how I can send it to you privately.

Thanks,
Caleb

Hi,

Please refer to following article to be able to send us files in ZIP format.

https://forum.aspose.com/t/how-to-share-a-document-in-a-forum-post/225947/

Thanks.

Ok, I sent you the code. The subject line of the e-mail I sent is: "My Sample Code for adding pictures to PDF"

Thanks,
Caleb

Hi,

You code is missing one statement. Please add the statement

sig.ImageInfo.ImageFileType = ImageFileType.Gif;

to the addRom function as follows

private void addRow(Pdf pdf, Aspose.Pdf.Table table)

{

Section section = pdf.Sections[0];

Aspose.Pdf.TextInfo tf1 = new Aspose.Pdf.TextInfo();

tf1.FontSize = 10;

tf1.Alignment = AlignmentType.Center;

Row row1DetailTable = table.Rows.Add();

row1DetailTable.Cells.Add("test");

tf1.Alignment = AlignmentType.Left;

row1DetailTable.Cells.Add("test");

tf1.Alignment = AlignmentType.Center;

row1DetailTable.Cells.Add("picture");

if (true)

{

Aspose.Pdf.Image sig = new Aspose.Pdf.Image();

MemoryStream ms = new MemoryStream();

int tempInt = 1;

System.Drawing.Image temp = getSignature(tempInt);

temp.Save(ms, ImageFormat.Gif);

sig.ImageInfo.ImageStream = ms;

sig.ImageInfo.ImageFileType = ImageFileType.Gif;

Cell c = new Cell(row1DetailTable);

c.Paragraphs.Add(sig);

row1DetailTable.Cells.Add(c);

}

else

{

row1DetailTable.Cells.Add("not used");

}

row1DetailTable.Cells.Add("date");

}

Thanks.

Thanks, that fixed it.