How to pass Rectangle size available in Millimetre

2019-02-25 14:12发布

问题:

I need to create a PDF file with 100mm X 150mm (Width X Height). To create this I tried to apply following:

  var doc = new iTextSharp.text.Document(new Rectangle(100f, 150f)); 

and

float height = 0;
float width = 0;

float.TryParse("100", out width);
float.TryParse("150", out height);

var doc = new iTextSharp.text.Document(new Rectangle(width, height));

But above are generating smaller/ larger size PDF. Please share suggestions that how I can convert the mm to float and make it work.

回答1:

The measurement used in PDF is called the user unit. By default 1 user unit equals 1 point. There are 72 points in one inch. This explains why you document is smaller than expected if you pass a value that is expressed in millimeters rather than user units.

If you want to use millimeters and you don't want to do the Math, you can use the static millimetersToPoints() method in the Utilities class.



标签: c# itext