Detect barcode in pdf file

Discussions about 1D barcode reading and writing
Post Reply
mdelbene
Posts: 31
Joined: Wed May 11, 2011 10:03 am

Detect barcode in pdf file

Post by mdelbene » Tue Jul 12, 2011 12:39 pm

Hi all,
I'm encountering some problems during detecting barcode in pdf file.

I acquire with a scanner the same document, then I create files with different extensions.
Then I'm trying to detect in this document a generic Code39 barcode.

For JPEG, PNG, BMP, TIFF no problem: I use the method CreateGdPictureImageFromFile, then Barcode1DReaderDoScan and my barcodes are detected.

So, when I have a PDF file, I use the new GdPicturePDF class available in GdPicture v.8.
Here is my code snippet:

Code: Select all

      GdPicture.GdPicturePDF gdPDF = new GdPicturePDF();
      gdPDF.SetLicenseNumber("XXX");

      GdPictureStatus gstatus = gdPDF.LoadFromFile(pdfPath, false);

       if (gstatus == GdPictureStatus.OK)
	{
		for (int i = 1; i <= gdPDF.GetPageCount(); i++)
		{
			// select the current page
			if (gdPDF.SelectPage(i))
			{
				// create image
				int imageId = gdPDF.RenderPageToGdPictureImage(72, false);

				if (imageId > 0)
				{
					// searching barcode in i-page
					gstatus = gdPicture.Barcode1DReaderDoScan(imageId, Barcode1DReaderScanMode.BestQuality);

					if (gstatus == GdPictureStatus.OK)
					{
						// for each barcode I read info
						for (int j = 1; j <= gdPicture.Barcode1DReaderGetBarcodeCount(); j++)
						{
							Console.WriteLine(gdPicture.Barcode1DReaderGetBarcodeValue(j));
							Console.WriteLine(gdPicture.Barcode1DReaderGetBarcodeType(j).ToString());
						}
					}

					gdPicture.Barcode1DReaderClear();
				}
			}
		}

	       gdPDF.CloseDocument();
	}
I attached two files:
- in the BMP file I found 3 barcodes
- in the PDF file no barcode is detected.

Anyone can help me?
Thanks.
Michela

User avatar
Loïc
Site Admin
Posts: 5564
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Detect barcode in pdf file

Post by Loïc » Tue Jul 12, 2011 4:52 pm

Hi,


You should try to rasterize PDF page in 200 DPI:

Code: Select all

int imageId = gdPDF.RenderPageToGdPictureImage(200, false);
Kind regards,

Loïc

mdelbene
Posts: 31
Joined: Wed May 11, 2011 10:03 am

Re: Detect barcode in pdf file

Post by mdelbene » Tue Jul 12, 2011 5:09 pm

Now it works...
Thanks a lot Loïc.

Bye
Michela

User avatar
Loïc
Site Admin
Posts: 5564
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Detect barcode in pdf file

Post by Loïc » Tue Jul 12, 2011 5:13 pm

You are welcome.

Thank you for the return.

User avatar
Loïc
Site Admin
Posts: 5564
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Detect barcode in pdf file

Post by Loïc » Tue Jul 12, 2011 5:13 pm

BTW, don't forget to release the imageId !

mdelbene
Posts: 31
Joined: Wed May 11, 2011 10:03 am

Re: Detect barcode in pdf file

Post by mdelbene » Tue Jul 12, 2011 6:00 pm

Thanks for the suggestion... :wink:
Good evening.
Michela

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest