chika Chika is a sales and marketing specialist at IDR Solutions, focusing on business opportunities, client relationships and product promotion. She represents the company at conferences and industry events, where she speaks about PDF document solutions for Java developers. In her free time she enjoy Pilates, content creation and bible study sessions with friends.

Updated Part 5: Path Objects

1 min read


Part 5: Path Objects (click to expand)

A PDF is drawn using a load of commands that sit in stream objects. With these commands a Pdf viewer can figure out how to draw all the content that you see on a page. I’m going to explore the graphics commands and create a Pdf in a text editor that draws a couple of lines on a page.

In a content stream you can create a combination of different graphics objects that a Pdf can understand. The one we are going to muck about with in this article is the Path object. A Path object is basically a list of points. Each Path object has a starting point and new points are added to the list. Each segment of the path can be a straight line, curve or rectangle. The collection of points are treated as one Path object because the painting operation you apply is applied to all the segments of your path.

175 720 m 175 50 l h S

The previous line contains 3 commands. The first one is m. This means start a path at the coordinates given. The l command means draw a line segment from the previous point in the trail to the coordinates 175, 50. The h command closes off the path. When you have set your path out you then have to give it some sort of paint command so that it will do something. I used the command S which strokes the path.

175 720 m 175 700 l 300 800 400 720 v h S

This adds another command, v, which draws a curved line. The first two coordinates are the control point which sets the bend of the line, the next two are where the line ends.

175 720 m 175 700 l 300 800 400 600 v 100 650 50 75 re h S

The re command draws a rectangle at coordinates 100 650 with a width and height of 50 and 75 respectively.

%PDF-2.0
1 0 obj <</Type /Catalog /Pages 2 0 R>>
endobj
2 0 obj <</Type /Pages /Kids [3 0 R] /Count 1 /MediaBox [0 0 500 800]>>
endobj
3 0 obj<</Type /Page /Parent 2 0 R /Contents 4 0 R>>
endobj
4 0 obj
<</Length 61>>
stream
175 720 m 175 500 l 300 800 400 600 v 100 650 50 75 re h S
endstream
endobj
xref
0 5
0000000000 65535 f
0000000010 00000 n
0000000059 00000 n
0000000140 00000 n
0000000202 00000 n
trailer <</Size 5/Root 1 0 R>>
startxref
314
%%EOF



Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
chika Chika is a sales and marketing specialist at IDR Solutions, focusing on business opportunities, client relationships and product promotion. She represents the company at conferences and industry events, where she speaks about PDF document solutions for Java developers. In her free time she enjoy Pilates, content creation and bible study sessions with friends.

Updated Part 6: Graphics State

Part 6: Graphics State (click to expand) It would be nice to get some color on the screen this time round and in doing...
chika
1 min read

Updated Part 4: Hello World PDF

Part 4: Hello World PDF (click to expand) Back when dinosaurs roamed the earth I talked about the different objects that are used to...
chika
1 min read

Updated Create a Non-Working PDF

Part 3: Create a Non-Working PDF (click to expand) In the previous article of this series, we learn to use a text editor to...
chika
1 min read