I've been looking for something similar to pdfsharp for a while for a project at work. It fits almost perfectly (no spot color as yet) but it can embed other pdf documents and is much easier to work with for what I need it to do. The only problem I was having was with text position in barcodes.
In the code I downloaded it only allows for the text to be at the bottom of the barcode or to remove it but if you increased the font it overlaped the bars. So I set about fixing it and came up with the solution below which works with the code39 and 2of5 types.
The fix replaces two routines in ThickThinBarcodeRenderer.cs, the replacements are:
Code:
internal void RenderBar(BarCodeRenderInfo info, bool isThick)
{
double barWidth = GetBarWidth(info, isThick);
double height = Size.Height;
double XPos = info.CurrPos.X;
double YPos = info.CurrPos.Y;
switch (TextLocation)
{
case TextLocation.AboveEmbedded:
height -= info.Gfx.MeasureString(this.Text, info.Font).Height;
YPos += info.Gfx.MeasureString(this.Text, info.Font).Height;
break;
case TextLocation.BelowEmbedded:
height -= info.Gfx.MeasureString(this.Text, info.Font).Height;
break;
}
XRect rect = new XRect(XPos, YPos, barWidth, height);
info.Gfx.DrawRectangle(info.Brush, rect);
info.CurrPos.X += barWidth;
}
and
Code:
internal void RenderText(BarCodeRenderInfo info)
{
if (info.Font == null)
info.Font = new XFont("Courier New", Size.Height / 6);
XPoint center = info.Position + CodeBase.CalcDistance(this.anchor, AnchorType.TopLeft, this.size);
switch (TextLocation)
{
case TextLocation.Above:
center = new XPoint(center.X, center.Y - info.Gfx.MeasureString(this.Text, info.Font).Height);
info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
break;
case TextLocation.AboveEmbedded:
info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.TopCenter);
break;
case TextLocation.Below:
center = new XPoint(center.X, info.Gfx.MeasureString(this.Text, info.Font).Height + center.Y);
info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
break;
case TextLocation.BelowEmbedded:
info.Gfx.DrawString(this.text, info.Font, info.Brush, new XRect(center, Size), XStringFormats.BottomCenter);
break;
}
}
I used measurestring as I found that font.height produced too big a gap and I just didn't like how it looked, the disadvantage is the increased time to render a barcode as its called each time a bar is rendered.
With these two routines in place TextLocation works as it is described. Above and Below place the text outside of the barcode area so a barcode height of 10mm is still 10mm. AboveEmbedded and BelowEmbedded place the text within the confines of the barcode area and decreases the height of the bars accordingly.