PDFOne .NET
Powerful all-in-one PDF library for .NET
Compatibility
VS 2005/2008/2010/2012/2013

How To Set Transparency Levels For PDF Elements

Render text, shapes, and images in PDF with varying levels of transparency.
By M. V. Niranjan

PDF format offers a great depth of features that you can use to spruce up your PDF documents. For this article, I will focus on rendering text, shapes, and images that appear translucent on a PDF document using Gnostice PDFOne .NET.

To change the level of transparency of PDF elements, you just need to specify the alpha value of the color used by the pen and brush objects of PDFPage, which are used to stroke and fill PDF elements such as text and shapes.

Color.FromArgb Method(Int32, Color)

public static Color FromArgb(
  int alpha,
  Color baseColor
);

When the alpha value is 0, the PDF element will rendered completely transparent i.e., it will not be visible even though it is present in the PDF. When the alpha value is set to 255, the PDF element appears totally opaque. The corollary then is that we need to vary the alpha value as required, specify the color, and then render the PDF element.

PDFPage page = new PDFPage();

// Sets alpha value for brush color
page.Brush.Color = Color.FromArgb(30, Color.Blue);
// Writes translucent text
page.WriteText("This is transparent text", 1, 2.5f);


// Changes alpha value for brush color
page.Brush.Color = Color.FromArgb(
                           40, Color.YellowGreen);
// Draws a translucent ellipse
page.DrawEllipse(Pens.Black, 
                 new RectangleF(1, 3.5f, 2, 1), 
                 true, true);

// Changes alpha value of brush color again
page.Brush.Color = Color.FromArgb(
                           10, Color.Empty);                    
// Draws a translucent image
page.DrawImage("image.bmp", 
               new RectangleF(1, 4.5f, 2, 1));

You have learned how to set transparency levels for text, shapes, and images in PDF. Now, with some imagination and/or practice, you will be able create translucent PDF elements along with smartly-positioned overlays. Your PDF documents may then sport an elegant and attractive look.

Translucent text in PDF Translucent shapes in PDF Translucent images in PDF
---o0O0o---

Downloads:

---o0O0o---

Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.

PDFOne .NET

A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
Gnostice Document Studio Java

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs
StarDocs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2024 Gnostice Information Technologies Private Limited. All rights reserved.