创建距离标尺的注释不会显示正确的度量单位,也不会给出正确的计算。知道我哪一部分做错了吗?还是缺少一些数据。
我当前正在创建一个度量距离注释。使用像素,效果很好。但是自从现在以来,我考虑了实际的尺寸和单位,所以我不确定我在哪一部分代码上有问题,或者我是否缺少某些内容。
请参阅图片。那是我用于创建距离注释的一些应用程序,我将其校准为该距离为14.5cm,因此通过将其除以像素,每个像素的校准值将为0.0519548。
现在,当我将其应用于iText代码时,我感到困惑,为什么显示始终始终为英寸?即使我将代码设置为英寸而不是厘米,计算也不正确。
我不确定是什么问题。
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正在为您添加标签,以防您有空闲时间进行检查和指导。谢谢。
答案 0 :(得分:1)
我没有完全遵循你的数学。
您的行的长度约为。 209.3用户空间单位。如果您希望该线代表14.5厘米,则 X C 转换系数应约为 0.069273 ,而不是您的 0.0519548 。
设置
import { Component, OnInit } from '@angular/core';
import { TimeoutError } from 'rxjs';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
@Component({
selector: 'app-customer-portal-step1',
templateUrl: './customer-portal-step1.component.html',
styleUrls: ['./customer-portal-step1.component.scss']
})
export class CustomerPortalStepOneComponent implements OnInit {
isLinear = true;
firstFormGroup: FormGroup;
secondFormGroup: FormGroup;
thirdFormGroup: FormGroup;
constructor(private _formBuilder: FormBuilder) { }
ngOnInit() {
this.firstFormGroup = this._formBuilder.group({
firstCtrl: ['', Validators.required]
});
this.secondFormGroup = this._formBuilder.group({
secondCtrl: ['', Validators.required]
});
this.thirdFormGroup = this._formBuilder.group({
secondCtrl: ['', Validators.required]
});
}
selectedStep1Option: string = 'nothing yet';
step1options = [
{
text: 'Buying my first home',
id: 'buying'
},
{
text: 'Moving to a new home',
id: 'moving'
},
{
text: 'Remortgaging my home',
id: 'remortgage'
},
{
text: 'Purchasing a buy-to-let',
id: 'purchase'
}
];
status: boolean = false;
getOptionName (Oname: any) {
this.selectedStep1Option = Oname.textContent;
localStorage.setItem('I\'m thinking of:', JSON.stringify({ motivation: Oname.textContent }));
}
}
我得到一个PDF,打开时显示
稍作移动(之后Adobe Reader会重建外观)
所以没有英寸...