C# 如何使用itextsharp(pdfstamper)将数字字段向右对齐

C# 如何使用itextsharp(pdfstamper)将数字字段向右对齐,c#,pdf,alignment,itextsharp,C#,Pdf,Alignment,Itextsharp,请参考我在pdf上写值的代码。但我想将数字字段向右对齐。 是否有用于此的属性/方法。我正在使用此属性PdfFormField.MK\u CAPTION\u RIGHT,但它不起作用 var pdfReader = new PdfReader(outputPath); string fontsfolder1 = @"D:\ItextSharp\Fonts\acmesab.TTF"; var pdfStamper1 = new PdfStamper(pdfReader, new FileStream

请参考我在pdf上写值的代码。但我想将数字字段向右对齐。
是否有用于此的属性/方法。我正在使用此属性
PdfFormField.MK\u CAPTION\u RIGHT
,但它不起作用

var pdfReader = new PdfReader(outputPath);
string fontsfolder1 = @"D:\ItextSharp\Fonts\acmesab.TTF";
var pdfStamper1 = new PdfStamper(pdfReader, new FileStream(outputPath3, FileMode.Create));
BaseFont customfont1 = BaseFont.CreateFont(fontsfolder, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
   AcroFields af = pdfStamper1.AcroFields;
   List<BaseFont> list1 = new List<BaseFont>();
   list.Add(customfont1);
   iTextSharp.text.Font bold1 = new iTextSharp.text.Font(customfont1, 6, 0, BaseColor.BLACK);
   af.SubstitutionFonts = list;
   foreach (var field1 in af.Fields)
   {
            af.SetFieldProperty(field1.Key, "textalignment", PdfFormField.MK_CAPTION_RIGHT, null);
     af.SetField(field1.Key, "123");
   }
     pdfStamper1.FormFlattening = false;
     pdfStamper1.Close();
var-pdfReader=新的pdfReader(outputPath);
字符串fontsfolder1=@“D:\ItextSharp\Fonts\acmesab.TTF”;
var pdfStamper1=newpdfstamper(pdfReader,newfilestream(outputPath3,FileMode.Create));
BaseFont customfont1=BaseFont.CreateFont(fontsfolder、BaseFont.IDENTITY、BaseFont.EMBEDDED);
AcroFields af=PDFS1.AcroFields;
List list1=新列表();
列表。添加(customfont1);
iTextSharp.text.Font bold1=新的iTextSharp.text.Font(customfont1,6,0,BaseColor.BLACK);
af.SubstitutionFonts=列表;
foreach(af.Fields中的变量字段1)
{
af.SetFieldProperty(field1.Key,“textalignment”,PdfFormField.MK_CAPTION_RIGHT,null);
af.SetField(字段1.Key,“123”);
}
PDFS1.FormFlatting=false;
pdfs1.Close();

我不知道如何使用ItextSharp属性直接执行此操作。但一种方法是在内容左侧添加空格,要执行此操作,可以获得字段长度,并基于该长度和内容长度,您可以计算要添加到内容左侧的空格。它会自动将您的内容放在PDF字段的右侧。希望这种方式可以帮助您解决问题…

您可以使用ShowTextAligned方法对齐文本,该方法采用对齐参数,如下所示:

cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT,"Text is left aligned",200,800,0);
cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT,"Text is right aligned",200,788,0);
其中cb是
PdfContentByte


感谢您的回复…我看到他们使用writer的链接…但这里我使用Pdfstamper…如何将此属性与Pdfstamper一起使用?