QR コードを既存のセクションに追加する必要があります。
また、右上隅に配置するには、右揃えParagraphを先頭またはドキュメントのヘッダーに挿入するか、フローティング を挿入しTextBoxます。
以下に、推奨される 3 つのアプローチすべての例を示します。
既存のセクションの本文に挿入
var qrCodeField = new Field(document, FieldType.DisplayBarcode, $"{qrCodeValue} QR");
var qrCodeParagraph = new Paragraph(document, qrCodeField);
qrCodeParagraph.ParagraphFormat.Alignment = HorizontalAlignment.Right;
document.Sections[0].Blocks.Insert(0, qrCodeParagraph);
既存のセクションのヘッダーに挿入
var qrCodeField = new Field(document, FieldType.DisplayBarcode, $"{qrCodeValue} QR");
var qrCodeParagraph = new Paragraph(document, qrCodeField);
qrCodeParagraph.ParagraphFormat.Alignment = HorizontalAlignment.Right;
var headersFooters = document.Sections[0].HeadersFooters;
if (headersFooters[HeaderFooterType.HeaderFirst] == null)
headersFooters.Add(new HeaderFooter(document, HeaderFooterType.HeaderFirst));
headersFooters[HeaderFooterType.HeaderFirst].Blocks.Insert(0, qrCodeParagraph);
フローティングテキストボックスで挿入
var qrCodeField = new Field(document, FieldType.DisplayBarcode, $"{qrCodeValue} QR");
var qrCodeParagraph = new Paragraph(document, qrCodeField);
var qrTextBox = new TextBox(document,
new FloatingLayout(
new HorizontalPosition(-50, LengthUnit.Point, HorizontalPositionAnchor.RightMargin),
new VerticalPosition(50, LengthUnit.Point, VerticalPositionAnchor.TopMargin),
new Size(100, 100)),
qrCodeParagraph);
qrTextBox.Outline.Fill.SetEmpty();
var paragraph = (Paragraph)document.Sections[0]
.GetChildElements(false, ElementType.Paragraph)
.First();
paragraph.Inlines.Add(qrTextBox);