using iTextSharp.text;
using iTextSharp.text.pdf;
string appPath = AppDomain.CurrentDomain.BaseDirectory;
Document doc = new Document(new Rectangle(390, 400), 0, 0, 0, 0); //紙張寬390 高400
PdfWriter.GetInstance(doc, new FileStream(appPath + "/DPD_15505984238198.pdf", FileMode.Create));
doc.Open();
//給pdf添加圖片
string filesPath = appPath + (appPath.EndsWith("\\") ? "" : "\\") + "GzImage\\";
string gzImage = ReportPage.GetSession("gzImage");
Image image = Image.GetInstance(filesPath + gzImage);
float percentage = 1;
//這裏都是圖片最原始的寬度與高度
float resizedWidht = image.Width;
float resizedHeight = image.Height;
//這裏用計算出來的百分比來縮小圖片
image.ScalePercent(percentage * 100);
//gzX居左的距離 gzY居底的距離
int gzX = Int32.Parse(ReportPage.GetSession("gzX"));
int gzY = Int32.Parse(ReportPage.GetSession("gzY"));
image.SetAbsolutePosition(gzX, gzY);
document.Add(image);