好吧,我试图用一些字符串打印一个定制的二维码。
我面临的问题是无法将字符串放置在正确的位置,简而言之无法自定义输出。
我得到的是混乱的。我可以创建模板并打印吗?
自定义代码
CurrentY = 0;
CurrentX = 0;
InvSubTitleHeight = (int)(InvSubTitleFont.GetHeight(g));
// Get Titles Length:
int lenInvSubTitle1 = (int)g.MeasureString("Bill ID : " + billId, InvSubTitleFont).Width;
int lenInvSubTitle2 = (int)g.MeasureString("Bill Amount : " + billAmt, InvSubTitleFont).Width;
int lenInvSubTitle3 = (int)g.MeasureString("Date : " + DateTime.Now.ToString("dd/MM/yyyy"), InvSubTitleFont).Width;
// Set Titles Left:
int xInvSubTitle1 = CurrentX + lenInvSubTitle1 / 2;
int xInvSubTitle2 = CurrentX + lenInvSubTitle2 / 2;
int xInvSubTitle3 = CurrentX + lenInvSubTitle3 / 2;
// Draw Invoice Head:
if (billId != "")
{
CurrentY = CurrentY + InvSubTitleHeight;
g.DrawString("Bill ID : " + billId, InvSubTitleFont, BlackBrush, 0, CurrentY);
}
if (billAmt != "")
{
CurrentY = CurrentY + InvSubTitleHeight + 5;
g.DrawString("Bill Amount : " + billAmt, InvSubTitleFont, BlackBrush, 0, CurrentY);
}
CurrentY = CurrentY + InvSubTitleHeight + 5;
g.DrawString("Date : " + DateTime.Now.ToString("dd/MM/yyyy"), InvSubTitleFont, BlackBrush, 0, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 15;
var image = QRValidation.CreateImage(img);
var p = new Point(0, CurrentY);
g.SmoothingMode = SmoothingMode.HighQuality;
g.DrawImage(image, p);
CurrentY += image.Height + 20;
//Add bottom Text
g.DrawString("Scan the image above with your", InvSubTitleFont, BlackBrush, 0, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 2;
g.DrawString("X app and earn reward", InvSubTitleFont, BlackBrush, 0, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 2;
g.DrawString("points for your last purchase", InvSubTitleFont, BlackBrush, 0, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 25;
g.DrawString("You can scan this QR Code only", new Font("Times New Roman", 10, FontStyle.Bold), BlackBrush, 0, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 3;
g.DrawString("once.", new Font("Times New Roman", 10, FontStyle.Bold), BlackBrush, 90, CurrentY);
// Draw line:
CurrentY = CurrentY + InvSubTitleHeight + 25;
var width = (int) g.MeasureString("Powered by X", InvSubTitleFont).Width;
g.DrawLine(new Pen(Brushes.DarkCyan, 3), CurrentX, CurrentY, width+2, CurrentY);
CurrentY = CurrentY + InvSubTitleHeight + 5;
g.DrawString("Powered by X", InvSubTitleFont, BlackBrush, 0, CurrentY);