We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Text in millimeters

Hi i have a document that has to have it's dimensions in millimeters any idea on how i can do that have tried something like below

 recGraphics.DrawString(gNumber.ToString(), recFont, recBrush, new PointF((float)(54* 3.7795275591), (float)(11* 3.7795275591)));
But it's not working , i am working under the assumption that PointF takes dimensions in pixels.

1 Reply

DB Dilli Babu Nandha Gopal Syncfusion Team December 6, 2018 10:20 AM UTC

Hi Jerry,  
Thank you for contacting Syncfusion support.  
In generally, Essential PDF uses point to draw a graphical object. If your requirement is to draw the graphics element in millimeter, then we have a PdfUnitConverter class to convert the millimeter to point. In this case, we have to convert all the points and size should convert to point before drawing into PDF.   
Please find the code snippet and sample below for your reference.  
Code snippet:   
//Initialize PDF document.  
PdfDocument doc = new PdfDocument();  
//Add pages to the PDF document.  
PdfPage page = doc.Pages.Add();  
//Initialize PdfUnitConverter.  
PdfUnitConvertor converter = new PdfUnitConvertor();  
//Convert Millemeter to Point  
float x = converter.ConvertUnits(54, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point);  
float y = converter.ConvertUnits(11, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point);  
//Font size.  
float fontSize = converter.ConvertUnits(12f, PdfGraphicsUnit.Millimeter, PdfGraphicsUnit.Point);  
//Create PdfFont.  
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize, PdfFontStyle.Regular);  
page.Graphics.DrawString("Hello World", font, PdfBrushes.Black, new PointF(x,y));  
//Initialize memorystream  
MemoryStream ms = new MemoryStream();  
//Save the document to stream  
Please let us know whether the provided suggestion fulfills your requirement 
Dilli babu. 

Live Chat Icon For mobile
Up arrow icon