Understanding the PDF File Format: Blend Modes

PDF_LogoThe PDF FIle Format includes some very sophisticated features. One of the most interesting ones is the Blend Mode (introduced in PDF version 1.4). This is intended as brief overview article – if you would like to see some more detailed articles, let us know.

What is Blend Mode?

Blend Mode controls how new content is painted and allows the new pixels to be effected by what has already been drawn.

In Normal mode, any new drawing will erase existing items which it draws over. So if I draw a RED box on a page, anything underneath will disappear. But it wouldn’t it be useful if the new red box could ‘interact’ (or blend) with whatever is on the page? This is what Blend Modes allow!

How is it set?

Blend Mode is set using the BM command in the GraphicsState and the default value is Normal.

Other possible values are Compatible (actually the same as Normal), Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn, HardLight, SoftLight, Difference, Exclusion.

How does it work?

When a pixel is drawn on the page, a formula is applied as defined in Section 11.3.5 of the PDF File Specification which produces a final blended result based on the current value and the new value.

How it works can be dependent on the exact colorspace used.

How would I implement it in Java?

If you want to implement this functionality in Java, the easiest way is to use JavaFX which includes all these modes defined so you can apply to any Node.

node.setBlendMode(BlendMode.MULTIPLY);

Java is more complex because it needs an implementation of CompositeContext for each Mode.

There is a nice tutorial exploring Composites in Swing/Java2D here.

Java also works in sRGB, so effects based on DeviceCMYK or other ColorSpaces become more complex to implement.

Is there a good PDF example?

If you are looking for a detailed example file, here is the link to an Adobe test file.

Final Comments

Blend Modes allow to to create some very interesting effecting in compositing (both in and beyond PDF). If you are doing any form of drawing, they are worth knowing about and experimenting with.

Want to learn more about PDF files?

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

One thought on “Understanding the PDF File Format: Blend Modes

  1. […] mentioned previously the PDF format contains blend modes, a set of functions determining how overlapping objects on a […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>