理解 PDPageContentStream.setTextMatrix() 的参数
Understanding the arguments of PDPageContentStream.setTextMatrix()
我无法理解 PDPageContentStream.setTextMatrix(Matrix m)
参数的矩阵 m
中的 6 个值表示什么。以前它需要 6 个值,但现在它需要一个包含所有值的矩阵。
是的,我已经阅读了文档,但我发现解释完全没有用 -
public void setTextMatrix(double a,
double b,
double c,
double d,
double e,
double f)
throws IOException
The Tm operator. Sets the text matrix to the given values. A current text matrix will be replaced with the new one.
Parameters:
a - The a value of the matrix.
b - The b value of the matrix.
c - The c value of the matrix.
d - The d value of the matrix.
e - The e value of the matrix.
f - The f value of the matrix.
我也搜索过示例,但没有找到对这些值的解释。另外,奇怪的是,当我对 2 个不同的 PDF 文件尝试相同的值时,结果不同,所以我假设这与边距和距离等有关。
我觉得我在浪费时间进行猜测。对参数的直接解释将非常好。
编辑
我知道矩阵以及如何传递值。我不知道矩阵中的值实际上是什么意思。
您可以尝试绕过新方法要求,方法是使用 Matrix
constructors
setTextMatrix(new Matrix(Double.valueOf(a).floatValue(),
Double.valueOf(b).floatValue(),
Double.valueOf(c).floatValue(),
Double.valueOf(d).floatValue(),
Double.valueOf(e).floatValue(),
Double.valueOf(f).floatValue()))
失去部分 double
准确性的风险很小。
编辑:
你可以看看这个例子 - UsingTextMatrix.
根据 PDPageContentStream.java 这是已弃用的 setTextMethod
,您为此查询:
@Deprecated
public void setTextMatrix(double a, double b, double c, double d, double e, double f) throws IOException
{
setTextMatrix(new Matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f));
}
这基本上完成了我在上面尝试过的操作。因此,除了更紧凑的用法之外,应该没有任何重大差异。有关详细信息 org.apache.pdfbox.pdmodel.PDPageContentStream
class.
关于单个float/double值的含义:
a, b, c, d, e, f
定义单个 org.apache.pdfbox.cos.COSArray
形式:
static final float[] DEFAULT_SINGLE =
{
a,b,0,
c,d,0,
e,f,1
};
哪里
a stands for ScaleX
b stands for ShearY
c stands for ShearX
d stands for ScaleY
e stands for TranslateX
f stands for TranslateY
在此 Wiki about Affine Transformations 中,您可以阅读可以使用这些值执行的操作。下面直观地表示了可能的操作:
注:org.apache.pdfbox.util.Matrix
和上图中tX
和tY
的位置略有不同
希望这能解决问题。
我无法理解 PDPageContentStream.setTextMatrix(Matrix m)
参数的矩阵 m
中的 6 个值表示什么。以前它需要 6 个值,但现在它需要一个包含所有值的矩阵。
是的,我已经阅读了文档,但我发现解释完全没有用 -
public void setTextMatrix(double a,
double b,
double c,
double d,
double e,
double f)
throws IOException
The Tm operator. Sets the text matrix to the given values. A current text matrix will be replaced with the new one.
Parameters:
a - The a value of the matrix.
b - The b value of the matrix.
c - The c value of the matrix.
d - The d value of the matrix.
e - The e value of the matrix.
f - The f value of the matrix.
我也搜索过示例,但没有找到对这些值的解释。另外,奇怪的是,当我对 2 个不同的 PDF 文件尝试相同的值时,结果不同,所以我假设这与边距和距离等有关。
我觉得我在浪费时间进行猜测。对参数的直接解释将非常好。
编辑
我知道矩阵以及如何传递值。我不知道矩阵中的值实际上是什么意思。
您可以尝试绕过新方法要求,方法是使用 Matrix
constructors
setTextMatrix(new Matrix(Double.valueOf(a).floatValue(),
Double.valueOf(b).floatValue(),
Double.valueOf(c).floatValue(),
Double.valueOf(d).floatValue(),
Double.valueOf(e).floatValue(),
Double.valueOf(f).floatValue()))
失去部分 double
准确性的风险很小。
编辑:
你可以看看这个例子 - UsingTextMatrix.
根据 PDPageContentStream.java 这是已弃用的 setTextMethod
,您为此查询:
@Deprecated
public void setTextMatrix(double a, double b, double c, double d, double e, double f) throws IOException
{
setTextMatrix(new Matrix((float)a, (float)b, (float)c, (float)d, (float)e, (float)f));
}
这基本上完成了我在上面尝试过的操作。因此,除了更紧凑的用法之外,应该没有任何重大差异。有关详细信息 org.apache.pdfbox.pdmodel.PDPageContentStream
class.
关于单个float/double值的含义:
a, b, c, d, e, f
定义单个 org.apache.pdfbox.cos.COSArray
形式:
static final float[] DEFAULT_SINGLE =
{
a,b,0,
c,d,0,
e,f,1
};
哪里
a stands for ScaleX
b stands for ShearY
c stands for ShearX
d stands for ScaleY
e stands for TranslateX
f stands for TranslateY
在此 Wiki about Affine Transformations 中,您可以阅读可以使用这些值执行的操作。下面直观地表示了可能的操作:
注:org.apache.pdfbox.util.Matrix
和上图中tX
和tY
的位置略有不同
希望这能解决问题。