Dev Center
Table of contents

Thanks for downloading Dynamsoft Barcode Reader Package!

Your download will start shortly. If your download does not begin, click here to retry.

Scan Barcodes from PDFs & multi-page TIFs

For multi-page TIF and PDF files, DBR provides the parameter Pages to process them, PDFReadingMode and PDFRasterDPI are used to handle PDF file specifically.

Specify the page number to be processed

When DBR is processing multi-page files (TIF or PDF), you can use the parameter Pages to specify the specific page or range of pages to be processed. This parameter can be used to specify one or more page index values, starting from 0. The default value is “”, which means all pages.

Pagescan be set by one or more of the following data, separated by commas:

  • An integer index value, representing a specific page;
  • Two integer index values, connected by “-“ in the middle, representing a certain range of page numbers.

Pages can only be configured in Json, for example, {"Pages": "0,3,5,7-10"}.

In the returned decoding result of a certain barcode, you can get its corresponding page number (out of the entire document) via the LocalizationResult. Please refer to the following procedure:

BarcodeReader* reader = new CBarcodeReader();     
reader->InitLicense("Insert license");    
char sError[512];     
reader->DecodeFile("File path", ""); //decoding    
TextResultArray* pResult = NULL;     
reader->GetAllTextResults(&pResult); //get the decoded results   
int iCount = pResult->resultsCount;  
for(int j = 0; j < iCount; j++)  //Loop through all returned results
{  
    TextResult* pBarcode = pResults->results[j];  
    LocalizationResult* pLocRes = pBarcode->localizationResult;  
    printf("pageNumber:%d\n", pLocRes->PageNumber); //get the page number in which the barcode is located
}  
dynamsoft::dbr::CBarcodeReader::FreeTextResults(&pResult);        
delete reader; 

Select PDFReadingMode

The parameter PDFReadingMode determines how to process PDF files. DBR provides two ways to read PDF data, PDFRM_RASTER and PDFRM_VECTOR.

  • PDFRM_RASTER
    This method will render each page of the PDF as an image, which will be processed later. This reading mode can be used for all PDF files, but the drawback is that you need to choose the appropriate value of PDFRasterDPI to render the image. Otherwise, if the image is too large, the processing speed of DBR may be slowed, and if the image is too small, the barcode region may be distorted and cannot be decoded.

  • PDFRM_VECTOR
    This method is specifically designed for PDF composed of vector data. This mode will not render PDF data into images, but directly extract PDF vector data for barcode region positioning and decoding. This mode can offer faster speed and higher accuracy, but it is only suitable for PDF composed of vector data.

At the same time, we also provide PDFRM_AUTO mode, this mode will automatically choose the appropriate processing mode according to whether the PDF file has enough available vector data.

Select the appropriate PDFRasterDPI

When using PDFRM_RASTER, we need to select an appropriate PDFRasterDPI to ensure that the rendered image has the right size. The higher the PDFRasterDPI, the higher the final resolution of the rendered image. A high-resolution image can ensure the image details are not distorted, which is helpful for DBR to correctly identify the barcode region but will make the processing speed slow at the same time. This section will clarify the calculation from PDFRasterDPI to the size of the rendered image. You can observe the rendered image based on the calculation method via the intermediate result IRT_ORIGINAL_IMAGE to decide how to adjust PDFRasterDPI.

The resolution of the rendered image is calculated as follows: Set PDF page height to h and page width to w, Final rendered image height ImgHeight = h / 72 * PDFRasterDPI Final rendered image width ImgWidth = w / 72 * PDFRasterDPI

PDFRasterDPI is the number of pixels per inch of the image. The page width and height unit defined in PDF is pt (length unit, 1 inch = 72 pt), so in the above formula we first divide the width and height by 72 to get the inch length of the page, and then multiply by PDFRasterDPI to get the final image pixel width and height.

Json Template

In the following template, we configured PDFReadingMode to PDFRM_AUTO, PDFRasterDPI to 500, and Pages specified three Pages in index 1, 2, and 3.

{
    "ImageParameter": {
        "BarcodeFormatIds": ["BF_ALL"], 
        "PDFRasterDPI": 500,
        "PDFReadingMode": {
            "Mode": "PDFRM_AUTO "
        },                         
        "Pages": "1,2,3"           
    }, 
    "Version": "3.0"
}

This page is compatible for:

Version 7.5.0

Is this page helpful?

YesYes NoNo

latest version

  • Latest version
  • Version 10.x
    • Version 10.2.0
    • Version 10.0.21
    • Version 10.0.20
    • Version 10.0.10
    • Version 10.0.0
  • Version 9.x
    • Version 9.6.40
    • Version 9.6.33
    • Version 9.6.32
    • Version 9.6.31
    • Version 9.6.30
    • Version 9.6.20
    • Version 9.6.10
    • Version 9.6.0
    • Version 9.4.0
    • Version 9.2.0
    • Version 9.0.0
  • Version 8.x
    • Version 8.8.0
    • Version 8.6.0
    • Version 8.4.0
    • Version 8.2.0
    • Version 8.1.2
    • Version 8.1.0
    • Version 8.0.0
  • Version 7.x
    • Version 7.6.0
    • Version 7.5.0
Change +