PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Creating a XPen with a Pen leads to corrupted PDF
http://forum.pdfsharp.com/viewtopic.php?f=3&t=993
Page 1 of 1

Author:  mried [ Wed Dec 16, 2009 12:42 pm ]
Post subject:  Creating a XPen with a Pen leads to corrupted PDF

Hi!

If you use a GDI-Pen to create a PDF-XPen and draw some lines with it, the produced PDF can't be read by the Acrobat-Reader under some circumstances (it sometimes doesn't complain about it, but the display is still wrong). Other readers (like the Foxit) can do so.

The following code will produce the error:
Code:
//Create a GDI-Pen
Pen pen = new Pen(Color.Gray);
pen.LineJoin = LineJoin.MiterClipped;

//Create a PDF-Pen
XPen xPen = new XPen(pen);

//Create a path (a triangle)
GraphicsPath path = new GraphicsPath(FillMode.Alternate);
path.AddLines(new [] {new Point(5, 5),
                                new Point(30, 30),
                                new Point(5, 30)});
path.CloseFigure();

//Draw the path (gfx = XGraphics)
gfx.DrawPath(xPen, new XGraphicsPath(path.PathPoints, path.PathTypes, XFillMode.Alternate));


The resulting PDF contains a triangle if you open it with the Foxit Reader. Using the Acrobat Reader will show an empty page.

The problem is the LineJoin here. PDF doesn't support MiterClipped as mentioned in the PDF-Reference, chapter 8.4.3.4. While creating a new XPen from a GDI-Pen, line 256 of XPen.cs is executed. It reads
Code:
xpen.LineJoin = (XLineJoin)pen.LineJoin;

In this case, xpen.LineJoin is set to 3. The XGraphicsPdfRenderer outputs the value of LineJoin to the PDF, which is the reason Acrobat Reader doesn't display the line.

Shouldn't there be an exception thrown if one tries to create a XPen with LineJoin == MiterClipped?

Malte

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/