PDFsharp & MigraDoc Forum
https://forum.pdfsharp.net/

Change the Origin in PDFSharp
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3159
Page 1 of 1

Author:  scotthclearspaninc [ Tue Aug 04, 2015 5:59 pm ]
Post subject:  Change the Origin in PDFSharp

I'm using PDFSharp 1.30 GDI+. I'm importing and drawing a truss shape into a document. The trick is that in my coordinate system, the truss's bottom left corner rests at 0,0 and fills in Quadrant I from there. Rendering it in PDFSharp seemed pretty straightforward at first glance. Just loop through the line segments, running this code:
Code:
gfx.DrawLine(XPens.PowderBlue, faceLine.BasePoint.X.Inches, faceLine.BasePoint.Y.Inches, faceLine.EndPoint.X.Inches, faceLine.EndPoint.Y.Inches);


However, since the origin in PDFSharp starts at the top left, my truss shape renders upside down. I can halfway solve this by moving the origin to the bottom right with this code:
Code:
gfx.RotateTransform(180);
gfx.TranslateTransform(-612, -792); // Assumes 8.5 inch x 11 inch at 72 points/inch


Now my truss renders right side up, but because of the rotate transform, any text I add is upside down. This might be solved by a
Code:
gfx.Save()
and
Code:
gfx.Restore()
, but the text I need to add needs to be in very specific places relative to the truss shape I've drawn (like labeling the members in the attachment. I do that by attempting to add the text at the same time as drawing the lines, but then it is upside down.
Attachment:
File comment: Example of my problem
Capture.PNG
Capture.PNG [ 98.46 KiB | Viewed 5824 times ]


The simplest solution seems to be if I could move the origin to the bottom left corner. However this is not yet implemented. What's the best approach to this problem?

Author:  TH-Soft [ Tue Aug 04, 2015 7:50 pm ]
Post subject:  Re: Change the Origin in PDFSharp

Answered on SO:
http://stackoverflow.com/a/31817994/1015447

A combination of TranslateTransform and ScaleTransform(1,-1) should do what you want.

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