您好,登錄后才能下訂單哦!
string filename = DateTime.Now.ToString("yyyyMMddHHmmss").ToString() + ".pdf";
float w = PageSize.A4.Width;
float h = PageSize.A4.Height;
Rectangle rect = new Rectangle(0, 0, w, h);
Document document = new Document(rect);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(Server.MapPath(filename), FileMode.Create));
document.Open();
PdfContentByte content = writer.DirectContent;
PdfTemplate template = content.CreateTemplate(rect.Width, rect.Height);
PdfGState state = null;
template.SaveState();
template.SetColorFill(Color.RED);
template.SetColorStroke(Color.GREEN);
template.SetLineWidth(3);
state = new PdfGState();
state.FillOpacity = 0.5f;
state.AlphaIsShape = false;
template.SetGState(state);
template.Rectangle(100, 100, 100, 100);
template.FillStroke();
template.RestoreState();
template.SaveState();
template.SetColorFill(Color.RED);
template.SetColorStroke(Color.BLUE);
template.SetLineWidth(3);
state = new PdfGState();
state.FillOpacity = 0.5f;
state.AlphaIsShape = false;
template.SetGState(state);
template.Rectangle(150, 150, 100, 100);
template.FillStroke();
template.RestoreState();
template.SaveState();
//處理同一組內(nèi)的元素,設(shè)置組的透明度為0.5,這樣組內(nèi)元素重疊的時候是后畫的圖形覆蓋先畫的圖形,不會應(yīng)為設(shè)置了透明度,讓元素重疊的部分顏色加深或者相互影響
state = new PdfGState();
state.FillOpacity = 0.5f;//設(shè)置透明度為0.5
template.SetGState(state);
PdfTemplate _template = template.CreateTemplate(rect.Width, rect.Height);
//設(shè)置透明為為一個組
PdfTransparencyGroup group = new PdfTransparencyGroup();
group.Isolated = false;//標(biāo)示是否獨立
_template.Group = group;
_template.SaveState();
_template.SetColorFill(Color.RED);
_template.SetColorStroke(Color.GREEN);
_template.SetLineWidth(3);
_template.Rectangle(300, 100, 100, 100);
_template.FillStroke();
_template.RestoreState();
_template.SaveState();
_template.SetColorFill(Color.RED);
_template.SetColorStroke(Color.BLUE);
_template.SetLineWidth(3);
_template.Rectangle(350, 150, 100, 100);
_template.FillStroke();
_template.RestoreState();
template.AddTemplate(_template, 0, 0);
template.RestoreState();
content.AddTemplate(template, 1, 0, 0, -1, 0, rect.Height);
document.Close();
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。