I need to put a barcode on each page of a PDF document. I'm having a hard time with this and hope someone can help.
This article on XsPDF.com is what you looking for, check out: Draw and add barcode on PDF in C#.
Answers
Sorry for the lack of my understanding. What do you mean by saying put a barcode in PDF document? Do you mean to create and draw a barcode on a PDF or directly add a barcode image to PDF document. These are totally different. The later one is actually to add an image to PDF file. If you want to create a barcode image on the fly and don't want to save to the server, i mean, just put it in the memory stream and show it in a pdf, you may need a library to do this.
Thank you for your quick reply.
Sorry about misleading you guys. I know how to create a pdf in the memory stream, open it, add image, etc. So, what i looking for is the second situation, creating barcode symbology and show it in a PDF page.
Got you! Please download a free trial of XsPDF Barcode SDK and integrate it to your VS project by adding project reference to the library dll. And then use the following sample code to create a QR Code and show it in PDF page.
Here is the simple example:
// Create a new PDF document. PdfDocument document = new PdfDocument(); // Create a page. PdfPage page = document.AddPage(); // Get graphics object from pdf page XGraphics g = XGraphics.FromPdfPage(page); // Create a pdf barcode object PdfBarcode barcode = new PdfBarcode(); // Set the barcode type to qrcode symbol barcode.BarType = BarCodeType.QRCode; // Input the barcode data content barcode.Data = "xspdf123456789"; // Change foreground and background color of barcode barcode.BarcodeColor = XColors.Black; barcode.BackgroundColor = XColors.White; // Set qrcode error correction level barcode.QRCodeECL = ErrorCorrectionLevelMode.L; // Set the barcode Position and location barcode.Location = new XPoint(100, 100); // Set the barcode width and height barcode.Size = new XSize(200, 200); barcode.DrawBarcode(g); // Save and show the document document.Save("Barcode.pdf"); Process.Start("Barcode.pdf");