LEAD Technologies, Inc

PDF Coordinate System

PDF files have the following properties:

For example, a typical PDF document may have a page width and height of 612 by 792 units. Hence:

The following image shows this typical PDF document and the object location:

Note that PDF documents contain a media box and a crop box values. The media box is the total size of the page while the crop box is its viewable areas. PDF viewers typically do not show any object that is located outside the crop box and report the size of the page to be the width and height of the crop box. So when a PDF viewer such as Adobe Acrobat Reader opens the document shown above; it will report the page size to be 8.5" by 11" even though the media box size of 10.5" by 13". Object location are always calculated as the distance from the media box location (always 0, 0) regardless of the value of the crop box. However, most PDF documents contain a media box and crop box of the same values so the two values are the same.

Physical values such as pixels are typically needed when a PDF document is rendered to the screen. To convert from logical to physical units, a resolution must be provided. Resolution is the value of dots (pixels) per inch to use when converting logical to physical values. In the example above, if a resolution value of 150 is used, then the size of the page in pixels is 1275 by 1650 - Obtained by multiplying 8.5" and 11" by 150. It is also desirable to obtain the converted value in top-left coordinates when converting from PDF units (logical) to pixels (physical) since most rendering systems such as System.Drawing and System.Windows.Media has the origin at the upper left corner of the window.

PDF documents do not contain a resolution; it is up to the user to specify the value to use when rendering the document on screen. High resolution values will render the document with greater details at the expense of using more system resources. Typical resolution values are 72, 96, 150, 200, 300 and 600.

If the document shown in the image above is loaded at a resolution of 150, then the object will be located at the following pixel value:

Pixel X = 600px (288 by 72 multiplied by 150)

Pixel Y = 750px (Page Height - 432 by 72 multiplied by 150)

Notice when the Y value is calculated, we subtracted the total value from the height of the page and thus, converted the result from bottom-left to top-left coordinates.

When using the Leadtools.Pdf.PDFFile or Leadtools.Pdf.PDFDocument classes of Leadtools.Pdf, LEADTOOLS will read the values from the PDF document as is without any conversion. The following values are read in PDF units (1/72 of an inch):

The PDFDocument.Resolution property contains the resolution value to use when converting PDF units (logical) to pixels or inches and back. This resolution can be changed at any time as desired.

The helper methods PDFDocumentPage.ConvertPoint and PDFDocumentPage.ConvertRect can be used to convert from any unit to another. These methods accept a Leadtools.Pdf.PDFCoordinateType enumeration member for the source and destination units.

The following converts a point (sourcePoint) from PDF units to inches and pixels:

    
             PDFPoint destPointInches = pdfDocumentPage.ConvertPoint(PDFCoordinateType.Pdf, PDFCoordinateType.Inch, sourcePoint);
             PDFPoint destPointPixels = pdfDocumentPage.ConvertPoint(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, sourcePoint);
             

  

To convert a rectangle (sourceRect) from PDF units to pixels and inches, you use the following:

    
             PDFRect destRectInches = pdfDocumentPage.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Inch, sourceRect);
             PDFRect destRectPixels = pdfDocumentPage.ConvertRect(PDFCoordinateType.Pdf, PDFCoordinateType.Pixel, sourceRect);
             

  

To convert the values back to PDF units, you use the following:

    
             sourcePoint = pdfDocumentPage.ConvertPoint(PDFCoordinateType.Inch, PDFCoordinateType.Pdf, destPointInches);
             sourcePoint = pdfDocumentPage.ConvertPoint(PDFCoordinateType.Pixel, PDFCoordinateType.Pdf, destPointPixels);
             sourceRect = pdfDocumentPage.ConvertRect(PDFCoordinateType.Inch, PDFCoordinateType.Pdf, destRectInches);
             sourceRect = pdfDocumentPage.ConvertRect(PDFCoordinateType.Pixel, PDFCoordinateType.Pdf, destRectPixels);
             

  

Note that the Leadtools.Pdf.PDFDocumentPage object will always use the value of the owner PDFDocument.Resolution when converting from and to pixels.

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.