Stamp a string of barcode text (3 of 9 barcode font)

I am trying to use a formatted text string to stamp a barcode on the top of a PDF document.

Instead of TimesBold below I need the barcode font:

FormattedText formText = new FormattedText("12345", System.Drawing.Color.Black, FontStyle.TimesBold, EncodingType.Winansi, false, 14);

The list of fonts in Aspose.Facades.PDF.FontStyle does not contain the 3 of 9 barcode font that I need. Is there a way to add the font? Or is there a different way to work with barcodes using another Aspose tool?

Hello Jessi,


Thanks for using our products.

I am afraid Aspose.Pdf.Facades does not support the feature to specify the custom font to be used while adding text over PDF file but we have classes present under Aspose.Pdf and Aspose.Pdf.Text namespaces which support the feature to manipulate/edit existing PDF files and also they support the feature to add text using custom font installed over system.

In order to accomplish your requirement, please try using the following code snippet. For your reference, I have also attached the resultant PDF being generated over my end.

[C#]

//open document<o:p></o:p>

Document pdfDocument = new Document("d:/pdftest/HelloWorld.pdf");

//get particular page

Page pdfPage = (Page)pdfDocument.Pages[1];

//create text fragment

TextFragment textFragment = new TextFragment("12345");

textFragment.Position = new Position(100, 600);

//set text properties

textFragment.TextState.FontSize = 14;

// specify the font for text fragment

textFragment.TextState.Font = FontRepository.FindFont("3 of 9 Barcode");

// font fore ground color

textFragment.TextState.ForegroundColor = System.Drawing.Color.Black;

// create TextBuilder object

TextBuilder textBuilder = new TextBuilder(pdfPage);

// append the text fragment to the PDF page

textBuilder.AppendText(textFragment);

//save document

pdfDocument.Save("d:/pdftest/TextWithBarCode.pdf");


For further information, please visit Add Text in an Existing PDF File

Thank you. Your example code was very helpful. This will work for me.

Hello Jessi,

I am glad to hear that your requirement can be accomplished with above specified code. Please continue using our products and in the event of any further query, please feel free to contact.