I just discovered MigraDoc the other day, and I love it! But I'm having difficulty getting a barcode to show up in a PDF I'm creating. Here's the relevant code (c# 6):
Code:
Table voterTable = CurrentSection.AddTable();
foreach( Unit colWidth in ColumnWidths )
{
voterTable.AddColumn( colWidth );
}
foreach( Voter voter in voters
.OrderBy( v => v.LastName )
.ThenBy( v => v.FirstName ) )
{
// create name
StringBuilder sbVoter = new StringBuilder();
if( voter.BallotType != BallotType.PollingPlace ) sbVoter.Append( "@" );
sbVoter.AppendWithSeparator( voter.LastName, "" );
sbVoter.AppendWithSeparator( voter.FirstName, ", " );
Row voterRow = voterTable.AddRow();
voterRow.Cells[ 0 ].AddParagraph( sbVoter.ToString() );
voterRow.Cells[ 1 ].AddParagraph( $"{voter.GetAge():n0}" );
foreach( string factor in voter.GetFactors() )
{
voterRow.Cells[ 2 ].AddParagraph( factor );
}
voterRow.Cells[ 3 ].AddParagraph( "Y N U AB LA" ).Format = GetParagraphFormat(BoldBaseFont, ptsAfter: 0, ptsBefore: 0);
Barcode bcVoter = voterRow.Cells[ 4 ].Elements.AddBarcode();
bcVoter.Code = voter.VoterID.ToString();
bcVoter.Text = false;
bcVoter.Type = BarcodeType.Barcode39;
bcVoter.Orientation = TextOrientation.Horizontal;
bcVoter.Width = Unit.FromInch(1.5);
bcVoter.Height = Unit.FromInch( 0.25 );
}
This creates a table, with one row for each voter. The table has five columns, the last one (4) should contain the barcode. No errors are reported during execution, and the PDF gets created by PdfRenderer. The Free 3 of 9 barcode font is installed on the machine.
PdfRenderer is created like this:
Code:
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer( false, PdfFontEmbedding.Always );
I'm obviously missing something simple. Suggestions?
- Mark