Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is PDF stroking, non-stroking and filling?

Tags:

pdf

pdfbox

I've just started using Apache PDFBox and I'm completely baffled as to what is meant by stroking, non-stroking and filling when applied to text and lines.

Please can someone point me to a reference / guide which explains what these terms mean (for beginners) and what the difference is between them.

like image 915
ksl Avatar asked Jan 15 '15 08:01

ksl


2 Answers

Its pretty simple. Consider a rectangle located at 0,0 and 50 units wide and high. That is described as a path with vertices at 0,0 0,50 50,50 and 50,0

Now, if you stroke the path (imagine drawing along the path using a pen) with black. What you get is a black square, the interior of the square is whatever was on the paper before you drew the border (probably nothing, so white).

If you fill the path, you get a filled in square, but no border drawn.

If you fill and stroke the path you get a filled in square with a border. Because the fill and stroke colours can be different you can have the square filled in one colour and the border drawn in another.

See the PDF Reference, section 4.4 "Path Construction and Painting"


Update (by -kp-)

I've copied the following table from the official PDF-1.7 specification:

This table shows the different text rendering modes. Here too, you can stroke or fill or do both to glyph shapes. You can even do neither stroke nor fill, but still define the shapes: that is, you get invisible text -- a very useful mode for placing OCR-ed text on top of a scanned image! It makes the text searchable, copy'n'paste-able and screen-reader aware.

like image 159
KenS Avatar answered Nov 30 '22 23:11

KenS


I am currently writing a book The ABC of PDF with iText that introduces you to all these principles.

You are talking about the "Graphics State" and syntax that is used to define objects on a page. This syntax is stored in content streams.

Ignoring "Text State" (a subset of "Graphics State") for the moment, the idea is that you create paths and shapes (shapes are closed paths). These path and shapes can be drawn using stroke and fill operators. If you fill a path, you need to define whether you're using the non-zero winding rule or the even-odd rule (if you've studied geometry at college level, you've already encountered these rules).

Stroke and fill operators will use the colors of the current graphics state. Lines will be drawn using the stroking color. Shapes will be filled using the non-stroking color.

There's much more info in the free ebook you can download from Leanpub.

like image 23
Bruno Lowagie Avatar answered Dec 01 '22 00:12

Bruno Lowagie