I'm trying what should be a fairly simple task. To create a pdf with a series of images in it from my database. I retrieve the images without any trouble, and can display them in a GdViewer control with no problem. SaveToPDF also works fine. But creating a PDF and adding the image, so that I can create a multi-page PDF this way does not seem to work.
Here's my code, it's basic functionality is to loop through the rows in a datagridview, get a documentID from the first cell in the datagridview, open the images with that documentID (may be multiple pages). Loop through the images with that documentID adding each one to a PDF file. The looping seems to work fine, I get the correct number of pages, I just don't get any images on the pages.
Thanks,
Neal.
--- Edit 08/26/09 10:10 AM (UTC - 4) ---
I added a line of code to display the return value of PdfAddImageFromGdPictureImage(pdfid, imageid). It returns 0, indicating an error, but what could that error be?
---- End edit ---
Code: Select all
private void btnMakePDF_Click(object sender, EventArgs e)
{
GdPictureImaging img = new GdPictureImaging();
int pdfid;
pdfid = img.PdfNewPdf("C:\\test.pdf");
img.PdfSetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch);
for (int z = 0; z < this.dataGridView1.Rows.Count; z++)
{
string DocID = this.dataGridView1.Rows[z].Cells[0].Value.ToString();
this.getimages(DocID);
for (int i = 1; i <= this.alPictures.Count; i++)
{
int imageid;
float pgheight = (float)11;
float pgwidth = (float)8.5;
byte[] imgArray = (byte[])this.alPictures[i-1];
imageid = img.CreateGdPictureImageFromByteArray(ref imgArray);
GdViewer1.DisplayFromGdPictureImage(imageid); // Display Image - Works Fine
img.PdfNewPage(pdfid,pgwidth,pgheight);
int pdfImageID = img.PdfAddImageFromGdPictureImage(pdfid, imageid);
img.PdfDrawImage(pdfid, pdfImageID, 0, 0, pgwidth, pgheight); // Image Does not show in PDF
img.SaveAsPDF(imageid, "C:\\test1.pdf", false, "", "", "", "", ""); // Save to PDF works Fine
//img.PdfDrawLine(pdfid, 1, 1, 5, 5, 1, Color.Red); // Drawing Line works fine
}
}
img.PdfEndPdf(pdfid);
}