-1

I have a code using AWT graphics and applets.

public class Draw extends Applet{

        public void paint(Graphics g){
                g.drawLine(10,10,20,10);
        }
}

The code above draws a line of 10 units. I am not really sure which unit is the one being used by default. However, I am looking to draw a 10mm line. Finally I would be exporting this output as a PDF and I need the PDF to have a line of required length in mm. How can this be achieved? Thanks in advance.

Maxim Dsouza
  • 1,507
  • 3
  • 19
  • 32

1 Answers1

2

The measurement unit in PDF is the user unit which by default corresponds with the point (72 user units = 1 inch). This default can be changed (but usually isn't).

If you want to convert points to millimeters, you can use the pointsToMillimeters() function.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • The pointsToMillimeters() returns a float value. g.drawLine expects integers as function values. I even want the co-ordinate system to be in mm instead of points. Basically my entire reference scale for the diagram needs to be in mm. It is basically a drawing for a unit in manufacturing. – Maxim Dsouza Jan 08 '14 at 05:14
  • 1 inch is 25.4mm. Assuming I want a line of 10mm on a pdf. Using a multiple of 72units, I would never get an integral value to be passed to g.drawLine. – Maxim Dsouza Jan 08 '14 at 06:09
  • Some sample code will be highly appreciated. I have tried a million things but nothing seems to be giving me the result that I expect. – Maxim Dsouza Jan 08 '14 at 06:35
  • I wouldn't know what sample code to send you as I don't understand the requirement. If you want to use millimeters: fine! But you'll have to convert them to user units. This is a no-brainer: it's a matter of simple math. In any case: PDF's measure unit is in user units and one user unit corresponds with one point. If you want to change that, good look, but as a member of the ISO committee, I can assure you that will never happen. – Bruno Lowagie Jan 08 '14 at 14:58