Mark Stephens I have been working with Java and PDF since 1999 and am a big NetBeans fan. I enjoy speaking at conferences including Business of Software, JavaOne, CodeOne and DevFest. I have an MA in Medieval History and a passion for reading.

3 examples of unusual ways to use PDF Image Masks

57 sec read

Early this week, I wrote an introductory article about Masks. I would like to follow that with another article highlighting an issue which can occur with masks.

As explained before, a Mask is effectively a stencil which allows you to define which pixels are painted onto the page any how transparent they are. That is the easy bit – the problem is that the Mask and the Image can be very different sizes. It does not even need to have the same aspect ration. And there are quite a few tools which use this feature to achieve some interesting effects. Here are some examples:-

1. Specify an SMask as a 1 x 1 pixel image (the image is actually a much larger rectangle).

2. Specify a Mask with the same width as the image but a height of 1 pixel (the image is 900 pixels high).

3. Specify a large Mask and a 1×1 pixel image.

So the way we handle image Masks to cover these is to :-

  • always use the bigger set of dimensions (whether on image or Mask)
  • Scale the smaller to the larger with separate scaling on width and height
  • Do not expect the Mask and the image to have the same aspect ratio

Have you come across and odd uses of image Masks in 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!

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Mark Stephens I have been working with Java and PDF since 1999 and am a big NetBeans fan. I enjoy speaking at conferences including Business of Software, JavaOne, CodeOne and DevFest. I have an MA in Medieval History and a passion for reading.

One Reply to “3 examples of unusual ways to use PDF Image…”

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.