How to apply transformation to get same length of line

Hi,

With the help of ElementReaderAdvTest sample, I am able to read path of a line for the attached PDF file.

I have applied page default matrix and CTM on the path points. I have used those path points and create a line in another format. But, length of the line differs. Please suggest me how to get the same line length on the conversion.

Here is the pseudo code for applying transformation.

Matrix2D defaultMatrix = pageIterator.Current().GetDefaultMatrix();

// Process path and apply transformation

Matrix2D ctm = path.GetCTM();
Matrix2D resultant = defaultMatrix * ctm;

// Process Path Data Points

List listPoints = new List();

switch ((PathData.PathSegmentType) ((int) opr[opr_itr]))

{
case PathData.PathSegmentType.e_moveto:
x1 = data[data_itr]; ++data_itr;
y1 = data[data_itr]; ++data_itr;
resultant.Mult(ref x1, ref y1);
listPoints.Add(new Point(x1, y1));
break;
case PathData.PathSegmentType.e_lineto:
x1 = data[data_itr]; ++data_itr;
y1 = data[data_itr]; ++data_itr;
resultant.Mult(ref x1, ref y1);
listPoints.Add(new Point(x1, y1));
break;
}

With the use of listPoints, I have created lines in another format. But, the line is not same length as in PDF. Please suggest me how to apply transformation to get proper value.

Note: I already posted a question. But I don’t see the question in the list. So, I am posting it again. Sorry for repetition if you already received the same question.

Thanks,
Senthilkumar C K

PdfLineTest.pdf (2.02 KB)

What is the other format that you mention?

How did you decide that they are not the same length? How are you measuring?

Thanks for your response. Other format is DWG. But, that doesn’t matter.

I measured the length from PDF file (attached snapshot).
Next, while reading path data points, I calculated the length using those points (after applying transformation as per above code) which are read from PDF file.
Another way, after conversion into DWG format, I have measured in AutoCAD itself.

PdfLineMeasure.PNG

The issue is that there is a VP entry on the page, which defines a ViewPort and a custom scale.

The idea is that a page might have different scaled regions, and therefore multiple view ports can be defined. View ports can also define the axis, etc.

See section 12.9 in the PDF standard here: https://www.xodo.com/view/#/c0c11968-ee14-478e-9b09-6dc5635c0915

You can also use the COSEdit tool that comes with our windows SDK to see the contents of the PDF.

In particular

trailer/Root/Pages/Kids/0/VP/0/Measure/X/0

Shows that the scale is 0.12395, for that region, though the region does not cover the entire page.

trailer/Root/Pages/Kids/0/VP/0/Measure/X/0

Gives the bounding box of the view port and defines the x/y axis which might not be the same as the PDF coordinate system.

See here on how to access these objects. https://www.pdftron.com/pdfnet/intro.html#sdf_obj

Hi Ryan,

Thanks for your response.I managed to fix the scaling issue from VP entry. We do have some pdf files which does not have any VP entry in the page. Please let me know how can we find scaling value.

Thanks,
Senthil