3

I'm drawing lines in PDF that I want to scale in a ratio other than 1:1.

The problem is that i get strokes that looks like they been drawn with a caligraphic pen.

Is it possible somehow in PDF to resize the path, restore the graphics state and then draw the stroke of the previous path.

This is how I get caligraphical line strokes in PDF:

5 w               // width of stroke
q                 // saves the current graphics state 
0 1 0 0.2 0 0 cm  // transformation matrix scaling with height reduced to 20%
0 10 m            // Start of line
10 10 l           // line to
20 100 l
30 100 l
40 10 l
S                 // draws stroke
Q                 // Restores graphics state

In HTML5 canvas it's possible to draw stroke after restoring the graphics state so that the path is drawn by a equally width line.

http://www.html5canvastutorials.com/advanced/html5-canvas-ovals/

In PDF putting S after Q doesn't work.

Is there some way to get the same result in PDF where only the line path gets scaled, not the stroke itself?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dominus
  • 67
  • 5

1 Answers1

4

Have a look at Figure 9 - Graphics Objects - on page 113 of the PDF specification ISO 32000-1:2008. It illustrates that as soon as you have started constructing a path, the only allowed operators are those for path construction, path clipping, and path painting. Q being a special graphics state operator is only allowed after a path painting operator, e.g. your S.

This also is stated in the example right below the graphic:

The path construction operators m and re signal the beginning of a path object. Inside the path object, additional path construction operators are permitted, as are the clipping path operators W and W*, but not general graphics state operators such as w or J. A path-painting operator, such as S or f, ends the path object and returns to the page description level.

Thus in response to "Is there some way to get the same result in PDF where only the line path get's scaled, not the stroke itself?": No, you have to explicitly select a smaller stroke width to compensate the different scale introduced by the transmation matrix.

Page 113 of ISO 32000-1:2008 showing Figure 9 - Graphics Objects

mkl
  • 90,588
  • 15
  • 125
  • 265
  • 2
    Thank you for your reply. It's to bad there isn't a bether solution for this other than to calculate the aspectratio for the coordinates manualy. It makes the PDF much larger when x y cordinates has to be described as absolute values as for example: "11.33533433, 43.4335334 l" instead of just "10 80 l" with a scaler. Hovever if i use 0 width then PDF readers show the lines as equaly width even if the aspectratio is wrong. – Dominus Nov 29 '12 at 11:03
  • Well, 0 remains 0 after scaling, and its meaning is "A line width of 0 shall denote the thinnest line that can be rendered at device resolution" (section 8.4.3.2 in ISO 32000-1:2008) which is independent of the ctm. – mkl Nov 29 '12 at 11:38
  • 2
    Keep in mind that it's common to ZIP compress the stream containing PDF operators for a page anyway; so the resulting file can be kept quite small typically. Also, don't go overboard on the precision: the unit here is user space where the unit ("1") is already only 1/72 of an inch. – David van Driessche Nov 29 '12 at 23:01
  • @DavidvanDriessche: And a typical PDF renderer uses only single precision floats; double precision is still very optional. – Martin Schröder Nov 30 '12 at 10:44