我目前正在使用iTextSharp的hello.hs:6:37: Not in scope: ‘args’
hello.hs:7:13:
The last statement in a 'do' block must be an expression
args1 <- getArgs putStrLn ("Hello," ++ args1 !! 1)
hello.hs:7:50:
Not in scope: ‘args1’
Perhaps you meant ‘args’ (line 5)
方法成功地将文字添加到PDF中。该方法看起来像这样(C#):
ShowTextAligned
但是,目前还不清楚我们正在制作的文字的定位点。我们提供public void ShowTextAligned(
int alignment,
string text,
float x,
float y,
float rotation
)
和x
,但这些是否对应于文字矩形的左上角,左下角或其他内容?这也受到行间距的影响吗?
我查看了此website的文档,但它并不是非常明确的解释。请参阅PdfContentByte类/ PdfContentByte方法/ ShowTextAligned方法。
答案 0 :(得分:8)
显然,锚点取决于对齐的类型。如果您的锚点位于文本的左侧,则说右对齐是没有意义的。
此外,文本操作通常相对于基线对齐。
因此:
更直观:
这是使用以下方式生成的:
[Test]
public void ShowAnchorPoints()
{
Directory.CreateDirectory(@"C:\Temp\test-results\content\");
string dest = @"C:\Temp\test-results\content\showAnchorPoints.pdf";
using (Document document = new Document())
{
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(dest, FileMode.Create, FileAccess.Write));
document.Open();
PdfContentByte canvas = writer.DirectContent;
canvas.MoveTo(300, 100);
canvas.LineTo(300, 700);
canvas.MoveTo(100, 300);
canvas.LineTo(500, 300);
canvas.MoveTo(100, 400);
canvas.LineTo(500, 400);
canvas.MoveTo(100, 500);
canvas.LineTo(500, 500);
canvas.Stroke();
ColumnText.ShowTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Left aligned"), 300, 500, 0);
ColumnText.ShowTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Center aligned"), 300, 400, 0);
ColumnText.ShowTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("Right aligned"), 300, 300, 0);
}
}