Arrrgh, I'm getting closer. This gets me my jpg image into the PDF, but it's showing up severely shrunk down. It also appears to be replicated three times - so the end result is I have my PDF, with the image in it, but it's very distorted. Here's the code I've got that creates this:
Code:
document.Info.CreationDate = DateTime.Now;
document.Info.Title = "";
document.Info.Author = "";
document.Info.Subject = "Server time: " + DateTime.Now.ToShortTimeString();
int i = 1;
FullFilename = ServerImagePath + "\\" + filename + "-" + i.ToString() + ".jpg";
MemoryStream ms = new MemoryStream();
//// Create new PDF page
PdfPage page = document.AddPage();
XImage image = XImage.FromFile(FullFilename);
page.Width = image.Width;
page.Height = image.Height;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawImage(image, 0, 0);
gfx.Dispose();
image.Dispose();
page.Close();
//Send PDF to browser
document.Save(ms, false);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", ms.Length.ToString());
Response.AppendHeader("content-disposition", string.Format("attachment;filename=output.pdf"));
Response.BinaryWrite(ms.ToArray());
Response.Flush();
ms.Close();
I tried this code from another post:
Help!
Code:
//page.Width = XUnit.FromInch(image.Width / image.HorizontalResolution);
//page.Height = XUnit.FromInch(image.Height / image.VerticalResolution);
thinking that would help the proportion problem, but that just made the page the size of the shrunk image. And it still has the repeating problem.
The jpegs I'm working with are scanned documents in grayscale. Does that affect anything?