时间:2018-03-08 标签:c#itextsharpabsolute text location multiline

c# itextsharp absolute text location multiline

我需要在 pdf 文档中定位多行文本。我发现了两个可能性

ColumnText.ShowTextAligned(writer.DirectContent, Element.ALIGN_LEFT, new Phrase(textPhrase), calculatedX,calculatedY, -rotation);

但是当我以这种方式定位文本时,我只能看到第一行,其他所有行都被截断了。

TextField tf = new TextField(writer,
                new Rectangle(calculatedX, calculatedY, calculatedX + width, calculatedY + height), "");
tf.Text = text;
tf.FontSize = font.Size;
tf.Font = font.BaseFont;
tf.Options = BaseField.MULTILINE | BaseField.READ_ONLY;
tf.TextColor = font.Color;
writer.AddAnnotation(tf.GetTextField());

效果很好,我可以看到所有行,但问题是我无法设置粗体下划线等属性....

能否请你帮我找到一个方法,我可以看到所有的行并设置粗体、下划线等属性...

我找到了一个方法:

Phrase phrase = new Phrase(text);
            phrase.Font.Size = font.Size;
            phrase.Font = font;

            ColumnText ct = new ColumnText(writer.DirectContent);
            ct.SetSimpleColumn(calculatedX, calculatedY, calculatedX + (width), calculatedY + height);
            ct.AddElement(phrase);
            ct.Go();