一: 把图片路径存到一个list .
List<string> list = new List<string>();
list.Add("d:\\6.png");list.Add("d:\\8.png");
list.Add("d:\\7.png");
list.Add("d:\\1.png");
string dateTimePdfName = DateTime.Now.ToString("yyyyMMddhhmmss") + "Images.pdf";
process(list,"d:\\" + dateTimePdfName); //文件生成存放路径
二:调用iTextsharp来做:
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
try {
iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(newpdf, FileMode.Create, FileAccess.ReadWrite)); document.Open();
iTextSharp.text.Image image;
for (int i = 0; i < files.Count; i++){
if (String.IsNullOrEmpty(files[i])) {
break;
}
image = iTextSharp.text.Image.GetInstance(files[i]);
if (image.Height > iTextSharp.text.PageSize.A4.Height - 25) {
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
} else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25) {
image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
}
image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
//image.SetDpi(72, 72);
document.NewPage();
document.Add(image);
}
//MessageBox.Show("转换成功!");
} catch (Exception ex){
//MessageBox.Show("转换失败,原因:" + ex.Message);
}
document.Close();
//更多相关pdf知识参考 : http://www.javashuo.com/tag/pdf/list-22.html