这是第二段代码,实现DrawToPDF,这个方法是我在iTextSharp.text.Pdf.Barcodes中的pdf417条码对象中加的一段:
public void DrawToPDF(iTextSharp.text.pdf.PdfContentByte cb,RectangleF drawRect,System.Drawing.Color foreColor,System.Drawing.Color backColor,float angle)
{
float bottom=cb.PdfDocument.PageSize.Height-drawRect.Bottom;
PdfTemplate pdfTmp=cb.CreateTemplate(drawRect.Width,drawRect.Height);
PaintCode();
float unitHeight=drawRect.Height/(codeRows*yHeight);
float unitWidth=drawRect.Width/bitColumns;
float tmpFloat=unitHeight>unitWidth?unitWidth:unitHeight;
float drawWidth=tmpFloat;
float drawHeight=tmpFloat*yHeight;
int stride = (bitColumns + 7) / 8;
float drawX=drawRect.X;
float drawY=drawRect.Y;
pdfTmp.SetColorFill(new iTextSharp.text.Color(backColor));
pdfTmp.Rectangle(0f,0f,pdfTmp.Width,pdfTmp.Height);
pdfTmp.Fill();
pdfTmp.SetColorFill(new iTextSharp.text.Color(foreColor));
for (int k = 0; k < codeRows; ++k)
{
drawX=0f;
drawY=pdfTmp.Height-(k+1)*drawHeight;
int p = k * stride;
for (int j = 0; j < bitColumns; ++j)
{
drawX=j*drawWidth;
int b = outBits[p + (j / 8)] & 0xff;
b <<= j % 8;
if((b & 0x80)==0)
{
pdfTmp.Rectangle(drawX,drawY,drawWidth,drawHeight);
}
}
}
pdfTmp.Fill();
cb.AddTemplate(
pdfTmp,(float)Math.Cos(System.Math.PI* angle/180),
(float)Math.Sin(System.Math.PI* angle/180),
-(float)Math.Sin(System.Math.PI* angle/180),
(float)Math.Cos(System.Math.PI* angle/180),
drawRect.X,
bottom
);
}
回复 引用