代码就像
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(Logo_Path);
Phrase p = new Phrase("");
logo.RotationDegrees = 180f;
p.Add(new Chunk(logo, 30, 30, false));
ColumnText.ShowTextAligned(stamper.GetOverContent(i), Element.ALIGN_RIGHT, p, 400f, 5f, 0);
但是它显示了左边的图像..如何正确地使用它?
答案 0 :(得分:1)
左右混淆,左对齐和右对齐。
我有一张狗的图像和一只狐狸的图像。
我正在添加左对齐的狗,并且狐狸右对齐:
Image d = Image.getInstance(DOG);
d.setScaleToFitHeight(false);
Image f = Image.getInstance(FOX);
f.setScaleToFitHeight(false);
Chunk dog = new Chunk(d, 0, 0, false);
Chunk fox = new Chunk(f, 0, 0, false);
PdfContentByte canvas = writer.getDirectContent();
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(dog), 250, 750f, 0);
ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase(fox), 250, 750f, 0);
狗是在右边,因为"左对齐"意味着x = 250
将与图像的左侧重合,将在左侧。狐狸在左边是因为"右对齐"意味着x = 250
将与图像的右侧重合。
答案 1 :(得分:0)
FileStream fs = new FileStream(@"D:\test.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(@"D:\testLogo.png");
logo.Alignment = 6;
doc.Add(logo);
doc.Add(new Paragraph(@"Test"));
doc.Close();
您只需将图像的对齐设置为6形式右对齐