创建用于距离注释的量度字典 [英] Creating measure dictionary for distance annotation

查看:106
本文介绍了创建用于距离注释的量度字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建距离标尺的注释不会显示正确的度量单位,也不会给出正确的计算.知道我哪一部分做错了吗?还是缺少一些数据.

Creating a measure distanced annotation does not display the correct measurement unit, nor gives the correct calculation. Any idea which part I am doing wrong? or if there is some lacking data.

我当前正在创建一个度量距离注释.使用像素,效果很好.但是自从现在以来,我考虑到了实际的尺寸和单位,所以我不确定我在哪一部分代码上有问题,或者我是否缺少某些内容.

I am currently creating a measure distance annotation. Using pixel, it works just fine. but since now i am taking into account actual measurement and unit, i am not sure which part of code i am having problem with or if i am lacking something.

请参阅图片.那是我用来创建距离注释的一些应用程序,我将其校准为该距离为14.5cm,因此通过将其除以像素,每个像素的校准值将为0.0519548.

Please see image. That is some application i use to create a distance annotation and i calibrate it that that distance is 14.5cm so by dividing it by pixel, the calibration value per pixel would be 0.0519548.

现在,当我将其应用于iText代码时,我很困惑为什么显示始终始终为英寸?即使我将代码设置为英寸而不是厘米,计算也不正确.

Now, when I apply it to iText code, i am confused why the display is always still in inches? Even if i set my code to be inches and not cm, the calculation is incorrect.

我不确定是什么问题.

public class Test {

        public static void main(String[] args) throws Exception {
            PdfReader reader = new PdfReader("src.pdf");
            PdfStamper stamper = new PdfStamper(reader, new FileOutputStream("result.pdf"));

            Rectangle location = new Rectangle(55.78125f, 493.875f, 253.59375f, 562.3125f);

            PdfDictionary dict = new PdfDictionary();

            PdfArray lineEndings = new PdfArray();
            lineEndings.add(new PdfName("OpenArrow"));
            lineEndings.add(new PdfName("OpenArrow"));

            PdfAnnotation stamp = PdfAnnotation.createLine(stamper.getWriter(), location, "test measurement", 55.78125f, 562.3125f, 253.59375f, 493.875f);
            stamp.put(new PdfName("LE"), lineEndings);
            stamp.put(PdfName.ROTATE, new PdfNumber(0));
            stamp.put(PdfName.MEASURE, createMeasureDictionary());
            stamp.put(new PdfName("IT"), new PdfName("LineDimension"));
            stamp.put(new PdfName("Cap"), new PdfBoolean(true));
            stamp.put(PdfName.F, new PdfNumber(516));

            stamp.setColor(PdfGraphics2D.prepareColor(Color.RED));
            stamper.addAnnotation(stamp, 1);
            stamper.close();
            reader.close();
        }

        private static PdfDictionary createMeasureDictionary() {
            PdfDictionary measureDictionary = new PdfDictionary(PdfName.MEASURE);
            measureDictionary.put(PdfName.R, new PdfString("1 cm = 1 cm"));

            PdfDictionary xDictionary = new PdfDictionary(PdfName.NUMBERFORMAT);

            xDictionary.put(PdfName.U, new PdfString("cm"));
            xDictionary.put(PdfName.C, new PdfNumber(0.0519548f));
            measureDictionary.put(PdfName.X, new PdfArray(xDictionary));

            PdfDictionary dDictionary = new PdfDictionary(PdfName.NUMBERFORMAT);
            dDictionary.put(PdfName.U, new PdfString("cm"));
            dDictionary.put(PdfName.C, new PdfNumber(1.0f));
            measureDictionary.put(PdfName.D, new PdfArray(dDictionary));

            PdfDictionary aDictionary = new PdfDictionary(PdfName.NUMBERFORMAT);
            aDictionary.put(PdfName.U, new PdfString("cm"));
            aDictionary.put(PdfName.C, new PdfNumber(1.0f));
            measureDictionary.put(PdfName.A, new PdfArray(aDictionary));

            return measureDictionary;
        }

}

@mkl正在为您添加标签,以防您有空闲时间进行检查和指导.谢谢.

@mkl im tagging you in case you have free time to check and guide. thank you.

推荐答案

我没有完全遵循你的数学.

I do not fully follow your math.

您的行的长度约为. 209.3用户空间单位.如果您希望该线代表14.5厘米,则 X C 转换系数应约为 0.069273 ,而不是您的 0.0519548 .

Your line has a length of ca. 209.3 user space units. If you want that line to represent 14.5 cm, the X Conversion factor should be about 0.069273 and not your 0.0519548.

设置

xDictionary.put(PdfName.C, new PdfNumber(0.069273f));

我得到一个PDF,打开时显示

I get a PDF which upon opening shows

并稍作移动(之后Adobe Reader会重建外观)

and after a slightest move (after which Adobe Reader rebuilds the appearance)

所以没有英寸...

这篇关于创建用于距离注释的量度字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆