【发布时间】:2013-01-10 09:20:48
【问题描述】:
我正在使用已弃用的 iTextSharp (4.1.6.0) 版本从我的 MVC3 应用程序中生成 PDF,并且确实需要能够在其他形状和图像之上放置半透明形状,目标是淡化颜色它下面的图像,或将其变灰。我原以为这就像在为形状填充选择颜色时设置 alpha 通道一样简单,所以我尝试了这个:
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(@"C:/Filepath/doc.pdf", FileMode.Create))
doc.Open();
PdfContentByte over = writer.DirectContent;
// draw shape to be faded out
over.Rectangle(10, 10, 50, 50);
over.SetColorFill(Color.BLUE);
over.Fill();
// draw shape over the top to do the fading (red so i can easily see where it is)
over.Rectangle(0, 0, 60, 60);
over.SetColorFill(new Color(255,0,0,150)); // rgba
over.Fill();
doc.Close();
我希望这会在页面左下角附近绘制两个矩形,一个小的蓝色矩形覆盖着一个较大的红色半透明矩形,但红色不是半透明的!
所以我做了一些谷歌搜索,发现了这个page,这实际上是关于 iText 而不是 iTextSharp,他们建议使用 PdfGstate 来设置填充不透明度,如下所示:
PdfGState gstate = new PdfGState();
gstate.setFillOpacity(0.3);
但是当我尝试gstate 对象没有类似.setFillOpacity() 的方法时!如果有人能指出我正确的方向,我将不胜感激。
【问题讨论】:
标签: c# pdf-generation itextsharp itext