Wrong size of drawn primitives

Hi. Using simple code as below

var doc = new PdfDocument();
//Load some existing document
var lDoc = pdfController.Load();
doc.ImportPage(lDoc, 0);
var page = doc.Pages[0];
var g1 = page.Graphics;
g1.DrawLine(PdfPens.Red, 100,100,200,100);
doc.Save(sfd.FileName);
doc.Close();
lDoc.Close();

And expecting to see line of lenght = 100 pixels. But get 135. Why? I suspect there some unit conversion but can't get it
Pdfreader set to 100% view


3 Replies 1 reply marked as answer

IJ Irfana Jaffer Sadhik Syncfusion Team May 2, 2022 12:31 PM UTC

Hi Oleksandr,


We have tried to reproduce the reported issue with the provided details on our end, but it is working properly. We suspect that reported issue may be input document specific. We have attached the sample for your reference in which we are trying to reproduce the reported issue. Please try the below sample on your end and let us know the result.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ConsoleSample_(2)-16459343

Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/output_(1)723958657


We request you to share the input document, output document and modified sample with product version to replicate the reported issue on our end. So, that it will be helpful for us to analyze and assist you further on this.



Regards,

Irfana J.




VI ViterAlex May 2, 2022 12:54 PM UTC

Hi, Irfana.

I found that line in your output is also 135 pixels. I use FastStone ruler to measure pixels on screen. What tool do you use for measuring?



GK Gowthamraj Kumar Syncfusion Team May 3, 2022 01:30 PM UTC

Hi Oleksandr,


Our Syncfusion PDF library will consider all values as points. For example, if you get a PDF document page size, it will be in points. And If you draw an image/rectangle/line on a PDF page, the input value will be considered as points. In this code snippet, line X bounds are used as 100 in point, when we convert this point to pixels, it's value is 133 pixels. We have unit conversion APIs, https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.Graphics.PdfGraphicsUnit.html. Using these APIs, you can convert which unit type is required and compare it accordingly.

//Create a PDF unit converter instance. 

PdfUnitConvertor converter = new PdfUnitConvertor(); 

//Convert to pixel. 

float width = converter.ConvertToPixels(100, PdfGraphicsUnit.Point);  


Regards,

Gowthamraj K


Marked as answer
Loader.
Up arrow icon