Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Aug 03, 2016 5:25 am

Hi Team,

Is there a way to read barcode/QR code which is present in an existing pdf file.

Thanks,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Wed Aug 03, 2016 6:17 am

Hi,

Thanks for your inquiry.
Sorry that Spire.PDF doesn't support to read barcode/QR code which is in PDF file. But you can save the PDF as image and then read the barcode/QR code by Spire.Barcode.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Aug 03, 2016 8:48 am

Hi Betsy,

Thanks for the quick reply.
Can you help me with any site source / example showing how to read a barcode from pdf document.

Regards,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Wed Aug 03, 2016 9:07 am

Dear Saurav,

Please download Spire.Office and then reference the corresponding dlls from it. And then convert PDF to image by Spire.PDF, here is a guide for your reference: http://www.e-iceblue.com/Tutorials/Spir ... ution.html. Then, read the barcode/QR code by Spire.Barcode, here is sample code.
Code: Select all
string[] datas = Spire.Barcode.BarcodeScanner.Scan("barcode.png");

Wish it can help you. If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Aug 03, 2016 9:36 am

Hi Betsy,

Solution did work. Many thanks for the help.

But it takes around 2-3 minutes to scan a single image. Is there any way to boost up the performance??

Regards,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Thu Aug 04, 2016 1:58 am

Dear Saurav,

Thanks for your reply.
Please try to use the method SaveAsImage(int pageIndex) to save the PDF as image, as I tested this method and found it is faster than the method SaveAsImage(int pageIndex, int dpiX, int dpiY), if the issue still exists, please provide us your sample document for investigation.

Sincerely,
Betsy
E-iceblue support team
Last edited by Betsy on Thu Aug 04, 2016 6:34 am, edited 1 time in total.
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Aug 04, 2016 6:33 am

Hi Betsy,

Thanks for the reply.
I'm already using SaveAsImage() method. This is what im doing.
Code: Select all
        public void ReadBarCode()
        {
            PdfDocument documemt = new PdfDocument();
            documemt.LoadFromFile(@"E:\DOC_2.pdf");
            Bitmap image = (Bitmap)documemt.SaveAsImage(0, PdfImageType.Bitmap, 400, 400);
            string[] datas = Spire.Barcode.BarcodeScanner.Scan(image);
            foreach (var item in datas)
            {
                Console.WriteLine(item);
            }

            documemt.Close();
        }


I want to know of there is any way to convert a particular area of pdf to image rather then just having the whole page to be converted as pdf.
Let's say i have my barcode on top left region of the page. SO in that case can i just not convert that part to image and scan for barcode??
Will this improve the performance.??

Thanks,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Thu Aug 04, 2016 6:49 am

Dear Saurav,

Sorry that there is no way to convert a particular area of pdf to image.
Also, please try to use the method SaveAsImage(int pageIndex) to save the PDF as image, as I tested this method and found it is faster than the method SaveAsImage(int pageIndex, PdfImageType type, int dpiX, int dpiY), like this
Code: Select all
Bitmap image = (Bitmap)doc.SaveAsImage(0);


Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Aug 04, 2016 7:55 am

Dear Saurav,

I find another way to achieve your target. If the barcode/QR code is image on PDF file, you can extract the image, here is the guide: http://www.e-iceblue.com/Tutorials/Spir ... -in-C.html. And then read the barcode/QR code by Spire.Barcode.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Aug 04, 2016 9:42 am

Hi Betsy,

Thanks for the solution. But i dont know how to save the barcode as an image in pdf file. This is what i am using right now to create a barcode.
Code: Select all
public void CreateBarCode()
        {
            PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(@"E:\doc.pdf");
            PdfDocument pdf1 = new PdfDocument();
            PdfPageBase page;
            for (int i = 0; i < pdf.Pages.Count-1; i++)
            {
                page = pdf1.Pages.Add(pdf.Pages[i].Size, new Spire.Pdf.Graphics.PdfMargins(0));
                pdf.Pages[i].CreateTemplate().Draw(page, new System.Drawing.PointF(0, 0));
             
                PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
                barcode1.BarcodeToTextGapHeight = 1f;
                barcode1.EnableCheckDigit = true;
                barcode1.ShowCheckDigit = true;
                barcode1.TextDisplayLocation = TextLocation.Bottom;
                barcode1.TextColor = Color.Green;
                barcode1.Draw(page, new PointF(2, 10));
               
            }
            pdf1.SaveToFile("DOC_4.pdf");       
        }


Can you please let me know what i need to change to save barcode as an image.

Also Betsy for the previous solution to use
Code: Select all
SaveAsImage(int pageIndex)
did speed up the processing but now the
Code: Select all
BarcodeScanner.Scan()
does not return correct result.

Please let me know what I can do to proceed further.

Thanks,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Thu Aug 04, 2016 11:16 am

Hi Besty,

Many thanks for the suggestion. I got the solution to save barcode as an image and extracting the same from pdf. It really works fast as well.

I have one doubt though. What if i have multiple images in my pdf page. In that case is there any way to filter out the unwanted images. Because i dont want to scan all the images since only one of them contains the barcode.

Thanks,
Saurav

sauravvijay13
 
Posts: 6
Joined: Wed Aug 03, 2016 5:20 am

Fri Aug 05, 2016 2:49 am

Dear Saurav,

Thanks for your feedback.
Sorry that there is no way to filter out the unwanted images. If there is other issue, please let me know.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.PDF

cron