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

What are all of the X, Y, width and height measurements in?
http://forum.pdfsharp.com/viewtopic.php?f=2&t=150
Page 1 of 1

Author:  cmgarnett [ Thu May 24, 2007 11:14 pm ]
Post subject:  What are all of the X, Y, width and height measurements in?

I'm just starting to use PDFsharp with VB.net and its looks really good. Thank you to everyone who has been working on it.

I've managed to print some strings and a paragraph of text in a rectangle, but I'm struggling with measurements.

What unit of measurement is used to define where drawstring and drawrectangle, etc. should be positioned, and how large they should be?

How about font sizes, are they in the same units?

Is it millimetres, points (72 points to an inch I think) or some other unit.

I am trying to layout a page but I'm having to do quite a lot of guessing rather than using a ruler.

Author:  Thomas Hoevel [ Thu May 31, 2007 3:46 pm ]
Post subject: 

Unit generally is Points.
You can use the XUnit class to make things simple:
Code:
XRect recA4 = new XRect(0, 0,
  XUnit.FromPoint(595),
  XUnit.FromPoint(842));

XRect recA4fromCentimeter = new XRect(0, 0,
  XUnit.FromCentimeter(21.0224),
  XUnit.FromCentimeter(29.7302));

You can also use XUnit.FromInch or XUnit.FromMillimeter.

Author:  cmgarnett [ Thu May 31, 2007 3:53 pm ]
Post subject: 

Thanks for that. I'll try it out and then add it to the documentation.

Ragrds.

Chris

Author:  cmgarnett [ Mon Jun 04, 2007 10:46 am ]
Post subject: 

When I try the code that you suggest, I get a 13mm margin on the left, rather than an 11mm margin, and a 29mm from the top rather than 23mm!

Dim dSideMargin As Double = XUnit.FromMillimeter(11)
oXGraphics.DrawString("My test string", oXFont_H, XBrushes.Black, _
New XRect(dSideMargin, XUnit.FromMillimeter(23), oPDFPage.Width.Point - (dSideMargin * 2), oXFont_H.Height), XStringFormat.TopLeft)

Have I misunderstood something?

Author:  Thomas Hoevel [ Mon Jun 04, 2007 11:13 am ]
Post subject: 

AFAIK this is a bug - in PDFsharp or in Windows.
The margins of the printer add to the margins you set.

See this thread for a solution.

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