A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
Hi @Pratham Jain,
Your export code is OK. The issue is typically that the “barcode” is generated by a Code39 font, and when WPF renders to a RenderTargetBitmap it will only draw the bars if that exact font is available and actually used. If WPF can’t resolve the Code39 font, it silently falls back to a normal font and the barcode bars won’t appear in the saved PNG.
Please check
- Is the Code39 font installed on the same machine where you generate the PNG (dev PC / server / VM)?
- Are you explicitly setting the barcode TextBlock’s
FontFamilyto the Code39 font (with the correct family name)?
Example (works if the font is installed and the family name matches):
<TextBlock Text="*RI000001*" FontFamily="Free 3 of 9" FontSize="48" />
To avoid relying on the font being installed on every machine, you can try embed the Code39 font to your WPF app
- Add the
.ttf(Code39) to your project, e.g.Fonts/Code39.ttf - Select the TTF in Solution Explorer and set Build Action =
Resource - Reference it via pack URI (important: the part after
#must match the font’s internal family name, not necessarily the file name):
<TextBlock
Text="*RI000001*"
FontSize="48"
FontFamily="pack://application:,,,/YourAssemblyName;component/Fonts/#Your Code39 Font Family Name" />
You can read more on that approach here Packaging Fonts with Applications.
Let me know if this works for you.