In DsPdf, soft mask can be created using the Create method of the SoftMask class which accepts the target document and the bounds where mask is to be applied as parameters. Then, you need to retrieve the graphics of the soft mask by using the Graphics property of FormXObject of the SoftMask class. You can design the mask by drawing on these graphics and once the mask is created, apply the mask to PDF document graphics by assigning it to SoftMask property of the PdfDocumentGraphics class.
Note:
To create soft mask using DsPdf:
C# |
Copy Code
|
---|---|
public int CreatePDF(Stream stream) { var doc = new GcPdfDocument(); var page = doc.NewPage(); var g = page.Graphics; var rMask = new RectangleF(0, 0, 72 * 5, 72 * 2); var rDoc = new RectangleF(36, 36, rMask.Width, rMask.Height); var softMask = SoftMask.Create(doc, rDoc); var smGraphics = softMask.FormXObject.Graphics; smGraphics.FillEllipse(rMask, Color.FromArgb(128, Color.Black)); smGraphics.DrawString("SOLID TEXT", new TextFormat() { Font = StandardFonts.HelveticaBold, FontSize = 52, ForeColor = Color.Black }, new RectangleF(rMask.X, rMask.Y, rMask.Width, rMask.Height), TextAlignment.Center, ParagraphAlignment.Center, false); var rt = rMask; rt.Inflate(-8, -8); // Color on the mask does not matter, only alpha channel is important: smGraphics.DrawEllipse(rt, Color.Red); g.SoftMask = softMask; g.DrawImage(Image.FromFile(Path.Combine("Resources", "Images", "reds.jpg")), rDoc, null, ImageAlign.StretchImage); // Done: doc.Save(stream); return doc.Pages.Count; } |
For more information about implementation of soft mask feature using DsPdf, see DsPdf sample browser.