Вопрос

I would like to create pdfs, which contains polygons (.NET enviroment). I have downloaded 2 libraries (PdfSharp, iTextSharp), but they only create "nice" polygons when all of the sides of the polygon has the same width.

Let me show you what I mean:

I can create this: easy.png

This is easy, I just have to provide an array of Points to the "Polygon" method. My problem is, that I can't specify the width of the lines. An another way is to draw a polygon is to use methods like "DrawLine", when you specify two points and the width of the "Pen". In this case the connections of the lines are ugly (lines.png - left side). Is it possible to calculate the connection points (lines.png - right side), or it is a dead idea in a Pdf enviroment, without any 2d rendering engine? Or do you know any libraries, which supports drawing like that?

I'm not a math genius, and I don't want to write a whole rendering engine library.

And of course, the drawings could (will) be very complicated, not just rectangles, like in the sample images (more polylines, sharp connections, bended lines, etc.)

Any ideas are welcomed, because I'm really out of them.

Это было полезно?

Решение

What you're asking for is not possible in PDF.

To elaborate, each path that is drawn in PDF has its parameters set by the current graphic state. This implies that each path drawn has a specific line-width (the whole path).

To deal with corners and end-points, you can use the line cap and join parameters (together with miter limit if you draw complicated shapes) but you correctly saw that these are only applied to the current path; not to connections between different paths. How you deal with such compositions between lines of different line width, is up to you.

Math is your friend...

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top