PDF添加圖片(圖片透明)

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);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章