【发布时间】:2011-09-07 16:18:33
【问题描述】:
所以我有生成条形码和带有该条形码标签的方法。我们注意到,当多个用户同时生成条形码时,他们都会得到相同的文件。我正在使用 ASP.NET,并且在内部服务器上托管应用程序和文件。
public void trickylabel(string fnsku, string title)
{
Random random = new Random();
int randomNumber = random.Next(0, 100000);
//Set barcode properties...
code.parse(fnsku); // Text
BCGDrawing drawing = new BCGDrawing(this.Server.MapPath("~") + "image"+ randomNumber.ToString() +".png", color_white);
drawing.setBarcode(code);
drawing.draw();
// Draw (or save) the image into PNG format.
Response.ContentType = "image/png";
drawing.finish(ImageFormat.Png);
Document doc = new Document(new iTextSharp.text.Rectangle(200f, 75f), 20F, 10F, 10F, 1F);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Request.PhysicalApplicationPath +
"\\"+randomNumber.ToString()+".pdf", FileMode.Create));
doc.Open();
iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(this.Server.MapPath("~") + "image" + randomNumber.ToString() +".png");
doc.Add(png);
//Sets pdf properties...
doc.Add(new Paragraph(title, times));
PdfAction action = new PdfAction(PdfAction.PRINTDIALOG);
writer.SetOpenAction(action);
doc.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=labels.pdf");
Response.TransmitFile(Server.MapPath("~/"+randomNumber.ToString()+".pdf"));
}
【问题讨论】:
标签: c# asp.net random itextsharp