Hi,
We use Barcode generator to Generate a Integer in the form of Barcode. Please find below code
Aspose.Pdf.Document pdfDoc = new Aspose.Pdf.Document(pdfStream);
using (MemoryStream barcodeStream = new MemoryStream())
{
string barcodePrefix = ConfigurationManager.AppSettings["BarcodePrefix"].ToString();
using (BarcodeGenerator builder = new BarcodeGenerator(EncodeTypes.Code128, barcodePrefix + docQueueID.ToString()))
{
builder.Save(barcodeStream, BarCodeImageFormat.Bmp);
double pdfPageHeight = pdfDoc.Pages[1].Rect.Height;
double pdfPageWidth = pdfDoc.Pages[1].Rect.Width;
double marginTop = 45;
double marginRight = 10;
//Locate the top right corner of the pdf for barcode placement
Aspose.Pdf.Rectangle rect = new Aspose.Pdf.Rectangle(pdfPageWidth - 230 - marginRight, pdfPageHeight - 65 - marginTop, pdfPageWidth - marginRight, pdfPageHeight - marginTop); //Barcode size is 230x65 pts
pdfDoc.Pages[1].AddImage(barcodeStream, rect); //Add barcode to first page of worksheet PDF
Same Barcode when we are reading it is reading as different number.
Document inputDocument = new Aspose.Pdf.Document(filePath);
for (int pageNo = 1; pageNo <= inputDocument.Pages.Count; pageNo++)
{
using (MemoryStream pageStream = new MemoryStream())
{
Resolution resolution = new Resolution(300);
PngDevice pngDevice = new PngDevice(resolution);
//Convert a particular page and save the image to stream
pngDevice.Process(inputDocument.Pages[pageNo], pageStream);
// Set the stream position to the beginning of Stream
pageStream.Position = 0;
// Instantiate a BarCodeReader object and set symbology type to recognize
BarCodeReader barCodeReader = new BarCodeReader(pageStream, DecodeType.Code128);
// if there is a barcode, then Read method will return true
string codeText = string.Empty;
bool isValidBarCode = barCodeReader.Read();
if (isValidBarCode)
{
codeText = barCodeReader.GetCodeText();
isValidBarCode = codeText.StartsWith(barcodePrefix); //Consider barcodes that start with the BarcodePrefix
isValidBarCode = isValidBarCode && (codeText.Length >= (BARCODE_VALID_MIN_LENGTH + barcodePrefix.Length)); //Consider barcodes that have the min-length
if (isValidBarCode)
{
codeText = codeText.Substring(barcodePrefix.Length); //Strip off the BarcodePrefix to get the DocQueueID
}
Please let us know what is causing this issue.