Add a barcode to the footer

57 Views Asked by At

There is a code that creates a footer and inserts a barcode.But the problem is that it adds it to all pages.And it is necessary that the right footer with the barcode is only on the first page.

string dataDir = @"D:\test44\";
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "1234567890");
Stream ms = new MemoryStream();
generator.Save(ms, BarCodeImageFormat.Png);

Document doc = new Document(dataDir + "sample.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move DocumentBuilder into the footer.
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Right;
builder.InsertImage(ms);

doc.Save(@"C:\Temp\out.docx");

The document is created based on an existing document.

1

There are 1 best solutions below

2
Alexey Noskov On

In this case you should simply use first page footer instead of primary footer. Modify your code like this:

builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);

See Aspose.Words documentation to learn how to work with headers/footers: https://docs.aspose.com/words/net/working-with-headers-and-footers/