我不明白m参数的矩阵PDPageContentStream.setTextMatrix(Matrix 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.

我也搜索了一些例子,但没有找到对这些值的解释。另外,奇怪的是,当我对两个不同的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类。
关于单浮点数/双浮点数的含义:
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中,您可以阅读如何处理这些值。以下是可能的操作的可视化表示:
android - 了解PDPageContentStream.setTextMatrix()的参数-LMLPHP
注:tXtYorg.apache.pdfbox.util.Matrix和上图中的位置略有不同。
希望这能解决问题。

关于android - 了解PDPageContentStream.setTextMatrix()的参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39597315/

10-08 22:28